Files
yaml-cpp/include/node.h
T

98 lines
2.2 KiB
C++
Raw Normal View History

2008-09-03 22:20:39 +00:00
#pragma once
#include <string>
#include <vector>
#include <map>
#include "parserstate.h"
#include "exceptions.h"
#include "iterator.h"
#include "conversion.h"
#include "noncopyable.h"
#include <iostream>
2008-09-03 22:20:39 +00:00
namespace YAML
{
class Content;
class Scanner;
class Emitter;
2008-09-03 22:20:39 +00:00
enum CONTENT_TYPE { CT_NONE, CT_SCALAR, CT_SEQUENCE, CT_MAP };
class Node: private noncopyable
2008-09-03 22:20:39 +00:00
{
public:
Node();
~Node();
void Clear();
void Parse(Scanner *pScanner, const ParserState& state);
CONTENT_TYPE GetType() const;
// file location of start of this node
int GetLine() const { return m_line; }
int GetColumn() const { return m_column; }
2008-09-03 22:20:39 +00:00
// 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
2008-09-03 22:20:39 +00:00
template <typename T>
bool Read(T& value) const;
2008-09-03 22:20:39 +00:00
template <typename T>
friend void operator >> (const Node& node, T& value);
2008-09-03 22:20:39 +00:00
// 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
2008-09-03 22:20:39 +00:00
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);
2008-09-03 22:20:39 +00:00
// ordering
int Compare(const Node& rhs) const;
friend bool operator < (const Node& n1, const Node& n2);
2008-09-19 02:44:49 +00:00
private:
// helper for maps
template <typename T>
const Node& GetValue(const T& key) const;
// helpers for parsing
2008-09-03 22:20:39 +00:00
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:
int m_line, m_column;
2008-09-03 22:20:39 +00:00
std::string m_anchor, m_tag;
Content *m_pContent;
bool m_alias;
const Node *m_pIdentity;
mutable bool m_referenced;
2008-09-03 22:20:39 +00:00
};
}
#include "nodeimpl.h"