2009-07-30 02:27:20 +04:00
|
|
|
#ifndef NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
|
|
|
|
#define NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
|
|
|
|
|
2011-09-06 09:16:03 +04:00
|
|
|
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
2011-03-02 09:11:41 +03:00
|
|
|
#pragma once
|
|
|
|
|
#endif
|
|
|
|
|
|
2009-07-30 02:27:20 +04:00
|
|
|
|
2011-03-16 05:31:30 +03:00
|
|
|
#include "yaml-cpp/dll.h"
|
2010-10-18 11:22:53 +04:00
|
|
|
#include "yaml-cpp/exceptions.h"
|
|
|
|
|
#include "yaml-cpp/mark.h"
|
|
|
|
|
#include "yaml-cpp/noncopyable.h"
|
2011-10-19 00:13:10 +04:00
|
|
|
#include "yaml-cpp/old-api/conversion.h"
|
2011-09-11 08:11:28 +04:00
|
|
|
#include "yaml-cpp/old-api/iterator.h"
|
|
|
|
|
#include "yaml-cpp/old-api/ltnode.h"
|
2009-07-12 06:59:23 +04:00
|
|
|
#include <iostream>
|
2009-07-27 06:56:18 +04:00
|
|
|
#include <map>
|
2009-08-25 00:10:42 +04:00
|
|
|
#include <memory>
|
2011-03-03 03:19:26 +03:00
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
2008-09-04 02:20:39 +04:00
|
|
|
|
|
|
|
|
namespace YAML
|
|
|
|
|
{
|
2010-10-18 10:45:03 +04:00
|
|
|
class AliasManager;
|
2008-09-04 02:20:39 +04:00
|
|
|
class Content;
|
2011-03-03 03:19:26 +03:00
|
|
|
class NodeOwnership;
|
2008-09-04 02:20:39 +04:00
|
|
|
class Scanner;
|
2009-07-11 03:39:14 +04:00
|
|
|
class Emitter;
|
2010-10-18 10:45:03 +04:00
|
|
|
class EventHandler;
|
2008-09-04 02:20:39 +04:00
|
|
|
|
2011-03-03 03:19:26 +03:00
|
|
|
struct NodeType { enum value { Null, Scalar, Sequence, Map }; };
|
2008-09-04 02:20:39 +04:00
|
|
|
|
2011-03-16 05:31:30 +03:00
|
|
|
class YAML_CPP_API Node: private noncopyable
|
2008-09-04 02:20:39 +04:00
|
|
|
{
|
|
|
|
|
public:
|
2011-03-03 03:19:26 +03:00
|
|
|
friend class NodeOwnership;
|
|
|
|
|
friend class NodeBuilder;
|
|
|
|
|
|
2008-09-04 02:20:39 +04:00
|
|
|
Node();
|
|
|
|
|
~Node();
|
|
|
|
|
|
|
|
|
|
void Clear();
|
2009-08-25 00:10:42 +04:00
|
|
|
std::auto_ptr<Node> Clone() const;
|
2010-10-18 10:45:03 +04:00
|
|
|
void EmitEvents(EventHandler& eventHandler) const;
|
|
|
|
|
void EmitEvents(AliasManager& am, EventHandler& eventHandler) const;
|
|
|
|
|
|
2011-03-03 03:19:26 +03:00
|
|
|
NodeType::value Type() const { return m_type; }
|
|
|
|
|
bool IsAliased() const;
|
2008-09-04 02:20:39 +04:00
|
|
|
|
2008-11-18 07:20:07 +03:00
|
|
|
// file location of start of this node
|
2009-07-27 06:56:18 +04:00
|
|
|
const Mark GetMark() const { return m_mark; }
|
2008-11-18 07:20:07 +03:00
|
|
|
|
2008-09-04 02:20:39 +04:00
|
|
|
// accessors
|
|
|
|
|
Iterator begin() const;
|
|
|
|
|
Iterator end() const;
|
2009-08-20 00:58:07 +04:00
|
|
|
std::size_t size() const;
|
2008-09-04 02:20:39 +04:00
|
|
|
|
2008-09-25 03:29:00 +04:00
|
|
|
// extraction of scalars
|
2009-05-24 03:51:01 +04:00
|
|
|
bool GetScalar(std::string& s) const;
|
|
|
|
|
|
|
|
|
|
// we can specialize this for other values
|
2008-09-04 02:20:39 +04:00
|
|
|
template <typename T>
|
2009-05-24 03:51:01 +04:00
|
|
|
bool Read(T& value) const;
|
2008-09-04 02:20:39 +04:00
|
|
|
|
2009-08-19 07:37:19 +04:00
|
|
|
template <typename T>
|
2011-03-15 08:49:56 +03:00
|
|
|
const T to() const;
|
2009-08-19 07:37:19 +04:00
|
|
|
|
2008-09-25 03:29:00 +04:00
|
|
|
template <typename T>
|
2011-03-16 05:31:30 +03:00
|
|
|
friend YAML_CPP_API void operator >> (const Node& node, T& value);
|
2008-09-04 02:20:39 +04:00
|
|
|
|
2009-08-20 00:58:07 +04:00
|
|
|
// retrieval for maps and sequences
|
2008-09-04 02:20:39 +04:00
|
|
|
template <typename T>
|
2009-07-12 06:59:23 +04:00
|
|
|
const Node *FindValue(const T& key) const;
|
2009-08-20 00:58:07 +04:00
|
|
|
|
2008-09-25 03:29:00 +04:00
|
|
|
template <typename T>
|
|
|
|
|
const Node& operator [] (const T& key) const;
|
2009-08-20 00:58:07 +04:00
|
|
|
|
|
|
|
|
// specific to maps
|
|
|
|
|
const Node *FindValue(const char *key) const;
|
2011-09-06 09:32:53 +04:00
|
|
|
const Node *FindValue(char *key) const;
|
2008-09-25 03:29:00 +04:00
|
|
|
const Node& operator [] (const char *key) const;
|
2011-09-06 09:32:53 +04:00
|
|
|
const Node& operator [] (char *key) const;
|
2008-09-04 02:20:39 +04:00
|
|
|
|
2009-10-29 18:48:06 +03:00
|
|
|
// for tags
|
2011-03-03 03:19:26 +03:00
|
|
|
const std::string& Tag() const { return m_tag; }
|
2009-05-23 01:48:05 +04:00
|
|
|
|
2009-07-11 03:39:14 +04:00
|
|
|
// emitting
|
2011-03-16 05:31:30 +03:00
|
|
|
friend YAML_CPP_API Emitter& operator << (Emitter& out, const Node& node);
|
2008-09-04 02:20:39 +04:00
|
|
|
|
|
|
|
|
// ordering
|
|
|
|
|
int Compare(const Node& rhs) const;
|
|
|
|
|
friend bool operator < (const Node& n1, const Node& n2);
|
|
|
|
|
|
2008-09-19 06:44:49 +04:00
|
|
|
private:
|
2011-03-03 03:19:26 +03:00
|
|
|
explicit Node(NodeOwnership& owner);
|
|
|
|
|
Node& CreateNode();
|
|
|
|
|
|
|
|
|
|
void Init(NodeType::value type, const Mark& mark, const std::string& tag);
|
|
|
|
|
|
|
|
|
|
void MarkAsAliased();
|
|
|
|
|
void SetScalarData(const std::string& data);
|
|
|
|
|
void Append(Node& node);
|
|
|
|
|
void Insert(Node& key, Node& value);
|
|
|
|
|
|
2009-08-20 00:58:07 +04:00
|
|
|
// helper for sequences
|
|
|
|
|
template <typename, bool> friend struct _FindFromNodeAtIndex;
|
|
|
|
|
const Node *FindAtIndex(std::size_t i) const;
|
|
|
|
|
|
2009-07-12 06:59:23 +04:00
|
|
|
// helper for maps
|
|
|
|
|
template <typename T>
|
|
|
|
|
const Node& GetValue(const T& key) const;
|
2009-08-20 00:58:07 +04:00
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
const Node *FindValueForKey(const T& key) const;
|
2008-09-04 02:20:39 +04:00
|
|
|
|
|
|
|
|
private:
|
2011-03-03 03:19:26 +03:00
|
|
|
std::auto_ptr<NodeOwnership> m_pOwnership;
|
|
|
|
|
|
2009-07-27 06:56:18 +04:00
|
|
|
Mark m_mark;
|
2010-10-18 10:45:03 +04:00
|
|
|
std::string m_tag;
|
2011-03-03 03:19:26 +03:00
|
|
|
|
|
|
|
|
typedef std::vector<Node *> node_seq;
|
|
|
|
|
typedef std::map<Node *, Node *, ltnode> node_map;
|
|
|
|
|
|
|
|
|
|
NodeType::value m_type;
|
|
|
|
|
std::string m_scalarData;
|
|
|
|
|
node_seq m_seqData;
|
|
|
|
|
node_map m_mapData;
|
2008-09-04 02:20:39 +04:00
|
|
|
};
|
|
|
|
|
}
|
2009-07-12 06:59:23 +04:00
|
|
|
|
2011-10-19 00:13:10 +04:00
|
|
|
#include "yaml-cpp/old-api/nodeimpl.h"
|
|
|
|
|
#include "yaml-cpp/old-api/nodereadimpl.h"
|
2009-07-30 02:27:20 +04:00
|
|
|
|
|
|
|
|
#endif // NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|