00001 #pragma once
00002
00003 #ifndef NODEIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
00004 #define NODEIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
00005
00006
00007 #include "nodeutil.h"
00008
00009 namespace YAML
00010 {
00011
00012 template <typename T>
00013 inline const T Node::Read() const {
00014 T value;
00015 *this >> value;
00016 return value;
00017 }
00018
00019 template <typename T>
00020 Node::operator T() const {
00021 return Read<T>();
00022 }
00023
00024 template <typename T>
00025 inline void operator >> (const Node& node, T& value) {
00026 if(!ConvertScalar(node, value))
00027 throw InvalidScalar(node.m_mark);
00028 }
00029
00030 template <typename T>
00031 inline const Node *Node::FindValue(const T& key) const {
00032 switch(GetType()) {
00033 case CT_MAP:
00034 return FindValueForKey(key);
00035 case CT_SEQUENCE:
00036 return FindFromNodeAtIndex(*this, key);
00037 default:
00038 return 0;
00039 }
00040 }
00041
00042 template <typename T>
00043 inline const Node *Node::FindValueForKey(const T& key) const {
00044 for(Iterator it=begin();it!=end();++it) {
00045 T t;
00046 if(it.first().Read(t)) {
00047 if(key == t)
00048 return &it.second();
00049 }
00050 }
00051
00052 return 0;
00053 }
00054
00055 template <typename T>
00056 inline const Node& Node::GetValue(const T& key) const {
00057 if(!m_pContent)
00058 throw BadDereference();
00059
00060 const Node *pValue = FindValue(key);
00061 if(!pValue)
00062 throw MakeTypedKeyNotFound(m_mark, key);
00063
00064 return *pValue;
00065 }
00066
00067 template <typename T>
00068 inline const Node& Node::operator [] (const T& key) const {
00069 return GetValue(key);
00070 }
00071
00072 inline const Node *Node::FindValue(const 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 template <typename T>
00081 inline bool operator == (const T& value, const Node& node) {
00082 return value == node.operator T();
00083 }
00084
00085 template <typename T>
00086 inline bool operator == (const Node& node, const T& value) {
00087 return value == node.operator T();
00088 }
00089
00090 template <typename T>
00091 inline bool operator != (const T& value, const Node& node) {
00092 return value != node.operator T();
00093 }
00094
00095 template <typename T>
00096 inline bool operator != (const Node& node, const T& value) {
00097 return value != node.operator T();
00098 }
00099
00100 inline bool operator == (const char *value, const Node& node) {
00101 return std::string(value) == node;
00102 }
00103
00104 inline bool operator == (const Node& node, const char *value) {
00105 return std::string(value) == node;
00106 }
00107
00108 inline bool operator != (const char *value, const Node& node) {
00109 return std::string(value) != node;
00110 }
00111
00112 inline bool operator != (const Node& node, const char *value) {
00113 return std::string(value) != node;
00114 }
00115
00116 }
00117
00118 #endif // NODEIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66