node.h 2.43 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#ifndef NODE_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define NODE_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66

#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif


#include "yaml-cpp/dll.h"
#include "yaml-cpp/node/ptr.h"
#include "yaml-cpp/node/type.h"
#include "yaml-cpp/node/detail/iterator_fwd.h"
#include <stdexcept>

namespace YAML
{
	class Node
	{
	public:
		friend class NodeBuilder;
		friend class NodeEvents;
		friend class detail::node_data;
		template<typename, typename, typename> friend class detail::iterator_base;
		
		Node();
		explicit Node(NodeType::value type);
		template<typename T> explicit Node(const T& rhs);
		Node(const Node& rhs);
		~Node();
		
		NodeType::value Type() const;
		
		// access
		template<typename T> const T as() const;
beder's avatar
beder committed
35
36
37
38
		const std::string& Scalar() const;
		const std::string& Tag() const;
		void SetTag(const std::string& tag);

39
40
41
42
		// assignment
		bool is(const Node& rhs) const;
		template<typename T> Node& operator=(const T& rhs);
		Node& operator=(const Node& rhs);
beder's avatar
beder committed
43

44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
		// size/iterator
		std::size_t size() const;

		const_iterator begin() const;
		iterator begin();
		
		const_iterator end() const;
		iterator end();
		
		// sequence
		template<typename T> void append(const T& rhs);
		void append(const Node& rhs);
		
		// indexing
		template<typename Key> const Node operator[](const Key& key) const;
		template<typename Key> Node operator[](const Key& key);
		template<typename Key> bool remove(const Key& key);

		const Node operator[](const Node& key) const;
		Node operator[](const Node& key);
		bool remove(const Node& key);
		
		const Node operator[](const char *key) const;
		Node operator[](const char *key);
		bool remove(const char *key);

		const Node operator[](char *key) const;
		Node operator[](char *key);
		bool remove(char *key);
		
	private:
		explicit Node(detail::node& node, detail::shared_memory_holder pMemory);
		
77
78
		void EnsureNodeExists() const;
		
79
80
81
82
83
84
85
86
		template<typename T> void Assign(const T& rhs);
		void Assign(const char *rhs);
		void Assign(char *rhs);

		void AssignData(const Node& rhs);
		void AssignNode(const Node& rhs);
		
	private:
87
88
		mutable detail::shared_memory_holder m_pMemory;
		mutable detail::node *m_pNode;
89
	};
90
91

	bool operator==(const Node& lhs, const Node& rhs);
92
93
94
95
96
97
	
	template<typename T>
	struct convert;
}

#endif // NODE_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66