node.h
Go to the documentation of this file.
00001 #ifndef NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
00002 #define NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
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/dll.h"
00010 #include "yaml-cpp-pm/exceptions.h"
00011 #include "yaml-cpp-pm/mark.h"
00012 #include "yaml-cpp-pm/noncopyable.h"
00013 #include "yaml-cpp-pm/conversion.h"
00014 #include "yaml-cpp-pm/iterator.h"
00015 #include "yaml-cpp-pm/ltnode.h"
00016 #include <iostream>
00017 #include <map>
00018 #include <memory>
00019 #include <string>
00020 #include <vector>
00021 
00022 namespace YAML_PM
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 typename enable_if<is_scalar_convertible<T> >::type 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 *FindValue(char *key) const;
00081                 const Node& operator [] (const char *key) const;
00082                 const Node& operator [] (char *key) const;
00083 
00084                 // for tags
00085                 const std::string& Tag() const { return m_tag; }
00086 
00087                 // emitting
00088                 friend YAML_CPP_API Emitter& operator << (Emitter& out, const Node& node);
00089 
00090                 // ordering
00091                 int Compare(const Node& rhs) const;
00092                 friend bool operator < (const Node& n1, const Node& n2);
00093 
00094         private:
00095                 explicit Node(NodeOwnership& owner);
00096                 Node& CreateNode();
00097                 
00098                 void Init(NodeType::value type, const Mark& mark, const std::string& tag);
00099                 
00100                 void MarkAsAliased();
00101                 void SetScalarData(const std::string& data);
00102                 void Append(Node& node);
00103                 void Insert(Node& key, Node& value);
00104 
00105                 // helper for sequences
00106                 template <typename, bool> friend struct _FindFromNodeAtIndex;
00107                 const Node *FindAtIndex(std::size_t i) const;
00108                 
00109                 // helper for maps
00110                 template <typename T>
00111                 const Node& GetValue(const T& key) const;
00112 
00113                 template <typename T>
00114                 const Node *FindValueForKey(const T& key) const;
00115 
00116         private:
00117                 std::auto_ptr<NodeOwnership> m_pOwnership;
00118 
00119                 Mark m_mark;
00120                 std::string m_tag;
00121 
00122                 typedef std::vector<Node *> node_seq;
00123                 typedef std::map<Node *, Node *, ltnode> node_map;
00124 
00125                 NodeType::value m_type;
00126                 std::string m_scalarData;
00127                 node_seq m_seqData;
00128                 node_map m_mapData;
00129         };
00130 }
00131 
00132 #include "yaml-cpp-pm/nodeimpl.h"
00133 #include "yaml-cpp-pm/nodereadimpl.h"
00134 
00135 #endif // NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66


upstream_src
Author(s):
autogenerated on Mon Oct 6 2014 10:27:42