00001 #pragma once
00002
00003 #ifndef NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
00004 #define NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
00005
00006
00007 #include "conversion.h"
00008 #include "exceptions.h"
00009 #include "iterator.h"
00010 #include "mark.h"
00011 #include "noncopyable.h"
00012 #include <iostream>
00013 #include <string>
00014 #include <vector>
00015 #include <map>
00016 #include <memory>
00017
00018 namespace YAML
00019 {
00020 class Content;
00021 class Scanner;
00022 class Emitter;
00023 struct ParserState;
00024
00025 enum CONTENT_TYPE { CT_NONE, CT_SCALAR, CT_SEQUENCE, CT_MAP };
00026
00027 class Node: private noncopyable
00028 {
00029 public:
00030 Node();
00031 ~Node();
00032
00033 void Clear();
00034 std::auto_ptr<Node> Clone() const;
00035 void Parse(Scanner *pScanner, ParserState& state);
00036
00037 CONTENT_TYPE GetType() const;
00038
00039
00040 const Mark GetMark() const { return m_mark; }
00041
00042
00043 Iterator begin() const;
00044 Iterator end() const;
00045 std::size_t size() const;
00046
00047
00048 bool GetScalar(std::string& s) const;
00049
00050
00051 template <typename T>
00052 bool Read(T& value) const;
00053
00054 template <typename T>
00055 const T Read() const;
00056
00057 template <typename T>
00058 operator T() const;
00059
00060 template <typename T>
00061 friend void operator >> (const Node& node, T& value);
00062
00063
00064 template <typename T>
00065 const Node *FindValue(const T& key) const;
00066
00067 template <typename T>
00068 const Node& operator [] (const T& key) const;
00069
00070
00071 const Node *FindValue(const char *key) const;
00072 const Node& operator [] (const char *key) const;
00073
00074
00075 const Node *Identity() const { return m_pIdentity; }
00076 bool IsAlias() const { return m_alias; }
00077 bool IsReferenced() const { return m_referenced; }
00078
00079
00080 const std::string GetTag() const { return IsAlias() ? m_pIdentity->GetTag() : m_tag; }
00081
00082
00083 friend Emitter& operator << (Emitter& out, const Node& node);
00084
00085
00086 int Compare(const Node& rhs) const;
00087 friend bool operator < (const Node& n1, const Node& n2);
00088
00089 private:
00090
00091 template <typename, bool> friend struct _FindFromNodeAtIndex;
00092 const Node *FindAtIndex(std::size_t i) const;
00093
00094
00095 template <typename T>
00096 const Node& GetValue(const T& key) const;
00097
00098 template <typename T>
00099 const Node *FindValueForKey(const T& key) const;
00100
00101
00102 Node(const Mark& mark, const std::string& anchor, const std::string& tag, const Content *pContent);
00103
00104
00105 void ParseHeader(Scanner *pScanner, ParserState& state);
00106 void ParseTag(Scanner *pScanner, ParserState& state);
00107 void ParseAnchor(Scanner *pScanner, ParserState& state);
00108 void ParseAlias(Scanner *pScanner, ParserState& state);
00109
00110 private:
00111 Mark m_mark;
00112 std::string m_anchor, m_tag;
00113 Content *m_pContent;
00114 bool m_alias;
00115 const Node *m_pIdentity;
00116 mutable bool m_referenced;
00117 };
00118
00119
00120 template <typename T>
00121 bool operator == (const T& value, const Node& node);
00122
00123 template <typename T>
00124 bool operator == (const Node& node, const T& value);
00125
00126 template <typename T>
00127 bool operator != (const T& value, const Node& node);
00128
00129 template <typename T>
00130 bool operator != (const Node& node, const T& value);
00131
00132 bool operator == (const char *value, const Node& node);
00133 bool operator == (const Node& node, const char *value);
00134 bool operator != (const char *value, const Node& node);
00135 bool operator != (const Node& node, const char *value);
00136 }
00137
00138 #include "nodeimpl.h"
00139 #include "nodereadimpl.h"
00140
00141 #endif // NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66