Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
cbd91767
Commit
cbd91767
authored
Jan 03, 2018
by
Dominik Charousset
Committed by
Dominik Charousset
Feb 06, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make CAF_ARG compatible with CAF_MESSAGE
parent
face0cb7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
81 deletions
+49
-81
libcaf_core/caf/detail/arg_wrapper.hpp
libcaf_core/caf/detail/arg_wrapper.hpp
+0
-46
libcaf_core/caf/logger.hpp
libcaf_core/caf/logger.hpp
+5
-20
libcaf_test/caf/test/unit_test.hpp
libcaf_test/caf/test/unit_test.hpp
+41
-14
libcaf_test/caf/test/unit_test_impl.hpp
libcaf_test/caf/test/unit_test_impl.hpp
+3
-1
No files found.
libcaf_core/caf/detail/arg_wrapper.hpp
View file @
cbd91767
...
...
@@ -19,14 +19,6 @@
#ifndef CAF_ARG_WRAPPER_HPP
#define CAF_ARG_WRAPPER_HPP
#include <tuple>
#include <string>
#include "caf/detail/int_list.hpp"
#include "caf/detail/type_list.hpp"
#include "caf/detail/apply_args.hpp"
#include "caf/detail/type_traits.hpp"
namespace
caf
{
namespace
detail
{
...
...
@@ -40,50 +32,12 @@ struct arg_wrapper {
}
};
template
<
class
...
Ts
>
struct
named_args_tuple
{
const
std
::
array
<
const
char
*
,
sizeof
...(
Ts
)
>&
names
;
std
::
tuple
<
const
Ts
&
...
>
xs
;
};
template
<
class
...
Ts
>
named_args_tuple
<
Ts
...
>
make_named_args_tuple
(
std
::
array
<
const
char
*
,
sizeof
...(
Ts
)
>&
names
,
const
Ts
&
...
xs
)
{
return
{
names
,
std
::
forward_as_tuple
(
xs
...)};
};
template
<
size_t
I
,
class
...
Ts
>
auto
get
(
const
named_args_tuple
<
Ts
...
>&
x
)
->
arg_wrapper
<
typename
type_at
<
I
,
Ts
...
>::
type
>
{
CAF_ASSERT
(
x
.
names
[
I
]
!=
nullptr
);
return
{
x
.
names
[
I
],
std
::
get
<
I
>
(
x
.
xs
)};
}
/// Used to implement `CAF_ARG`.
template
<
class
T
>
static
arg_wrapper
<
T
>
make_arg_wrapper
(
const
char
*
name
,
const
T
&
value
)
{
return
{
name
,
value
};
}
struct
arg_wrapper_maker
{
template
<
class
...
Ts
>
auto
operator
()(
const
Ts
&
...
xs
)
const
->
decltype
(
std
::
make_tuple
(
xs
...))
{
return
std
::
make_tuple
(
xs
...);
}
};
/// Used to implement `CAF_ARGS`.
template
<
class
...
Ts
>
static
std
::
tuple
<
arg_wrapper
<
Ts
>
...
>
make_args_wrapper
(
std
::
array
<
const
char
*
,
sizeof
...(
Ts
)
>
names
,
const
Ts
&
...
xs
)
{
arg_wrapper_maker
f
;
typename
il_range
<
0
,
sizeof
...(
Ts
)
>::
type
indices
;
auto
tup
=
make_named_args_tuple
(
names
,
xs
...);
return
apply_args
(
f
,
indices
,
tup
);
}
}
// namespace detail
}
// namespace caf
...
...
libcaf_core/caf/logger.hpp
View file @
cbd91767
...
...
@@ -41,9 +41,10 @@
#include "caf/intrusive/singly_linked.hpp"
#include "caf/intrusive/task_queue.hpp"
#include "caf/detail/arg_wrapper.hpp"
#include "caf/detail/pretty_type_name.hpp"
#include "caf/detail/scope_guard.hpp"
#include "caf/detail/shared_spinlock.hpp"
#include "caf/detail/pretty_type_name.hpp"
/*
* To enable logging, you have to define CAF_DEBUG. This enables
...
...
@@ -162,22 +163,6 @@ public:
/// Stores a parsed format string as list of fields.
using
line_format
=
std
::
vector
<
field
>
;
/// Enables automagical string conversion for `CAF_ARG`.
template
<
class
T
>
struct
arg_wrapper
{
const
char
*
name
;
const
T
&
value
;
arg_wrapper
(
const
char
*
x
,
const
T
&
y
)
:
name
(
x
),
value
(
y
)
{
// nop
}
};
/// Used to implement `CAF_ARG`.
template
<
class
T
>
static
arg_wrapper
<
T
>
make_arg_wrapper
(
const
char
*
name
,
const
T
&
value
)
{
return
{
name
,
value
};
}
/// Utility class for building user-defined log messages with `CAF_ARG`.
class
line_builder
{
public:
...
...
@@ -193,7 +178,7 @@ public:
}
template
<
class
T
>
line_builder
&
operator
<<
(
const
arg_wrapper
<
T
>&
x
)
{
line_builder
&
operator
<<
(
const
detail
::
arg_wrapper
<
T
>&
x
)
{
if
(
behind_arg_
)
str_
+=
", "
;
else
if
(
!
str_
.
empty
())
...
...
@@ -346,9 +331,9 @@ bool operator==(const logger::field& x, const logger::field& y);
#define CAF_LOG_LEVEL_DEBUG 3
#define CAF_LOG_LEVEL_TRACE 4
#define CAF_ARG(argument) caf::
logger
::make_arg_wrapper(#argument, argument)
#define CAF_ARG(argument) caf::
detail
::make_arg_wrapper(#argument, argument)
#define CAF_ARG2(argname, argval) caf::
logger
::make_arg_wrapper(argname, argval)
#define CAF_ARG2(argname, argval) caf::
detail
::make_arg_wrapper(argname, argval)
#ifdef CAF_MSVC
#define CAF_PRETTY_FUN __FUNCSIG__
...
...
libcaf_test/caf/test/unit_test.hpp
View file @
cbd91767
...
...
@@ -19,22 +19,24 @@
#ifndef CAF_TEST_UNIT_TEST_HPP
#define CAF_TEST_UNIT_TEST_HPP
#include <map>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <memory>
#include <mutex>
#include <sstream>
#include <string>
#include <thread>
#include <vector>
#include <string>
#include <memory>
#include <fstream>
#include <sstream>
#include <iostream>
#include "caf/deep_to_string.hpp"
#include "caf/fwd.hpp"
#include "caf/term.hpp"
#include "caf/logger.hpp"
#include "caf/optional.hpp"
#include "caf/deep_to_string.hpp"
#include "caf/term.hpp"
#include "caf/detail/arg_wrapper.hpp"
namespace
caf
{
namespace
test
{
...
...
@@ -193,12 +195,10 @@ public:
template
<
class
T
>
void
log
(
level
lvl
,
const
T
&
x
)
{
if
(
lvl
<=
level_console_
)
{
if
(
lvl
<=
level_console_
)
*
console_
<<
x
;
}
if
(
lvl
<=
level_file_
)
{
if
(
lvl
<=
level_file_
)
file_
<<
x
;
}
}
/// Output stream for logging purposes.
...
...
@@ -208,9 +208,33 @@ public:
stream
(
const
stream
&
)
=
default
;
struct
reset_flags_t
{};
stream
&
operator
<<
(
reset_flags_t
)
{
behind_text_
=
false
;
behind_arg_
=
false
;
return
*
this
;
}
template
<
class
T
>
stream
&
operator
<<
(
const
T
&
x
)
{
parent_
.
log
(
lvl_
,
x
);
behind_text_
=
true
;
behind_arg_
=
false
;
return
*
this
;
}
template
<
class
T
>
stream
&
operator
<<
(
const
caf
::
detail
::
arg_wrapper
<
T
>&
x
)
{
if
(
behind_arg_
)
parent_
.
log
(
lvl_
,
", "
);
else
if
(
behind_text_
)
parent_
.
log
(
lvl_
,
" "
);
parent_
.
log
(
lvl_
,
x
.
name
);
parent_
.
log
(
lvl_
,
" = "
);
parent_
.
log
(
lvl_
,
deep_to_string
(
x
.
value
));
behind_text_
=
false
;
behind_arg_
=
true
;
return
*
this
;
}
...
...
@@ -222,6 +246,8 @@ public:
}
private:
bool
behind_text_
;
bool
behind_arg_
;
logger
&
parent_
;
level
lvl_
;
};
...
...
@@ -414,8 +440,9 @@ using caf_test_case_auto_fixture = caf::test::dummy_fixture;
#define CAF_TEST_PRINT(level, msg, colorcode) \
(::caf::test::logger::instance().level() \
<< ::caf::term:: colorcode << " -> " << ::caf::term::reset << msg \
<< " [line " << __LINE__ << "]\n")
<< ::caf::term::colorcode << " -> " << ::caf::term::reset \
<< ::caf::test::logger::stream::reset_flags_t{} << msg << " [line " \
<< __LINE__ << "]\n")
#define CAF_TEST_PRINT_ERROR(msg) CAF_TEST_PRINT(info, msg, red)
#define CAF_TEST_PRINT_INFO(msg) CAF_TEST_PRINT(info, msg, yellow)
...
...
libcaf_test/caf/test/unit_test_impl.hpp
View file @
cbd91767
...
...
@@ -172,7 +172,9 @@ bool check(test* parent, const char *file, size_t line,
}
// namespace detail
logger
::
stream
::
stream
(
logger
&
parent
,
logger
::
level
lvl
)
:
parent_
(
parent
),
:
behind_text_
(
false
),
behind_arg_
(
false
),
parent_
(
parent
),
lvl_
(
lvl
)
{
// nop
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment