15 #include <msgpack.hpp> 39 std::vector<ARILES_SHARED_PTR< ::msgpack::object_handle> >
handles_;
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 ARILES_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 ARILES_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)
91 if (node_stack_[depth].isArray())
93 return (getRawNode(depth - 1).via.array.ptr[node_stack_[depth].index_]);
97 return (*node_stack_[depth].node_);
105 return (getRawNode(node_stack_.size() - 1));
119 std::ifstream config_ifs;
122 impl_->initialize(config_ifs);
129 impl_->initialize(input_stream);
136 return (
impl_->getRawNode().via.map.size);
145 if (
impl_->node_stack_.size() == 0)
147 for (std::size_t i = 0; i <
impl_->handles_.size(); ++i)
149 if (::msgpack::type::MAP ==
impl_->handles_[i]->get().type)
151 if (child_name ==
impl_->handles_[i]->get().via.map.ptr[0].key.as<std::string>())
153 if (::msgpack::type::MAP ==
impl_->handles_[i]->get().via.map.ptr[0].val.type)
155 impl_->node_stack_.push_back(
165 if (::msgpack::type::MAP ==
impl_->getRawNode().type)
167 for (std::size_t i = 0; i <
impl_->getRawNode().via.map.size; ++i)
169 if (child_name ==
impl_->getRawNode().via.map.ptr[i].key.as<std::string>())
185 impl_->node_stack_.pop_back();
192 std::size_t size =
impl_->getRawNode().via.array.size;
202 impl_->node_stack_.pop_back();
209 ARILES_ASSERT(
true ==
impl_->node_stack_.back().isArray(),
"Internal error: expected array.");
211 impl_->node_stack_.back().index_ <
impl_->node_stack_.back().size_,
212 "Internal error: array has more elements than expected.");
213 ++
impl_->node_stack_.back().index_;
220 if (
true == name.empty())
223 0 ==
impl_->nameless_counter_,
224 "Multiple nameless root entries are not supported, specify root names explicitly.");
225 ++
impl_->nameless_counter_;
241 #define ARILES_BASIC_TYPE(type) \ 242 void Reader::readElement(type &element) \ 244 ARILES_TRACE_FUNCTION; \ 245 impl_->getRawNode() >> element; \ 250 #undef ARILES_BASIC_TYPE bool descend(const std::string &child_name)
Descend to the entry with the given name.
#define ARILES_TRACE_FUNCTION
bool startRoot(const std::string &name)
std::size_t getMapSize(const bool)
static void openFile(std::ifstream &config_ifs, const std::string &file_name)
open configuration file
std::vector< ARILES_SHARED_PTR< ::msgpack::object_handle > > handles_
void ascend()
Ascend from the current entry to its parent.
#define ARILES_BASIC_TYPES_LIST
void initialize(std::istream &input_stream)
open configuration file
std::vector< NodeWrapper > node_stack_
Stack of nodes.
ARILES_MACRO_SUBSTITUTE(ARILES_BASIC_SIGNED_INTEGER_TYPES_LIST) ARILES_MACRO_SUBSTITUTE(ARILES_BASIC_UNSIGNED_INTEGER_TYPES_LIST) ARILES_MACRO_SUBSTITUTE(ARILES_BASIC_REAL_TYPES_LIST) void Reader
void endRoot(const std::string &name)
std::size_t nameless_counter_
const ::msgpack::object & getRawNode()
ariles::Node< const ::msgpack::object * > NodeWrapper
#define ARILES_VISIBILITY_ATTRIBUTE
ARILES_SHARED_PTR< impl::Reader > ImplPtr
#define ARILES_TRACE_ENTRY(entry_name)
const ::msgpack::object & getRawNode(const std::size_t depth)
Get current node.
Reader(const std::string &file_name)
Constructor.