|
Video Processing Framework
|
00001 #ifndef NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 00002 #define NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 00003 00004 #if !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/conversion.h" 00010 #include "yaml-cpp/dll.h" 00011 #include "yaml-cpp/exceptions.h" 00012 #include "yaml-cpp/iterator.h" 00013 #include "yaml-cpp/ltnode.h" 00014 #include "yaml-cpp/mark.h" 00015 #include "yaml-cpp/noncopyable.h" 00016 #include <iostream> 00017 #include <map> 00018 #include <memory> 00019 #include <string> 00020 #include <vector> 00021 00022 namespace YAML 00023 { 00024 class AliasManager; 00025 class Content; 00026 class NodeOwnership; 00027 class Scanner; 00028 class Emitter; 00029 class EventHandler; 00030 00031 struct NodeType { enum value { Null, Scalar, Sequence, Map }; }; 00032 00033 class YAML_CPP_API Node: private noncopyable 00034 { 00035 public: 00036 friend class NodeOwnership; 00037 friend class NodeBuilder; 00038 00039 Node(); 00040 ~Node(); 00041 00042 void Clear(); 00043 std::auto_ptr<Node> Clone() const; 00044 void EmitEvents(EventHandler& eventHandler) const; 00045 void EmitEvents(AliasManager& am, EventHandler& eventHandler) const; 00046 00047 NodeType::value Type() const { return m_type; } 00048 bool IsAliased() const; 00049 00050 // file location of start of this node 00051 const Mark GetMark() const { return m_mark; } 00052 00053 // accessors 00054 Iterator begin() const; 00055 Iterator end() const; 00056 std::size_t size() const; 00057 00058 // extraction of scalars 00059 bool GetScalar(std::string& s) const; 00060 00061 // we can specialize this for other values 00062 template <typename T> 00063 bool Read(T& value) const; 00064 00065 template <typename T> 00066 const T to() const; 00067 00068 template <typename T> 00069 friend YAML_CPP_API void operator >> (const Node& node, T& value); 00070 00071 // retrieval for maps and sequences 00072 template <typename T> 00073 const Node *FindValue(const T& key) const; 00074 00075 template <typename T> 00076 const Node& operator [] (const T& key) const; 00077 00078 // specific to maps 00079 const Node *FindValue(const char *key) const; 00080 const Node& operator [] (const char *key) const; 00081 00082 // for tags 00083 const std::string& Tag() const { return m_tag; } 00084 00085 // emitting 00086 friend YAML_CPP_API Emitter& operator << (Emitter& out, const Node& node); 00087 00088 // ordering 00089 int Compare(const Node& rhs) const; 00090 friend bool operator < (const Node& n1, const Node& n2); 00091 00092 private: 00093 explicit Node(NodeOwnership& owner); 00094 Node& CreateNode(); 00095 00096 void Init(NodeType::value type, const Mark& mark, const std::string& tag); 00097 00098 void MarkAsAliased(); 00099 void SetScalarData(const std::string& data); 00100 void Append(Node& node); 00101 void Insert(Node& key, Node& value); 00102 00103 // helper for sequences 00104 template <typename, bool> friend struct _FindFromNodeAtIndex; 00105 const Node *FindAtIndex(std::size_t i) const; 00106 00107 // helper for maps 00108 template <typename T> 00109 const Node& GetValue(const T& key) const; 00110 00111 template <typename T> 00112 const Node *FindValueForKey(const T& key) const; 00113 00114 private: 00115 std::auto_ptr<NodeOwnership> m_pOwnership; 00116 00117 Mark m_mark; 00118 std::string m_tag; 00119 00120 typedef std::vector<Node *> node_seq; 00121 typedef std::map<Node *, Node *, ltnode> node_map; 00122 00123 NodeType::value m_type; 00124 std::string m_scalarData; 00125 node_seq m_seqData; 00126 node_map m_mapData; 00127 }; 00128 } 00129 00130 #include "yaml-cpp/nodeimpl.h" 00131 #include "yaml-cpp/nodereadimpl.h" 00132 00133 #endif // NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66