16 #include <boost/lexical_cast.hpp> 26 template <
class t_NameValuePair>
51 template <
class t_NameValuePair>
75 if (index_ == name_value_pairs_->size())
77 name_value_pairs_->resize(name_value_pairs_->size() + 1);
84 name_value_pairs_->reserve(reserve_);
89 name_value_pairs_->clear();
96 name_value_pairs_ = &buffer_name_value_pairs_;
100 expandReserve(reserve);
106 explicit GenericWriter(std::vector<t_NameValuePair> *name_value_pairs,
const std::size_t reserve = 0)
108 name_value_pairs_ = name_value_pairs;
112 expandReserve(reserve);
130 void reset(
const bool initialize_structure =
true)
132 if (
true == initialize_structure)
136 initialize_structure_ = initialize_structure;
142 virtual void descend(
const std::string &map_name)
144 if (
true == initialize_structure_)
146 if (0 == node_stack_.size())
148 node_stack_.push_back(map_name);
152 if (
true == node_stack_.back().isArray())
154 std::string node = node_stack_.back().node_;
156 node += boost::lexical_cast<std::string>(node_stack_.back().index_);
159 node_stack_.push_back(node);
163 node_stack_.push_back(node_stack_.back().node_ +
"." + map_name);
171 if (
true == initialize_structure_)
173 node_stack_.pop_back();
178 virtual void startMap(
const std::size_t num_entries)
180 if (
true == initialize_structure_)
182 expandReserve(num_entries);
191 virtual void startArray(
const std::size_t size,
const bool compact =
false)
193 if (
true == initialize_structure_)
196 if (
true == node_stack_.back().isArray())
198 std::string node = node_stack_.back().node_;
200 node += boost::lexical_cast<std::string>(node_stack_.back().index_);
201 node_stack_.push_back(
NodeWrapper(node, 0, size, compact));
205 node_stack_.push_back(
NodeWrapper(node_stack_.back().node_, 0, size));
212 if (
true == initialize_structure_)
214 ARILES_ASSERT(
true == node_stack_.back().isArray(),
"Internal error: array expected.");
215 ++node_stack_.back().index_;
221 if (
true == initialize_structure_)
223 node_stack_.pop_back();
228 #define ARILES_BASIC_TYPE(type) \ 229 void writeElement(const type &element) \ 232 if (true == initialize_structure_) \ 234 NameValuePairHandler<t_NameValuePair>::name((*name_value_pairs_)[index_]) = node_stack_.back().node_; \ 235 if (true == node_stack_.back().isArray()) \ 237 NameValuePairHandler<t_NameValuePair>::name((*name_value_pairs_)[index_]) += "_"; \ 238 NameValuePairHandler<t_NameValuePair>::name((*name_value_pairs_)[index_]) += \ 239 boost::lexical_cast<std::string>(node_stack_.back().index_); \ 242 NameValuePairHandler<t_NameValuePair>::value((*name_value_pairs_)[index_]) = element; \ 248 #undef ARILES_BASIC_TYPE 251 void writeElement(
const std::string & )
bool initialize_structure_
ARILES_MACRO_SUBSTITUTE(ARILES_BASIC_NUMERIC_TYPES_LIST) void writeElement(const std
void flush()
Flush the configuration to the output.
Configuration writer class.
void reset(const bool initialize_structure=true)
std::vector< NodeWrapper > node_stack_
std::vector< t_NameValuePair > * name_value_pairs_
virtual void shiftArray()
virtual void startMap(const std::size_t num_entries)
Starts a nested map in the configuration file.
static double & value(NameValuePair &pair)
GenericWriter(std::vector< t_NameValuePair > *name_value_pairs, const std::size_t reserve=0)
static std::string & name(NameValuePair &pair)
GenericWriter< NameValuePair > Writer
const serialization::Features & getSerializationFeatures() const
std::pair< std::string, double > NameValuePair
virtual void descend(const std::string &map_name)
Starts a nested map in the configuration file.
virtual void startArray(const std::size_t size, const bool compact=false)
GenericWriter(const std::size_t reserve=0)
void expandReserve(const std::size_t size)
virtual void endMap()
Ends a nested map in the configuration file.
ariles::Node< const ::msgpack::object * > NodeWrapper
#define ARILES_BASIC_NUMERIC_TYPES_LIST
#define ARILES_VISIBILITY_ATTRIBUTE
ariles::Node< std::string > NodeWrapper
std::vector< t_NameValuePair > buffer_name_value_pairs_