nodeimpl.h
Go to the documentation of this file.
00001 #ifndef NODEIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
00002 #define NODEIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
00003 
00004 #if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
00005 #pragma once
00006 #endif
00007 
00008 
00009 #include "yaml-cpp-pm/nodeutil.h"
00010 #include <cassert>
00011 
00012 namespace YAML_PM
00013 {
00014         // implementation of templated things
00015         template <typename T>
00016         inline const T Node::to() const {
00017                 T value;
00018                 *this >> value;
00019                 return value;
00020         }
00021 
00022         template <typename T>
00023         inline typename enable_if<is_scalar_convertible<T> >::type operator >> (const Node& node, T& value) {
00024                 if(!ConvertScalar(node, value))
00025                         throw InvalidScalar(node.m_mark);
00026         }
00027         
00028         template <typename T>
00029         inline const Node *Node::FindValue(const T& key) const {
00030                 switch(m_type) {
00031                         case NodeType::Null:
00032                         case NodeType::Scalar:
00033                                 throw BadDereference();
00034                         case NodeType::Sequence:
00035                                 return FindFromNodeAtIndex(*this, key);
00036                         case NodeType::Map:
00037                                 return FindValueForKey(key);
00038                 }
00039                 assert(false);
00040                 throw BadDereference();
00041         }
00042         
00043         template <typename T>
00044         inline const Node *Node::FindValueForKey(const T& key) const {
00045                 for(Iterator it=begin();it!=end();++it) {
00046                         T t;
00047                         if(it.first().Read(t)) {
00048                                 if(key == t)
00049                                         return &it.second();
00050                         }
00051                 }
00052                 
00053                 return 0;
00054         }
00055         
00056         template <typename T>
00057         inline const Node& Node::GetValue(const T& key) const {
00058                 if(const Node *pValue = FindValue(key))
00059                         return *pValue;
00060                 throw MakeTypedKeyNotFound(m_mark, key);
00061         }
00062         
00063         template <typename T>
00064         inline const Node& Node::operator [] (const T& key) const {
00065                 return GetValue(key);
00066         }
00067         
00068         inline const Node *Node::FindValue(const char *key) const {
00069                 return FindValue(std::string(key));
00070         }
00071 
00072         inline const Node *Node::FindValue(char *key) const {
00073                 return FindValue(std::string(key));
00074         }
00075         
00076         inline const Node& Node::operator [] (const char *key) const {
00077                 return GetValue(std::string(key));
00078         }
00079 
00080         inline const Node& Node::operator [] (char *key) const {
00081                 return GetValue(std::string(key));
00082         }
00083 }
00084 
00085 #endif // NODEIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM


libpointmatcher
Author(s):
autogenerated on Thu Jun 20 2019 19:51:31