Ariles
node_wrapper.h
Go to the documentation of this file.
1 /**
2  @file
3  @author Alexander Sherikov
4 
5  @copyright 2017-2024 Alexander Sherikov, Licensed under the Apache License, Version 2.0.
6  (see @ref LICENSE or http://www.apache.org/licenses/LICENSE-2.0)
7 
8  @brief
9 */
10 
11 namespace ariles2
12 {
13  namespace ns_ros2param
14  {
15  class NodeBase : public serialization::Node<std::string>
16  {
17  protected:
19 
20  public:
21  enum class ArrayType
22  {
23  UNDEFINED = 0,
24  BUILTIN = 1,
25  GENERIC = 2
26  };
27 
28  public:
30 
31  public:
32  using Parent::Parent;
33 
34  [[nodiscard]] bool isNonBuiltinArray() const
35  {
36  return (ArrayType::BUILTIN != array_type_ and isArray());
37  }
38 
39  [[nodiscard]] bool isBuiltinArray() const
40  {
41  return (ArrayType::BUILTIN == array_type_ and isArray());
42  }
43  };
44 
45 
46  class ModifierNode : public NodeBase
47  {
48  public:
49  std::variant<
50  std::vector<uint8_t>,
51  std::vector<bool>,
52  std::vector<int64_t>,
53  std::vector<float>,
54  std::vector<double>,
55  std::vector<std::string>>
57 
58  public:
59  using NodeBase::NodeBase;
60 
61 
62  ModifierNode(const std::string &name, std::size_t size) : NodeBase(name, 0, size)
63  {
65  }
66 
67  template <class t_Value>
68  bool tryPushArray(const t_Value value)
69  {
72  CPPUT_TRACE_TYPE(t_Value);
73  if (isArray())
74  {
76  {
77  array_values_.emplace<std::vector<t_Value>>();
78  std::get<std::vector<t_Value>>(array_values_).reserve(size_);
80  }
81  std::get<std::vector<t_Value>>(array_values_).push_back(value);
82  return (true);
83  }
84  return (false);
85  }
86 
87  bool tryPushArray(const std::string &value)
88  {
91  if (isArray())
92  {
94  {
95  array_values_.emplace<std::vector<std::string>>();
96  std::get<std::vector<std::string>>(array_values_).reserve(size_);
98  }
99  std::get<std::vector<std::string>>(array_values_).push_back(value);
100  return (true);
101  }
102  return (false);
103  }
104  };
105  } // namespace ns_ros2param
106 } // namespace ariles2
ModifierNode(const std::string &name, std::size_t size)
Definition: node_wrapper.h:62
bool tryPushArray(const std::string &value)
Definition: node_wrapper.h:87
bool tryPushArray(const t_Value value)
Definition: node_wrapper.h:68
std::variant< std::vector< uint8_t >, std::vector< bool >, std::vector< int64_t >, std::vector< float >, std::vector< double >, std::vector< std::string > > array_values_
Definition: node_wrapper.h:56
Definition: basic.h:17
std::string reserve(t_String &&...strings)
Definition: concat.h:31
#define CPPUT_TRACE_FUNCTION
Definition: trace.h:126
#define CPPUT_TRACE_TYPE(type)
Definition: trace.h:128
#define CPPUT_TRACE_VALUE(value)
Definition: trace.h:127