1 #ifndef NODE_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 #define NODE_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 4 #if defined(_MSC_VER) || \ 5 (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 10 #include "yaml-cpp/node/node.h" 11 #include "yaml-cpp/node/iterator.h" 12 #include "yaml-cpp/node/detail/memory.h" 13 #include "yaml-cpp/node/detail/node.h" 14 #include "yaml-cpp/exceptions.h" 18 inline Node::Node() : m_isValid(true), m_pNode(NULL) {}
20 inline Node::Node(NodeType::value type)
22 m_pMemory(new detail::memory_holder),
23 m_pNode(&m_pMemory->create_node()) {
24 m_pNode->set_type(type);
28 inline Node::Node(
const T& rhs)
30 m_pMemory(new detail::memory_holder),
31 m_pNode(&m_pMemory->create_node()) {
35 inline Node::Node(
const detail::iterator_value& rhs)
36 : m_isValid(rhs.m_isValid),
37 m_pMemory(rhs.m_pMemory),
38 m_pNode(rhs.m_pNode) {}
40 inline Node::Node(
const Node& rhs)
41 : m_isValid(rhs.m_isValid),
42 m_pMemory(rhs.m_pMemory),
43 m_pNode(rhs.m_pNode) {}
45 inline Node::Node(Zombie) : m_isValid(false), m_pNode(NULL) {}
47 inline Node::Node(detail::node& node, detail::shared_memory_holder pMemory)
48 : m_isValid(true), m_pMemory(pMemory), m_pNode(&node) {}
50 inline Node::~Node() {}
52 inline void Node::EnsureNodeExists()
const {
56 m_pMemory.reset(
new detail::memory_holder);
57 m_pNode = &m_pMemory->create_node();
62 inline bool Node::IsDefined()
const {
66 return m_pNode ? m_pNode->is_defined() :
true;
69 inline Mark Node::Mark()
const {
73 return m_pNode ? m_pNode->mark() : Mark::null_mark();
76 inline NodeType::value Node::Type()
const {
79 return m_pNode ? m_pNode->type() : NodeType::Null;
85 template <
typename T,
typename S>
87 explicit as_if(
const Node& node_) : node(node_) {}
90 T operator()(
const S& fallback)
const {
101 template <
typename S>
103 explicit as_if(
const Node& node_) : node(node_) {}
106 std::string operator()(
const S& fallback)
const {
107 if (node.Type() != NodeType::Scalar)
109 return node.Scalar();
113 template <
typename T>
115 explicit as_if(
const Node& node_) : node(node_) {}
118 T operator()()
const {
131 explicit as_if(
const Node& node_) : node(node_) {}
134 std::string operator()()
const {
135 if (node.Type() != NodeType::Scalar)
137 return node.Scalar();
142 template <
typename T>
143 inline T Node::as()
const {
149 template <
typename T,
typename S>
150 inline T Node::as(
const S& fallback)
const {
156 inline const std::string& Node::Scalar()
const {
159 return m_pNode ? m_pNode->scalar() : detail::node_data::empty_scalar;
162 inline const std::string& Node::Tag()
const {
165 return m_pNode ? m_pNode->tag() : detail::node_data::empty_scalar;
168 inline void Node::SetTag(
const std::string& tag) {
172 m_pNode->set_tag(tag);
175 inline EmitterStyle::value Node::Style()
const {
178 return m_pNode ? m_pNode->style() : EmitterStyle::Default;
181 inline void Node::SetStyle(EmitterStyle::value style) {
185 m_pNode->set_style(style);
189 inline bool Node::is(
const Node& rhs)
const {
190 if (!m_isValid || !rhs.m_isValid)
192 if (!m_pNode || !rhs.m_pNode)
194 return m_pNode->is(*rhs.m_pNode);
197 template <
typename T>
198 inline Node& Node::operator=(
const T& rhs) {
205 inline void Node::reset(
const YAML::Node& rhs) {
206 if (!m_isValid || !rhs.m_isValid)
208 m_pMemory = rhs.m_pMemory;
209 m_pNode = rhs.m_pNode;
212 template <
typename T>
213 inline void Node::Assign(
const T& rhs) {
220 inline void Node::Assign(
const std::string& rhs) {
224 m_pNode->set_scalar(rhs);
227 inline void Node::Assign(
const char* rhs) {
231 m_pNode->set_scalar(rhs);
234 inline void Node::Assign(
char* rhs) {
238 m_pNode->set_scalar(rhs);
241 inline Node& Node::operator=(
const Node& rhs) {
242 if (!m_isValid || !rhs.m_isValid)
250 inline void Node::AssignData(
const Node& rhs) {
251 if (!m_isValid || !rhs.m_isValid)
254 rhs.EnsureNodeExists();
256 m_pNode->set_data(*rhs.m_pNode);
257 m_pMemory->merge(*rhs.m_pMemory);
260 inline void Node::AssignNode(
const Node& rhs) {
261 if (!m_isValid || !rhs.m_isValid)
263 rhs.EnsureNodeExists();
266 m_pNode = rhs.m_pNode;
267 m_pMemory = rhs.m_pMemory;
271 m_pNode->set_ref(*rhs.m_pNode);
272 m_pMemory->merge(*rhs.m_pMemory);
273 m_pNode = rhs.m_pNode;
277 inline std::size_t Node::size()
const {
280 return m_pNode ? m_pNode->size() : 0;
309 template <
typename T>
310 inline void Node::push_back(
const T& rhs) {
313 push_back(
Node(rhs));
316 inline void Node::push_back(
const Node& rhs) {
317 if (!m_isValid || !rhs.m_isValid)
320 rhs.EnsureNodeExists();
322 m_pNode->push_back(*rhs.m_pNode, m_pMemory);
323 m_pMemory->merge(*rhs.m_pMemory);
328 template <
typename T>
332 typedef const T& return_type;
334 const T& operator()()
const {
return t; }
339 explicit to_value_t(
const char* t_) : t(t_) {}
341 typedef std::string return_type;
343 const std::string operator()()
const {
return t; }
350 typedef std::string return_type;
352 const std::string operator()()
const {
return t; }
355 template <std::
size_t N>
357 explicit to_value_t(
const char* t_) : t(t_) {}
359 typedef std::string return_type;
361 const std::string operator()()
const {
return t; }
365 template <
typename T>
366 inline typename to_value_t<T>::return_type to_value(
const T& t) {
372 template <
typename Key>
373 inline const Node Node::operator[](
const Key& key)
const {
378 .get(detail::to_value(key), m_pMemory);
380 return Node(ZombieNode);
382 return Node(*value, m_pMemory);
385 template <
typename Key>
386 inline Node Node::operator[](
const Key& key) {
390 detail::node& value = m_pNode->get(detail::to_value(key), m_pMemory);
391 return Node(value, m_pMemory);
394 template <
typename Key>
395 inline bool Node::remove(
const Key& key) {
399 return m_pNode->remove(detail::to_value(key), m_pMemory);
402 inline const Node Node::operator[](
const Node& key)
const {
403 if (!m_isValid || !key.m_isValid)
406 key.EnsureNodeExists();
407 m_pMemory->merge(*key.m_pMemory);
409 static_cast<const detail::node&
>(*m_pNode).get(*key.m_pNode, m_pMemory);
411 return Node(ZombieNode);
413 return Node(*value, m_pMemory);
416 inline Node Node::operator[](
const Node& key) {
417 if (!m_isValid || !key.m_isValid)
420 key.EnsureNodeExists();
421 m_pMemory->merge(*key.m_pMemory);
422 detail::node& value = m_pNode->get(*key.m_pNode, m_pMemory);
423 return Node(value, m_pMemory);
426 inline bool Node::remove(
const Node& key) {
427 if (!m_isValid || !key.m_isValid)
430 key.EnsureNodeExists();
431 return m_pNode->remove(*key.m_pNode, m_pMemory);
435 template <
typename Key,
typename Value>
436 inline void Node::force_insert(
const Key& key,
const Value& value) {
440 m_pNode->force_insert(detail::to_value(key), detail::to_value(value),
445 inline bool operator==(
const Node& lhs,
const Node& rhs) {
return lhs.is(rhs); }
448 #endif // NODE_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
Definition: iterator.h:21
Definition: _tbb_windef.h:37
Definition: exceptions.h:204
Definition: exceptions.h:187
Definition: DrawableObjectLoader.h:10