Ariles
common.h
Go to the documentation of this file.
1 /**
2  @file
3  @author Alexander Sherikov
4 
5  @copyright 2018-2020 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 #pragma once
12 
13 
14 // In old versions of RapidJSON it is impossible to specify flags
15 // as template parameter of PrettyWriter, so this is the only way
16 // to change them.
17 #define RAPIDJSON_WRITE_DEFAULT_FLAGS ::rapidjson::kWriteNanAndInfFlag
18 #define RAPIDJSON_PARSE_DEFAULT_FLAGS ::rapidjson::kParseNanAndInfFlag
19 
20 
21 #include <boost/lexical_cast.hpp>
22 
23 #include <rapidjson/document.h>
24 
25 #include "istreamwrapper.h"
26 
27 
28 namespace ariles
29 {
30  namespace ns_rapidjson
31  {
32  template <class t_Node>
33  class ARILES_LIB_LOCAL ImplBase
34  {
35  public:
37 
38 
39  public:
40  /// instance of the parser
41  ::rapidjson::Document document_;
42 
43  /// Stack of nodes.
44  std::vector<NodeWrapper> node_stack_;
45 
46 
47  public:
48  /**
49  * @brief Get current node
50  *
51  * @return pointer to the current node
52  */
53  t_Node &getRawNode(const std::size_t depth)
54  {
55  if (node_stack_[depth].isArray())
56  {
57  return (getRawNode(depth - 1)[node_stack_[depth].index_]);
58  }
59  else
60  {
61  return (*node_stack_[depth].node_);
62  }
63  }
64 
65 
66  t_Node &getRawNode()
67  {
68  if (true == node_stack_.empty())
69  {
70  return (document_);
71  }
72  else
73  {
74  return (getRawNode(node_stack_.size() - 1));
75  }
76  }
77  };
78  } // namespace ns_rapidjson
79 } // namespace ariles
t_Node & getRawNode(const std::size_t depth)
Get current node.
Definition: common.h:53
std::vector< NodeWrapper > node_stack_
Stack of nodes.
Definition: common.h:44
ariles::Node< t_Node * > NodeWrapper
Definition: common.h:36
Copied from a newer version of RapidJSON to addd this functionality to older versions.
::rapidjson::Document document_
instance of the parser
Definition: common.h:41
Definition: basic.h:17