nodeimpl.h
Go to the documentation of this file.
1 #ifndef NODEIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
2 #define NODEIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
3 
4 #if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
5 #pragma once
6 #endif
7 
8 
9 #include "yaml-cpp-pm/nodeutil.h"
10 #include <cassert>
11 
12 namespace YAML_PM
13 {
14  // implementation of templated things
15  template <typename T>
16  inline const T Node::to() const {
17  T value;
18  *this >> value;
19  return value;
20  }
21 
22  template <typename T>
23  inline typename enable_if<is_scalar_convertible<T> >::type operator >> (const Node& node, T& value) {
24  if(!ConvertScalar(node, value))
25  throw InvalidScalar(node.m_mark);
26  }
27 
28  template <typename T>
29  inline const Node *Node::FindValue(const T& key) const {
30  switch(m_type) {
31  case NodeType::Null:
32  case NodeType::Scalar:
33  throw BadDereference();
34  case NodeType::Sequence:
35  return FindFromNodeAtIndex(*this, key);
36  case NodeType::Map:
37  return FindValueForKey(key);
38  }
39  assert(false);
40  throw BadDereference();
41  }
42 
43  template <typename T>
44  inline const Node *Node::FindValueForKey(const T& key) const {
45  for(Iterator it=begin();it!=end();++it) {
46  T t;
47  if(it.first().Read(t)) {
48  if(key == t)
49  return &it.second();
50  }
51  }
52 
53  return 0;
54  }
55 
56  template <typename T>
57  inline const Node& Node::GetValue(const T& key) const {
58  if(const Node *pValue = FindValue(key))
59  return *pValue;
60  throw MakeTypedKeyNotFound(m_mark, key);
61  }
62 
63  template <typename T>
64  inline const Node& Node::operator [] (const T& key) const {
65  return GetValue(key);
66  }
67 
68  inline const Node *Node::FindValue(const char *key) const {
69  return FindValue(std::string(key));
70  }
71 
72  inline const Node *Node::FindValue(char *key) const {
73  return FindValue(std::string(key));
74  }
75 
76  inline const Node& Node::operator [] (const char *key) const {
77  return GetValue(std::string(key));
78  }
79 
80  inline const Node& Node::operator [] (char *key) const {
81  return GetValue(std::string(key));
82  }
83 }
84 
85 #endif // NODEIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
bool ConvertScalar(const Node &node, T &value)
Definition: nodereadimpl.h:77
::std::string string
Definition: gtest.h:1979
Mark m_mark
Definition: node.h:119
Iterator begin() const
Definition: node.cpp:141
const Node * FindFromNodeAtIndex(const Node &node, const T &key)
Definition: nodeutil.h:57
Iterator end() const
Definition: node.cpp:159
NodeType::value m_type
Definition: node.h:125
const Node & GetValue(const T &key) const
Definition: nodeimpl.h:57
const Node & operator[](const T &key) const
Definition: nodeimpl.h:64
const Node * FindValue(const T &key) const
Definition: nodeimpl.h:29
friend YAML_CPP_API enable_if< is_scalar_convertible< T > >::type operator>>(const Node &node, T &value)
Definition: nodeimpl.h:23
const Node * FindValueForKey(const T &key) const
Definition: nodeimpl.h:44
const T to() const
Definition: nodeimpl.h:16
TypedKeyNotFound< T > MakeTypedKeyNotFound(const Mark &mark, const T &key)
Definition: exceptions.h:147


libpointmatcher
Author(s):
autogenerated on Sat May 27 2023 02:38:02