Ariles
writer.cpp
Go to the documentation of this file.
1 /**
2  @file
3  @author Alexander Sherikov
4 
5  @copyright 2018 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 
12 #include "common.h"
13 
14 
15 namespace ariles2
16 {
17  namespace ns_rosparam
18  {
19  namespace impl
20  {
22  {
23  public:
24  explicit Writer(const ::ros::NodeHandle &nh)
25  {
26  nh_ = nh;
27  }
28  };
29  } // namespace impl
30  } // namespace ns_rosparam
31 } // namespace ariles2
32 
33 
34 namespace ariles2
35 {
36  namespace ns_rosparam
37  {
38  Writer::Writer(const ::ros::NodeHandle &nh)
39  {
40  makeImplPtr(nh);
41  }
42 
43 
45  {
46  if (XmlRpc::XmlRpcValue::TypeInvalid == impl_->root_value_.getType())
47  {
48  impl_->root_value_ = "";
49  }
50  impl_->nh_.setParam(impl_->root_name_, impl_->root_value_);
51  impl_->root_name_.clear();
52  }
53 
54 
55 
56  void Writer::startMapEntry(const std::string &map_name)
57  {
58  if (impl_->empty())
59  {
60  impl_->root_name_ = map_name;
61  impl_->emplace(&impl_->root_value_);
62  }
63  else
64  {
65  impl_->emplace(&(impl_->getRawNode()[map_name]));
66  }
67  }
68 
70  {
71  impl_->pop();
72  }
73 
74 
75  void Writer::startArray(const std::size_t size, const bool /*compact*/)
76  {
77  impl_->getRawNode().setSize(static_cast<int>(size));
78  impl_->emplace(0, size);
79  }
80 
82  {
84  impl_->back().index_ < impl_->back().size_,
85  "Internal error: array has more elements than expected.");
86  }
87 
89  {
90  impl_->shiftArray();
91  }
92 
94  {
95  impl_->pop();
96  }
97 
98 
99 
100  void Writer::writeElement(const bool &element, const Parameters &)
101  {
102  impl_->getRawNode() = element;
103  }
104 
105 
106  void Writer::writeElement(const std::string &element, const Parameters &)
107  {
108  impl_->getRawNode() = element;
109  }
110 
111 
112  void Writer::startRoot(const std::string &name, const Parameters &)
113  {
115 
116  impl_->root_name_ = "";
117  impl_->root_value_.clear();
118 
119  if (name.empty())
120  {
121  startMapEntry("ariles");
122  }
123  else
124  {
125  startMapEntry(name);
126  }
127  }
128 
129  void Writer::endRoot(const std::string & /*name*/)
130  {
132  endMapEntry();
133  }
134 
135 
136 #define ARILES2_BASIC_TYPE(type) \
137  void Writer::writeElement(const type &element, const Parameters &) \
138  { \
139  impl_->getRawNode() = element; \
140  }
141 
143 
144 #undef ARILES2_BASIC_TYPE
145 
146 
147 
148 #define ARILES2_BASIC_TYPE(type) \
149  void Writer::writeElement(const type &element, const Parameters &) \
150  { \
151  CPPUT_ASSERT( \
152  static_cast<int64_t>(element) <= std::numeric_limits<int>::max() \
153  && static_cast<int64_t>(element) >= static_cast<int64_t>(std::numeric_limits<int>::min()), \
154  "Value is out of range."); \
155  impl_->getRawNode() = static_cast<int>(element); \
156  }
157 
159 
160 #undef ARILES2_BASIC_TYPE
161 
162 
163 #define ARILES2_BASIC_TYPE(type) \
164  void Writer::writeElement(const type &element, const Parameters &) \
165  { \
166  CPPUT_ASSERT( \
167  static_cast<uint64_t>(element) <= static_cast<uint64_t>(std::numeric_limits<int>::max()), \
168  "Value is too large."); \
169  impl_->getRawNode() = static_cast<int>(element); \
170  }
171 
173 
174 #undef ARILES2_BASIC_TYPE
175  } // namespace ns_rosparam
176 } // namespace ariles2
::ros::NodeHandle nh_
Definition: common.h:34
void startArray(const std::size_t size, const bool=false)
Definition: writer.cpp:75
void flush()
Flush the configuration to the output.
Definition: writer.cpp:44
void startMapEntry(const std::string &map_name)
Starts a nested map in the configuration file.
Definition: writer.cpp:56
Writer(const ::ros::NodeHandle &nh)
Definition: writer.cpp:38
void endRoot(const std::string &name)
Definition: writer.cpp:129
void startRoot(const std::string &name, const Parameters &)
Definition: writer.cpp:112
Writer(const ::ros::NodeHandle &nh)
Definition: writer.cpp:24
void writeElement(const std::complex< t_Scalar > &entry, const Parameters &param)
Definition: write.h:264
#define CPPUT_ASSERT(condition,...)
Definition: exception.h:32
#define ARILES2_BASIC_REAL_TYPES_LIST
Definition: helpers.h:59
#define ARILES2_BASIC_UNSIGNED_INTEGER_TYPES_LIST
Definition: helpers.h:50
#define ARILES2_BASIC_SIGNED_INTEGER_TYPES_LIST
Definition: helpers.h:37
visitor::Parameters Parameters
Definition: count.h:26
CPPUT_MACRO_SUBSTITUTE(ARILES2_BASIC_SIGNED_INTEGER_TYPES_LIST) CPPUT_MACRO_SUBSTITUTE(ARILES2_BASIC_UNSIGNED_INTEGER_TYPES_LIST) CPPUT_MACRO_SUBSTITUTE(ARILES2_BASIC_REAL_TYPES_LIST) void Reader
Definition: reader.cpp:187
Definition: basic.h:17
#define CPPUT_TRACE_FUNCTION
Definition: trace.h:126