mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 12:41:17 +00:00
Set the eol style to native for all files.
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
// for detecting memory leaks
|
||||
#ifdef _DEBUG
|
||||
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
|
||||
#endif // _DEBUG
|
||||
|
||||
#pragma once
|
||||
|
||||
// for detecting memory leaks
|
||||
#ifdef _DEBUG
|
||||
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
|
||||
#endif // _DEBUG
|
||||
|
||||
|
@@ -1,59 +1,59 @@
|
||||
#pragma once
|
||||
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
class Exception: public std::exception {};
|
||||
class ParserException: public Exception {
|
||||
public:
|
||||
ParserException(int line_, int column_, const std::string& msg_)
|
||||
: line(line_), column(column_), msg(msg_) {}
|
||||
virtual ~ParserException() throw () {}
|
||||
|
||||
int line, column;
|
||||
std::string msg;
|
||||
};
|
||||
|
||||
class RepresentationException: public Exception {};
|
||||
|
||||
// representation exceptions
|
||||
class InvalidScalar: public RepresentationException {};
|
||||
class BadDereference: public RepresentationException {};
|
||||
|
||||
// error messages
|
||||
namespace ErrorMsg
|
||||
{
|
||||
const std::string YAML_DIRECTIVE_ARGS = "YAML directives must have exactly one argument";
|
||||
const std::string YAML_VERSION = "bad YAML version: ";
|
||||
const std::string YAML_MAJOR_VERSION = "YAML major version too large";
|
||||
const std::string TAG_DIRECTIVE_ARGS = "TAG directives must have exactly two arguments";
|
||||
const std::string END_OF_MAP = "end of map not found";
|
||||
const std::string END_OF_MAP_FLOW = "end of map flow not found";
|
||||
const std::string END_OF_SEQ = "end of sequence not found";
|
||||
const std::string END_OF_SEQ_FLOW = "end of sequence flow not found";
|
||||
const std::string MULTIPLE_TAGS = "cannot assign multiple tags to the same node";
|
||||
const std::string MULTIPLE_ANCHORS = "cannot assign multiple anchors to the same node";
|
||||
const std::string MULTIPLE_ALIASES = "cannot assign multiple aliases to the same node";
|
||||
const std::string ALIAS_CONTENT = "aliases can't have any content, *including* tags";
|
||||
const std::string INVALID_HEX = "bad character found while scanning hex number";
|
||||
const std::string INVALID_UNICODE = "invalid unicode: ";
|
||||
const std::string INVALID_ESCAPE = "unknown escape character: ";
|
||||
const std::string UNKNOWN_TOKEN = "unknown token";
|
||||
const std::string DOC_IN_SCALAR = "illegal document indicator in scalar";
|
||||
const std::string EOF_IN_SCALAR = "illegal EOF in scalar";
|
||||
const std::string CHAR_IN_SCALAR = "illegal character in scalar";
|
||||
const std::string TAB_IN_INDENTATION = "illegal tab when looking for indentation";
|
||||
const std::string FLOW_END = "illegal flow end";
|
||||
const std::string BLOCK_ENTRY = "illegal block entry";
|
||||
const std::string MAP_KEY = "illegal map key";
|
||||
const std::string MAP_VALUE = "illegal map value";
|
||||
const std::string ALIAS_NOT_FOUND = "alias not found after *";
|
||||
const std::string ANCHOR_NOT_FOUND = "anchor not found after &";
|
||||
const std::string CHAR_IN_ALIAS = "illegal character found while scanning alias";
|
||||
const std::string CHAR_IN_ANCHOR = "illegal character found while scanning anchor";
|
||||
const std::string ZERO_INDENT_IN_BLOCK = "cannot set zero indentation for a block scalar";
|
||||
const std::string CHAR_IN_BLOCK = "unexpected character in block scalar";
|
||||
}
|
||||
}
|
||||
#pragma once
|
||||
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
class Exception: public std::exception {};
|
||||
class ParserException: public Exception {
|
||||
public:
|
||||
ParserException(int line_, int column_, const std::string& msg_)
|
||||
: line(line_), column(column_), msg(msg_) {}
|
||||
virtual ~ParserException() throw () {}
|
||||
|
||||
int line, column;
|
||||
std::string msg;
|
||||
};
|
||||
|
||||
class RepresentationException: public Exception {};
|
||||
|
||||
// representation exceptions
|
||||
class InvalidScalar: public RepresentationException {};
|
||||
class BadDereference: public RepresentationException {};
|
||||
|
||||
// error messages
|
||||
namespace ErrorMsg
|
||||
{
|
||||
const std::string YAML_DIRECTIVE_ARGS = "YAML directives must have exactly one argument";
|
||||
const std::string YAML_VERSION = "bad YAML version: ";
|
||||
const std::string YAML_MAJOR_VERSION = "YAML major version too large";
|
||||
const std::string TAG_DIRECTIVE_ARGS = "TAG directives must have exactly two arguments";
|
||||
const std::string END_OF_MAP = "end of map not found";
|
||||
const std::string END_OF_MAP_FLOW = "end of map flow not found";
|
||||
const std::string END_OF_SEQ = "end of sequence not found";
|
||||
const std::string END_OF_SEQ_FLOW = "end of sequence flow not found";
|
||||
const std::string MULTIPLE_TAGS = "cannot assign multiple tags to the same node";
|
||||
const std::string MULTIPLE_ANCHORS = "cannot assign multiple anchors to the same node";
|
||||
const std::string MULTIPLE_ALIASES = "cannot assign multiple aliases to the same node";
|
||||
const std::string ALIAS_CONTENT = "aliases can't have any content, *including* tags";
|
||||
const std::string INVALID_HEX = "bad character found while scanning hex number";
|
||||
const std::string INVALID_UNICODE = "invalid unicode: ";
|
||||
const std::string INVALID_ESCAPE = "unknown escape character: ";
|
||||
const std::string UNKNOWN_TOKEN = "unknown token";
|
||||
const std::string DOC_IN_SCALAR = "illegal document indicator in scalar";
|
||||
const std::string EOF_IN_SCALAR = "illegal EOF in scalar";
|
||||
const std::string CHAR_IN_SCALAR = "illegal character in scalar";
|
||||
const std::string TAB_IN_INDENTATION = "illegal tab when looking for indentation";
|
||||
const std::string FLOW_END = "illegal flow end";
|
||||
const std::string BLOCK_ENTRY = "illegal block entry";
|
||||
const std::string MAP_KEY = "illegal map key";
|
||||
const std::string MAP_VALUE = "illegal map value";
|
||||
const std::string ALIAS_NOT_FOUND = "alias not found after *";
|
||||
const std::string ANCHOR_NOT_FOUND = "anchor not found after &";
|
||||
const std::string CHAR_IN_ALIAS = "illegal character found while scanning alias";
|
||||
const std::string CHAR_IN_ANCHOR = "illegal character found while scanning anchor";
|
||||
const std::string ZERO_INDENT_IN_BLOCK = "cannot set zero indentation for a block scalar";
|
||||
const std::string CHAR_IN_BLOCK = "unexpected character in block scalar";
|
||||
}
|
||||
}
|
||||
|
@@ -1,30 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
class Node;
|
||||
struct IterPriv;
|
||||
|
||||
class Iterator
|
||||
{
|
||||
public:
|
||||
Iterator();
|
||||
Iterator(IterPriv *pData);
|
||||
Iterator(const Iterator& rhs);
|
||||
~Iterator();
|
||||
|
||||
Iterator& operator = (const Iterator& rhs);
|
||||
Iterator& operator ++ ();
|
||||
Iterator operator ++ (int);
|
||||
const Node& operator * () const;
|
||||
const Node *operator -> () const;
|
||||
const Node& first() const;
|
||||
const Node& second() const;
|
||||
|
||||
friend bool operator == (const Iterator& it, const Iterator& jt);
|
||||
friend bool operator != (const Iterator& it, const Iterator& jt);
|
||||
|
||||
private:
|
||||
IterPriv *m_pData;
|
||||
};
|
||||
}
|
||||
#pragma once
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
class Node;
|
||||
struct IterPriv;
|
||||
|
||||
class Iterator
|
||||
{
|
||||
public:
|
||||
Iterator();
|
||||
Iterator(IterPriv *pData);
|
||||
Iterator(const Iterator& rhs);
|
||||
~Iterator();
|
||||
|
||||
Iterator& operator = (const Iterator& rhs);
|
||||
Iterator& operator ++ ();
|
||||
Iterator operator ++ (int);
|
||||
const Node& operator * () const;
|
||||
const Node *operator -> () const;
|
||||
const Node& first() const;
|
||||
const Node& second() const;
|
||||
|
||||
friend bool operator == (const Iterator& it, const Iterator& jt);
|
||||
friend bool operator != (const Iterator& it, const Iterator& jt);
|
||||
|
||||
private:
|
||||
IterPriv *m_pData;
|
||||
};
|
||||
}
|
||||
|
184
include/node.h
184
include/node.h
@@ -1,92 +1,92 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <ios>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include "parserstate.h"
|
||||
#include "exceptions.h"
|
||||
#include "iterator.h"
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
class Content;
|
||||
class Scanner;
|
||||
|
||||
enum CONTENT_TYPE { CT_NONE, CT_SCALAR, CT_SEQUENCE, CT_MAP };
|
||||
|
||||
class Node
|
||||
{
|
||||
public:
|
||||
Node();
|
||||
~Node();
|
||||
|
||||
void Clear();
|
||||
void Parse(Scanner *pScanner, const ParserState& state);
|
||||
void Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine) const;
|
||||
|
||||
CONTENT_TYPE GetType() const;
|
||||
|
||||
// accessors
|
||||
Iterator begin() const;
|
||||
Iterator end() const;
|
||||
unsigned size() const;
|
||||
|
||||
template <typename T>
|
||||
const Node& GetValue(const T& key) const {
|
||||
if(!m_pContent)
|
||||
throw BadDereference();
|
||||
|
||||
for(Iterator it=begin();it!=end();++it) {
|
||||
T t;
|
||||
try {
|
||||
it.first() >> t;
|
||||
if(key == t)
|
||||
return it.second();
|
||||
} catch(RepresentationException&) {
|
||||
}
|
||||
}
|
||||
|
||||
throw BadDereference();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const Node& operator [] (const T& key) const {
|
||||
return GetValue(key);
|
||||
}
|
||||
|
||||
const Node& operator [] (const char *key) const {
|
||||
return GetValue(std::string(key));
|
||||
}
|
||||
|
||||
const Node& operator [] (unsigned u) const;
|
||||
const Node& operator [] (int i) const;
|
||||
|
||||
// extraction
|
||||
friend void operator >> (const Node& node, std::string& s);
|
||||
friend void operator >> (const Node& node, int& i);
|
||||
friend void operator >> (const Node& node, unsigned& u);
|
||||
friend void operator >> (const Node& node, long& l);
|
||||
friend void operator >> (const Node& node, float& f);
|
||||
friend void operator >> (const Node& node, double& d);
|
||||
friend void operator >> (const Node& node, char& c);
|
||||
|
||||
// insertion
|
||||
friend std::ostream& operator << (std::ostream& out, const Node& node);
|
||||
|
||||
// ordering
|
||||
int Compare(const Node& rhs) const;
|
||||
friend bool operator < (const Node& n1, const Node& n2);
|
||||
|
||||
private:
|
||||
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:
|
||||
std::string m_anchor, m_tag;
|
||||
Content *m_pContent;
|
||||
bool m_alias;
|
||||
};
|
||||
}
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <ios>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include "parserstate.h"
|
||||
#include "exceptions.h"
|
||||
#include "iterator.h"
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
class Content;
|
||||
class Scanner;
|
||||
|
||||
enum CONTENT_TYPE { CT_NONE, CT_SCALAR, CT_SEQUENCE, CT_MAP };
|
||||
|
||||
class Node
|
||||
{
|
||||
public:
|
||||
Node();
|
||||
~Node();
|
||||
|
||||
void Clear();
|
||||
void Parse(Scanner *pScanner, const ParserState& state);
|
||||
void Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine) const;
|
||||
|
||||
CONTENT_TYPE GetType() const;
|
||||
|
||||
// accessors
|
||||
Iterator begin() const;
|
||||
Iterator end() const;
|
||||
unsigned size() const;
|
||||
|
||||
template <typename T>
|
||||
const Node& GetValue(const T& key) const {
|
||||
if(!m_pContent)
|
||||
throw BadDereference();
|
||||
|
||||
for(Iterator it=begin();it!=end();++it) {
|
||||
T t;
|
||||
try {
|
||||
it.first() >> t;
|
||||
if(key == t)
|
||||
return it.second();
|
||||
} catch(RepresentationException&) {
|
||||
}
|
||||
}
|
||||
|
||||
throw BadDereference();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const Node& operator [] (const T& key) const {
|
||||
return GetValue(key);
|
||||
}
|
||||
|
||||
const Node& operator [] (const char *key) const {
|
||||
return GetValue(std::string(key));
|
||||
}
|
||||
|
||||
const Node& operator [] (unsigned u) const;
|
||||
const Node& operator [] (int i) const;
|
||||
|
||||
// extraction
|
||||
friend void operator >> (const Node& node, std::string& s);
|
||||
friend void operator >> (const Node& node, int& i);
|
||||
friend void operator >> (const Node& node, unsigned& u);
|
||||
friend void operator >> (const Node& node, long& l);
|
||||
friend void operator >> (const Node& node, float& f);
|
||||
friend void operator >> (const Node& node, double& d);
|
||||
friend void operator >> (const Node& node, char& c);
|
||||
|
||||
// insertion
|
||||
friend std::ostream& operator << (std::ostream& out, const Node& node);
|
||||
|
||||
// ordering
|
||||
int Compare(const Node& rhs) const;
|
||||
friend bool operator < (const Node& n1, const Node& n2);
|
||||
|
||||
private:
|
||||
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:
|
||||
std::string m_anchor, m_tag;
|
||||
Content *m_pContent;
|
||||
bool m_alias;
|
||||
};
|
||||
}
|
||||
|
@@ -1,42 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include <ios>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include "node.h"
|
||||
#include "parserstate.h"
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
class Scanner;
|
||||
struct Token;
|
||||
|
||||
class Parser
|
||||
{
|
||||
public:
|
||||
Parser(std::istream& in);
|
||||
~Parser();
|
||||
|
||||
operator bool() const;
|
||||
|
||||
void Load(std::istream& in);
|
||||
void GetNextDocument(Node& document);
|
||||
void PrintTokens(std::ostream& out);
|
||||
|
||||
private:
|
||||
void ParseDirectives();
|
||||
void HandleDirective(Token *pToken);
|
||||
void HandleYamlDirective(Token *pToken);
|
||||
void HandleTagDirective(Token *pToken);
|
||||
|
||||
private:
|
||||
// can't copy this
|
||||
Parser(const Parser& rhs) {}
|
||||
Parser& operator = (const Parser& rhs) { return *this; }
|
||||
|
||||
private:
|
||||
Scanner *m_pScanner;
|
||||
ParserState m_state;
|
||||
};
|
||||
}
|
||||
#pragma once
|
||||
|
||||
#include <ios>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include "node.h"
|
||||
#include "parserstate.h"
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
class Scanner;
|
||||
struct Token;
|
||||
|
||||
class Parser
|
||||
{
|
||||
public:
|
||||
Parser(std::istream& in);
|
||||
~Parser();
|
||||
|
||||
operator bool() const;
|
||||
|
||||
void Load(std::istream& in);
|
||||
void GetNextDocument(Node& document);
|
||||
void PrintTokens(std::ostream& out);
|
||||
|
||||
private:
|
||||
void ParseDirectives();
|
||||
void HandleDirective(Token *pToken);
|
||||
void HandleYamlDirective(Token *pToken);
|
||||
void HandleTagDirective(Token *pToken);
|
||||
|
||||
private:
|
||||
// can't copy this
|
||||
Parser(const Parser& rhs) {}
|
||||
Parser& operator = (const Parser& rhs) { return *this; }
|
||||
|
||||
private:
|
||||
Scanner *m_pScanner;
|
||||
ParserState m_state;
|
||||
};
|
||||
}
|
||||
|
@@ -1,20 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
struct Version {
|
||||
int major, minor;
|
||||
};
|
||||
|
||||
struct ParserState
|
||||
{
|
||||
Version version;
|
||||
std::map <std::string, std::string> tags;
|
||||
|
||||
void Reset();
|
||||
std::string TranslateTag(const std::string& handle) const;
|
||||
};
|
||||
}
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
struct Version {
|
||||
int major, minor;
|
||||
};
|
||||
|
||||
struct ParserState
|
||||
{
|
||||
Version version;
|
||||
std::map <std::string, std::string> tags;
|
||||
|
||||
void Reset();
|
||||
std::string TranslateTag(const std::string& handle) const;
|
||||
};
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "crt.h"
|
||||
#include "parser.h"
|
||||
#include "node.h"
|
||||
#include "iterator.h"
|
||||
#include "exceptions.h"
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "crt.h"
|
||||
#include "parser.h"
|
||||
#include "node.h"
|
||||
#include "iterator.h"
|
||||
#include "exceptions.h"
|
||||
|
||||
|
Reference in New Issue
Block a user