Line data Source code
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; 42 : using const_iterator = YAML::const_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 29918 : bool IsScalar() const { return Type() == NodeType::Scalar; } 57 20 : bool IsSequence() const { return Type() == NodeType::Sequence; } 58 631 : 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 : 71 : const std::string& Tag() const; 72 : void SetTag(const std::string& tag); 73 : 74 : // style 75 : // WARNING: This API might change in future releases. 76 : EmitterStyle::value Style() const; 77 : void SetStyle(EmitterStyle::value style); 78 : 79 : // assignment 80 : bool is(const Node& rhs) const; 81 : template <typename T> 82 : Node& operator=(const T& rhs); 83 : Node& operator=(const Node& rhs); 84 : void reset(const Node& rhs = Node()); 85 : 86 : // size/iterator 87 : std::size_t size() const; 88 : 89 : const_iterator begin() const; 90 : iterator begin(); 91 : 92 : const_iterator end() const; 93 : iterator end(); 94 : 95 : // sequence 96 : template <typename T> 97 : void push_back(const T& rhs); 98 : void push_back(const Node& rhs); 99 : 100 : // indexing 101 : template <typename Key> 102 : const Node operator[](const Key& key) const; 103 : template <typename Key> 104 : Node operator[](const Key& key); 105 : template <typename Key> 106 : bool remove(const Key& key); 107 : 108 : const Node operator[](const Node& key) const; 109 : Node operator[](const Node& key); 110 : bool remove(const Node& key); 111 : 112 : // map 113 : template <typename Key, typename Value> 114 : void force_insert(const Key& key, const Value& value); 115 : 116 : private: 117 : enum Zombie { ZombieNode }; 118 : explicit Node(Zombie); 119 : explicit Node(Zombie, const std::string&); 120 : explicit Node(detail::node& node, detail::shared_memory_holder pMemory); 121 : 122 : void EnsureNodeExists() const; 123 : 124 : template <typename T> 125 : void Assign(const T& rhs); 126 : void Assign(const char* rhs); 127 : void Assign(char* rhs); 128 : 129 : void AssignData(const Node& rhs); 130 : void AssignNode(const Node& rhs); 131 : 132 : private: 133 : bool m_isValid; 134 : // String representation of invalid key, if the node is invalid. 135 : std::string m_invalidKey; 136 : mutable detail::shared_memory_holder m_pMemory; 137 : mutable detail::node* m_pNode; 138 : }; 139 : 140 : YAML_CPP_API bool operator==(const Node& lhs, const Node& rhs); 141 : 142 : YAML_CPP_API Node Clone(const Node& node); 143 : 144 : template <typename T> 145 : struct convert; 146 : } 147 : 148 : #endif // NODE_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66