15 #include <msgpack.hpp>
39 std::vector<ARILES2_SHARED_PTR< ::msgpack::object_handle> >
handles_;
55 ARILES2_TRACE_FUNCTION;
56 std::stringstream str_stream;
57 str_stream << input_stream.rdbuf();
58 buffer_ = str_stream.str();
64 std::size_t buffer_offset = 0;
66 while (buffer_offset != buffer_.size())
69 ARILES2_SHARED_PTR< ::msgpack::object_handle>(new ::msgpack::object_handle));
71 unpack(*handles_[handles_.size() - 1], buffer_.data(), buffer_.size(), buffer_offset);
74 catch (
const std::exception &e)
76 ARILES2_THROW(std::string(
"Failed to parse the configuration file: ") + e.what());
79 nameless_counter_ = 0;
88 const ::msgpack::object &
getRawNode(
const std::size_t depth)
90 ARILES2_TRACE_FUNCTION;
91 if (node_stack_[depth].isArray())
93 return (getRawNode(depth - 1).via.array.ptr[node_stack_[depth].index_]);
95 return (*node_stack_[depth].node_);
101 ARILES2_TRACE_FUNCTION;
102 return (getRawNode(node_stack_.size() - 1));
116 std::ifstream config_ifs;
119 impl_->initialize(config_ifs);
126 impl_->initialize(input_stream);
132 ARILES2_TRACE_FUNCTION;
133 checkSize(limit_type,
impl_->getRawNode().via.map.size, min, max);
140 ARILES2_TRACE_FUNCTION;
141 ARILES2_TRACE_VALUE(child_name);
142 if (
impl_->node_stack_.empty())
144 for (std::size_t i = 0; i <
impl_->handles_.size(); ++i)
146 if (::msgpack::type::MAP ==
impl_->handles_[i]->get().type)
148 if (child_name ==
impl_->handles_[i]->get().via.map.ptr[0].key.as<std::string>())
150 if (::msgpack::type::MAP ==
impl_->handles_[i]->get().via.map.ptr[0].val.type)
152 impl_->node_stack_.push_back(
162 if (::msgpack::type::MAP ==
impl_->getRawNode().type)
164 for (std::size_t i = 0; i <
impl_->getRawNode().via.map.size; ++i)
166 if (child_name ==
impl_->getRawNode().via.map.ptr[i].key.as<std::string>())
181 ARILES2_TRACE_FUNCTION;
182 impl_->node_stack_.pop_back();
188 ARILES2_TRACE_FUNCTION;
189 const std::size_t size =
impl_->getRawNode().via.array.size;
198 ARILES2_TRACE_FUNCTION;
199 impl_->node_stack_.pop_back();
206 impl_->node_stack_.back().index_ <
impl_->node_stack_.back().size_,
207 "Internal error: namevalue.has more elements than expected.");
213 ARILES2_TRACE_FUNCTION;
214 ARILES2_ASSERT(
true ==
impl_->node_stack_.back().isArray(),
"Internal error: expected array.");
215 ++
impl_->node_stack_.back().index_;
221 ARILES2_TRACE_FUNCTION;
222 if (
true == name.empty())
225 0 ==
impl_->nameless_counter_,
226 "Multiple nameless root entries are not supported, specify root names explicitly.");
227 ++
impl_->nameless_counter_;
235 ARILES2_TRACE_FUNCTION;
240 #define ARILES2_BASIC_TYPE(type) \
241 void Reader::readElement(type &element) \
243 ARILES2_TRACE_FUNCTION; \
244 impl_->getRawNode() >> element; \
249 #undef ARILES2_BASIC_TYPE