Commit 2601f5fd authored by beder's avatar beder
Browse files

No commit message

No commit message
parent 89ed418b
...@@ -13,6 +13,8 @@ namespace YAML ...@@ -13,6 +13,8 @@ namespace YAML
class Content; class Content;
class Scanner; class Scanner;
enum CONTENT_TYPE { CT_NONE, CT_SCALAR, CT_SEQUENCE, CT_MAP };
class Node class Node
{ {
public: public:
...@@ -23,6 +25,8 @@ namespace YAML ...@@ -23,6 +25,8 @@ namespace YAML
void Parse(Scanner *pScanner, const ParserState& state); void Parse(Scanner *pScanner, const ParserState& state);
void Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine) const; void Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine) const;
CONTENT_TYPE GetType() const;
// accessors // accessors
Iterator begin() const; Iterator begin() const;
Iterator end() const; Iterator end() const;
......
...@@ -16,6 +16,8 @@ namespace YAML ...@@ -16,6 +16,8 @@ namespace YAML
class Sequence; class Sequence;
class Map; class Map;
enum CONTENT_TYPE;
class Content class Content
{ {
public: public:
...@@ -31,6 +33,7 @@ namespace YAML ...@@ -31,6 +33,7 @@ namespace YAML
virtual bool GetEnd(std::map <Node *, Node *, ltnode>::const_iterator& it) const { return false; } virtual bool GetEnd(std::map <Node *, Node *, ltnode>::const_iterator& it) const { return false; }
virtual Node *GetNode(unsigned i) const { return 0; } virtual Node *GetNode(unsigned i) const { return 0; }
virtual unsigned GetSize() const { return 0; } virtual unsigned GetSize() const { return 0; }
virtual CONTENT_TYPE GetType() const = 0;
// extraction // extraction
virtual void Read(std::string& s) { throw InvalidScalar(); } virtual void Read(std::string& s) { throw InvalidScalar(); }
......
...@@ -163,6 +163,11 @@ namespace YAML ...@@ -163,6 +163,11 @@ namespace YAML
out << std::endl; out << std::endl;
} }
CONTENT_TYPE Map::GetType() const
{
return CT_MAP;
}
int Map::Compare(Content *pContent) int Map::Compare(Content *pContent)
{ {
return -pContent->Compare(this); return -pContent->Compare(this);
......
...@@ -19,6 +19,8 @@ namespace YAML ...@@ -19,6 +19,8 @@ namespace YAML
virtual void Parse(Scanner *pScanner, const ParserState& state); virtual void Parse(Scanner *pScanner, const ParserState& state);
virtual void Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine); virtual void Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine);
virtual CONTENT_TYPE GetType() const;
// ordering // ordering
virtual int Compare(Content *pContent); virtual int Compare(Content *pContent);
virtual int Compare(Scalar *pScalar) { return 1; } virtual int Compare(Scalar *pScalar) { return 1; }
......
...@@ -144,6 +144,14 @@ namespace YAML ...@@ -144,6 +144,14 @@ namespace YAML
} }
} }
CONTENT_TYPE Node::GetType() const
{
if(!m_pContent)
return CT_NONE;
return m_pContent->GetType();
}
// begin // begin
// Returns an iterator to the beginning of this (sequence or map). // Returns an iterator to the beginning of this (sequence or map).
Iterator Node::begin() const Iterator Node::begin() const
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "scanner.h" #include "scanner.h"
#include "token.h" #include "token.h"
#include "exceptions.h" #include "exceptions.h"
#include "node.h"
#include <sstream> #include <sstream>
namespace YAML namespace YAML
...@@ -37,6 +38,11 @@ namespace YAML ...@@ -37,6 +38,11 @@ namespace YAML
out << "\"\n"; out << "\"\n";
} }
CONTENT_TYPE Scalar::GetType() const
{
return CT_SCALAR;
}
void Scalar::Read(std::string& s) void Scalar::Read(std::string& s)
{ {
s = m_data; s = m_data;
......
...@@ -14,6 +14,8 @@ namespace YAML ...@@ -14,6 +14,8 @@ namespace YAML
virtual void Parse(Scanner *pScanner, const ParserState& state); virtual void Parse(Scanner *pScanner, const ParserState& state);
virtual void Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine); virtual void Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine);
virtual CONTENT_TYPE GetType() const;
// extraction // extraction
virtual void Read(std::string& s); virtual void Read(std::string& s);
virtual void Read(int& i); virtual void Read(int& i);
......
...@@ -150,6 +150,11 @@ namespace YAML ...@@ -150,6 +150,11 @@ namespace YAML
out << std::endl; out << std::endl;
} }
CONTENT_TYPE Sequence::GetType() const
{
return CT_SEQUENCE;
}
int Sequence::Compare(Content *pContent) int Sequence::Compare(Content *pContent)
{ {
return -pContent->Compare(this); return -pContent->Compare(this);
......
...@@ -22,6 +22,8 @@ namespace YAML ...@@ -22,6 +22,8 @@ namespace YAML
virtual void Parse(Scanner *pScanner, const ParserState& state); virtual void Parse(Scanner *pScanner, const ParserState& state);
virtual void Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine); virtual void Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine);
virtual CONTENT_TYPE GetType() const;
// ordering // ordering
virtual int Compare(Content *pContent); virtual int Compare(Content *pContent);
virtual int Compare(Scalar *pScalar) { return 1; } virtual int Compare(Scalar *pScalar) { return 1; }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment