My Project
node.h
1 #ifndef NODE_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
2 #define NODE_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
3 
4 #if defined(_MSC_VER) || \
5  (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
6  (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
7 #pragma once
8 #endif
9 
10 #include <stdexcept>
11 #include <string>
12 
13 #include "yaml-cpp/dll.h"
14 #include "yaml-cpp/emitterstyle.h"
15 #include "yaml-cpp/mark.h"
16 #include "yaml-cpp/node/detail/iterator_fwd.h"
17 #include "yaml-cpp/node/ptr.h"
18 #include "yaml-cpp/node/type.h"
19 
20 namespace YAML {
21 namespace detail {
22 class node;
23 class node_data;
24 struct iterator_value;
25 } // namespace detail
26 } // namespace YAML
27 
28 namespace YAML {
29 class YAML_CPP_API Node {
30  public:
31  friend class NodeBuilder;
32  friend class NodeEvents;
33  friend struct detail::iterator_value;
34  friend class detail::node;
35  friend class detail::node_data;
36  template <typename>
37  friend class detail::iterator_base;
38  template <typename T, typename S>
39  friend struct as_if;
40 
41  using iterator = YAML::iterator;
43 
44  Node();
45  explicit Node(NodeType::value type);
46  template <typename T>
47  explicit Node(const T& rhs);
48  explicit Node(const detail::iterator_value& rhs);
49  Node(const Node& rhs);
50  ~Node();
51 
52  YAML::Mark Mark() const;
53  NodeType::value Type() const;
54  bool IsDefined() const;
55  bool IsNull() const { return Type() == NodeType::Null; }
56  bool IsScalar() const { return Type() == NodeType::Scalar; }
57  bool IsSequence() const { return Type() == NodeType::Sequence; }
58  bool IsMap() const { return Type() == NodeType::Map; }
59 
60  // bool conversions
61  explicit operator bool() const { return IsDefined(); }
62  bool operator!() const { return !IsDefined(); }
63 
64  // access
65  template <typename T>
66  T as() const;
67  template <typename T, typename S>
68  T as(const S& fallback) const;
69  const std::string& Scalar() const;
70  const std::string& UninstrumentedScalarForTesting() const;
71 
72  const std::string& Tag() const;
73  void SetTag(const std::string& tag);
74 
75  // style
76  // WARNING: This API might change in future releases.
77  EmitterStyle::value Style() const;
78  void SetStyle(EmitterStyle::value style);
79 
80  // assignment
81  bool is(const Node& rhs) const;
82  template <typename T>
83  Node& operator=(const T& rhs);
84  Node& operator=(const Node& rhs);
85  void reset(const Node& rhs = Node());
86 
87  // size/iterator
88  std::size_t size() const;
89 
90  const_iterator begin() const;
91  iterator begin();
92 
93  const_iterator end() const;
94  iterator end();
95 
96  // sequence
97  template <typename T>
98  void push_back(const T& rhs);
99  void push_back(const Node& rhs);
100 
101  // indexing
102  template <typename Key>
103  const Node operator[](const Key& key) const;
104  template <typename Key>
105  Node operator[](const Key& key);
106  template <typename Key>
107  bool remove(const Key& key);
108 
109  const Node operator[](const Node& key) const;
110  Node operator[](const Node& key);
111  bool remove(const Node& key);
112 
113  // map
114  template <typename Key, typename Value>
115  void force_insert(const Key& key, const Value& value);
116 
117  private:
118  enum Zombie { ZombieNode };
119  explicit Node(Zombie);
120  explicit Node(Zombie, const std::string&);
121  explicit Node(detail::node& node, detail::shared_memory_holder pMemory);
122 
123  void EnsureNodeExists() const;
124  void Invalidate();
125 
126  template <typename T>
127  void Assign(const T& rhs);
128  void Assign(const char* rhs);
129  void Assign(char* rhs);
130 
131  void AssignData(const Node& rhs);
132  void AssignNode(const Node& rhs);
133 
134  private:
135  bool m_isValid;
136  // String representation of invalid key, if the node is invalid.
137  std::string m_invalidKey;
138  mutable detail::shared_memory_holder m_pMemory;
139  mutable detail::node* m_pNode;
140 };
141 
142 YAML_CPP_API bool operator==(const Node& lhs, const Node& rhs);
143 
144 YAML_CPP_API Node Clone(const Node& node);
145 
146 template <typename T>
147 struct convert;
148 }
149 
150 #endif // NODE_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
Definition: mark.h:13
Definition: node_data.h:30
Definition: iterator.h:23
Definition: iterator.h:23
Definition: tag.h:16
Definition: convert.h:38
Definition: node.h:20
Definition: impl.h:98
Definition: nodeevents.h:26
Definition: anchor.h:12
Definition: node.h:29
Definition: nodebuilder.h:27