ifw-core
6.0.0
Loading...
Searching...
No Matches
protocol
base
src
include
ifw
core
protocol
base
utils.hpp
Go to the documentation of this file.
1
8
#ifndef CORE_PROTOCOL_BASE_UTILS_HPP
9
#define CORE_PROTOCOL_BASE_UTILS_HPP
10
11
#include <boost/variant.hpp>
12
13
namespace
ifw::core::protocol::base
{
14
15
// Visitor class to convert the value of the variant to an std::string
16
class
VariantStr
:
public
boost::static_visitor<std::string> {
17
public
:
18
// Overload for scalar types other than char
19
template
<
typename
T>
20
std::string
operator()
(
const
T& value)
const
{
21
// We need to do a special handling for strings types
22
if
constexpr
(std::is_same_v<T, std::string>) {
23
return
"[scalar type: std::string]= "
+ value;
24
}
else
{
25
return
"[scalar type: "
+ boost::core::demangle(
typeid
(T).name()) +
26
"]= "
+ std::to_string(value);
27
}
28
}
29
};
30
31
class
VariantValue
:
public
boost::static_visitor<std::string> {
32
public
:
33
// Overload for scalar types other than char
34
template
<
typename
T>
35
std::string
operator()
(
const
T& value)
const
{
36
// We need to do a special handling for strings types
37
if
constexpr
(std::is_same_v<T, std::string>) {
38
return
value;
39
}
else
{
40
return
std::to_string(value);
41
}
42
}
43
};
44
45
46
}
47
48
#endif
//CORE_PROTOCOL_BASE_UTILS_HPP
ifw::core::protocol::base::VariantStr
Definition
utils.hpp:16
ifw::core::protocol::base::VariantStr::operator()
std::string operator()(const T &value) const
Definition
utils.hpp:20
ifw::core::protocol::base::VariantValue
Definition
utils.hpp:31
ifw::core::protocol::base::VariantValue::operator()
std::string operator()(const T &value) const
Definition
utils.hpp:35
ifw::core::protocol::base
Definition
commFactory.cpp:13
Generated by
1.10.0