yaml-cpp/include/node.h

104 lines
2.4 KiB
C
Raw Normal View History

#pragma once
2009-07-30 02:27:20 +04:00
#ifndef NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#include "conversion.h"
#include "exceptions.h"
#include "iterator.h"
#include "mark.h"
#include "noncopyable.h"
#include "parserstate.h"
#include <iostream>
#include <string>
#include <vector>
#include <map>
namespace YAML
{
class Content;
class Scanner;
class Emitter;
enum CONTENT_TYPE { CT_NONE, CT_SCALAR, CT_SEQUENCE, CT_MAP };
class Node: private noncopyable
{
public:
Node();
~Node();
void Clear();
void Parse(Scanner *pScanner, const ParserState& state);
CONTENT_TYPE GetType() const;
// file location of start of this node
const Mark GetMark() const { return m_mark; }
// accessors
Iterator begin() const;
Iterator end() const;
unsigned size() const;
// extraction of scalars
bool GetScalar(std::string& s) const;
// we can specialize this for other values
template <typename T>
bool Read(T& value) const;
template <typename T>
friend void operator >> (const Node& node, T& value);
// just for maps
template <typename T>
const Node *FindValue(const T& key) const;
const Node *FindValue(const char *key) const;
template <typename T>
const Node& operator [] (const T& key) const;
const Node& operator [] (const char *key) const;
// just for sequences
const Node& operator [] (unsigned u) const;
const Node& operator [] (int i) const;
// for anchors/aliases
const Node *Identity() const { return m_pIdentity; }
bool IsAlias() const { return m_alias; }
bool IsReferenced() const { return m_referenced; }
// emitting
friend Emitter& operator << (Emitter& out, const Node& node);
// 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:
// helper for maps
template <typename T>
const Node& GetValue(const T& key) const;
// helpers for parsing
void ParseHeader(Scanner *pScanner, const ParserState& state);
void ParseTag(Scanner *pScanner, const ParserState& state);
void ParseAnchor(Scanner *pScanner, const ParserState& state);
void ParseAlias(Scanner *pScanner, const ParserState& state);
private:
Mark m_mark;
std::string m_anchor, m_tag;
Content *m_pContent;
bool m_alias;
const Node *m_pIdentity;
mutable bool m_referenced;
};
}
#include "nodeimpl.h"
2009-07-30 02:27:20 +04:00
#endif // NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66