Commit 9b4db068 by Jesse Beder

Run clang-format

parent e40ed4f9
#ifndef ANCHOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef ANCHOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define ANCHOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define ANCHOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
#include <cstddef> #include <cstddef>
namespace YAML namespace YAML {
{ typedef std::size_t anchor_t;
typedef std::size_t anchor_t; const anchor_t NullAnchor = 0;
const anchor_t NullAnchor = 0;
} }
#endif // ANCHOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // ANCHOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#ifndef BASE64_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef BASE64_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define BASE64_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define BASE64_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
#include <string> #include <string>
#include <vector> #include <vector>
namespace YAML namespace YAML {
{ std::string EncodeBase64(const unsigned char *data, std::size_t size);
std::string EncodeBase64(const unsigned char *data, std::size_t size); std::vector<unsigned char> DecodeBase64(const std::string &input);
std::vector<unsigned char> DecodeBase64(const std::string& input);
class Binary {
class Binary { public:
public: Binary() : m_unownedData(0), m_unownedSize(0) {}
Binary(): m_unownedData(0), m_unownedSize(0) {} Binary(const unsigned char *data_, std::size_t size_)
Binary(const unsigned char *data_, std::size_t size_): m_unownedData(data_), m_unownedSize(size_) {} : m_unownedData(data_), m_unownedSize(size_) {}
bool owned() const { return !m_unownedData; } bool owned() const { return !m_unownedData; }
std::size_t size() const { return owned() ? m_data.size() : m_unownedSize; } std::size_t size() const { return owned() ? m_data.size() : m_unownedSize; }
const unsigned char *data() const { return owned() ? &m_data[0] : m_unownedData; } const unsigned char *data() const {
return owned() ? &m_data[0] : m_unownedData;
void swap(std::vector<unsigned char>& rhs) { }
if(m_unownedData) {
m_data.swap(rhs); void swap(std::vector<unsigned char> &rhs) {
rhs.clear(); if (m_unownedData) {
rhs.resize(m_unownedSize); m_data.swap(rhs);
std::copy(m_unownedData, m_unownedData + m_unownedSize, &rhs[0]); rhs.clear();
m_unownedData = 0; rhs.resize(m_unownedSize);
m_unownedSize = 0; std::copy(m_unownedData, m_unownedData + m_unownedSize, &rhs[0]);
} else { m_unownedData = 0;
m_data.swap(rhs); m_unownedSize = 0;
} } else {
} m_data.swap(rhs);
}
bool operator == (const Binary& rhs) const { }
const std::size_t s = size();
if(s != rhs.size()) bool operator==(const Binary &rhs) const {
return false; const std::size_t s = size();
const unsigned char *d1 = data(); if (s != rhs.size())
const unsigned char *d2 = rhs.data(); return false;
for(std::size_t i=0;i<s;i++) { const unsigned char *d1 = data();
if(*d1++ != *d2++) const unsigned char *d2 = rhs.data();
return false; for (std::size_t i = 0; i < s; i++) {
} if (*d1++ != *d2++)
return true; return false;
} }
return true;
bool operator != (const Binary& rhs) const { }
return !(*this == rhs);
} bool operator!=(const Binary &rhs) const { return !(*this == rhs); }
private: private:
std::vector<unsigned char> m_data; std::vector<unsigned char> m_data;
const unsigned char *m_unownedData; const unsigned char *m_unownedData;
std::size_t m_unownedSize; std::size_t m_unownedSize;
}; };
} }
#endif // BASE64_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // BASE64_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#ifndef ANCHORDICT_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef ANCHORDICT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define ANCHORDICT_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define ANCHORDICT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
...@@ -9,34 +11,27 @@ ...@@ -9,34 +11,27 @@
#include "../anchor.h" #include "../anchor.h"
namespace YAML namespace YAML {
{ /// AnchorDict
/// AnchorDict /// . An object that stores and retrieves values correlating to anchor_t
/// . An object that stores and retrieves values correlating to anchor_t /// values.
/// values. /// . Efficient implementation that can make assumptions about how anchor_t
/// . Efficient implementation that can make assumptions about how anchor_t /// values are assigned by the Parser class.
/// values are assigned by the Parser class. template <class T>
template <class T> class AnchorDict {
class AnchorDict public:
{ void Register(anchor_t anchor, T value) {
public: if (anchor > m_data.size()) {
void Register(anchor_t anchor, T value) m_data.resize(anchor);
{
if (anchor > m_data.size())
{
m_data.resize(anchor);
}
m_data[anchor - 1] = value;
} }
m_data[anchor - 1] = value;
T Get(anchor_t anchor) const }
{
return m_data[anchor - 1]; T Get(anchor_t anchor) const { return m_data[anchor - 1]; }
}
private:
private: std::vector<T> m_data;
std::vector<T> m_data; };
};
} }
#endif // ANCHORDICT_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // ANCHORDICT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#ifndef DLL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef DLL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define DLL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define DLL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
// The following ifdef block is the standard way of creating macros which make exporting // The following ifdef block is the standard way of creating macros which make
// from a DLL simpler. All files within this DLL are compiled with the yaml_cpp_EXPORTS // exporting
// symbol defined on the command line. this symbol should not be defined on any project // from a DLL simpler. All files within this DLL are compiled with the
// that uses this DLL. This way any other project whose source files include this file see // yaml_cpp_EXPORTS
// YAML_CPP_API functions as being imported from a DLL, whereas this DLL sees symbols // symbol defined on the command line. this symbol should not be defined on any
// project
// that uses this DLL. This way any other project whose source files include
// this file see
// YAML_CPP_API functions as being imported from a DLL, whereas this DLL sees
// symbols
// defined with this macro as being exported. // defined with this macro as being exported.
#undef YAML_CPP_API #undef YAML_CPP_API
#ifdef YAML_CPP_DLL // Using or Building YAML-CPP DLL (definition defined manually) #ifdef YAML_CPP_DLL // Using or Building YAML-CPP DLL (definition defined
#ifdef yaml_cpp_EXPORTS // Building YAML-CPP DLL (definition created by CMake or defined manually) // manually)
// #pragma message( "Defining YAML_CPP_API for DLL export" ) #ifdef yaml_cpp_EXPORTS // Building YAML-CPP DLL (definition created by CMake
#define YAML_CPP_API __declspec(dllexport) // or defined manually)
#else // yaml_cpp_EXPORTS // #pragma message( "Defining YAML_CPP_API for DLL export" )
// #pragma message( "Defining YAML_CPP_API for DLL import" ) #define YAML_CPP_API __declspec(dllexport)
#define YAML_CPP_API __declspec(dllimport) #else // yaml_cpp_EXPORTS
#endif // yaml_cpp_EXPORTS // #pragma message( "Defining YAML_CPP_API for DLL import" )
#else //YAML_CPP_DLL #define YAML_CPP_API __declspec(dllimport)
#endif // yaml_cpp_EXPORTS
#else // YAML_CPP_DLL
#define YAML_CPP_API #define YAML_CPP_API
#endif // YAML_CPP_DLL #endif // YAML_CPP_DLL
#endif // DLL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // DLL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#ifndef EMITFROMEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef EMITFROMEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define EMITFROMEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define EMITFROMEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
#include "yaml-cpp/eventhandler.h" #include "yaml-cpp/eventhandler.h"
#include <stack> #include <stack>
namespace YAML namespace YAML {
{ class Emitter;
class Emitter;
class EmitFromEvents : public EventHandler {
class EmitFromEvents: public EventHandler public:
{ EmitFromEvents(Emitter& emitter);
public:
EmitFromEvents(Emitter& emitter); virtual void OnDocumentStart(const Mark& mark);
virtual void OnDocumentEnd();
virtual void OnDocumentStart(const Mark& mark);
virtual void OnDocumentEnd(); virtual void OnNull(const Mark& mark, anchor_t anchor);
virtual void OnAlias(const Mark& mark, anchor_t anchor);
virtual void OnNull(const Mark& mark, anchor_t anchor); virtual void OnScalar(const Mark& mark, const std::string& tag,
virtual void OnAlias(const Mark& mark, anchor_t anchor); anchor_t anchor, const std::string& value);
virtual void OnScalar(const Mark& mark, const std::string& tag, anchor_t anchor, const std::string& value);
virtual void OnSequenceStart(const Mark& mark, const std::string& tag,
virtual void OnSequenceStart(const Mark& mark, const std::string& tag, anchor_t anchor); anchor_t anchor);
virtual void OnSequenceEnd(); virtual void OnSequenceEnd();
virtual void OnMapStart(const Mark& mark, const std::string& tag, anchor_t anchor); virtual void OnMapStart(const Mark& mark, const std::string& tag,
virtual void OnMapEnd(); anchor_t anchor);
virtual void OnMapEnd();
private:
void BeginNode(); private:
void EmitProps(const std::string& tag, anchor_t anchor); void BeginNode();
void EmitProps(const std::string& tag, anchor_t anchor);
private:
Emitter& m_emitter; private:
Emitter& m_emitter;
struct State { enum value { WaitingForSequenceEntry, WaitingForKey, WaitingForValue }; };
std::stack<State::value> m_stateStack; struct State {
}; enum value {
WaitingForSequenceEntry,
WaitingForKey,
WaitingForValue
};
};
std::stack<State::value> m_stateStack;
};
} }
#endif // EMITFROMEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // EMITFROMEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#ifndef EMITTERDEF_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef EMITTERDEF_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define EMITTERDEF_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define EMITTERDEF_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
namespace YAML namespace YAML {
{ struct EmitterNodeType {
struct EmitterNodeType { enum value { None, Property, Scalar, FlowSeq, BlockSeq, FlowMap, BlockMap }; }; enum value {
None,
Property,
Scalar,
FlowSeq,
BlockSeq,
FlowMap,
BlockMap
};
};
} }
#endif // EMITTERDEF_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // EMITTERDEF_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#ifndef EMITTERMANIP_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef EMITTERMANIP_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define EMITTERMANIP_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define EMITTERMANIP_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
#include <string> #include <string>
namespace YAML namespace YAML {
{ enum EMITTER_MANIP {
enum EMITTER_MANIP { // general manipulators
// general manipulators Auto,
Auto, TagByKind,
TagByKind, Newline,
Newline,
// output character set
// output character set EmitNonAscii,
EmitNonAscii, EscapeNonAscii,
EscapeNonAscii,
// string manipulators
// string manipulators // Auto, // duplicate
// Auto, // duplicate SingleQuoted,
SingleQuoted, DoubleQuoted,
DoubleQuoted, Literal,
Literal,
// bool manipulators
// bool manipulators YesNoBool, // yes, no
YesNoBool, // yes, no TrueFalseBool, // true, false
TrueFalseBool, // true, false OnOffBool, // on, off
OnOffBool, // on, off UpperCase, // TRUE, N
UpperCase, // TRUE, N LowerCase, // f, yes
LowerCase, // f, yes CamelCase, // No, Off
CamelCase, // No, Off LongBool, // yes, On
LongBool, // yes, On ShortBool, // y, t
ShortBool, // y, t
// int manipulators
// int manipulators Dec,
Dec, Hex,
Hex, Oct,
Oct,
// document manipulators
// document manipulators BeginDoc,
BeginDoc, EndDoc,
EndDoc,
// sequence manipulators
// sequence manipulators BeginSeq,
BeginSeq, EndSeq,
EndSeq, Flow,
Flow, Block,
Block,
// map manipulators
// map manipulators BeginMap,
BeginMap, EndMap,
EndMap, Key,
Key, Value,
Value, // Flow, // duplicate
// Flow, // duplicate // Block, // duplicate
// Block, // duplicate // Auto, // duplicate
// Auto, // duplicate LongKey
LongKey };
};
struct _Indent {
struct _Indent { _Indent(int value_) : value(value_) {}
_Indent(int value_): value(value_) {} int value;
int value; };
};
inline _Indent Indent(int value) { return _Indent(value); }
inline _Indent Indent(int value) {
return _Indent(value); struct _Alias {
} _Alias(const std::string& content_) : content(content_) {}
std::string content;
struct _Alias { };
_Alias(const std::string& content_): content(content_) {}
std::string content; inline _Alias Alias(const std::string content) { return _Alias(content); }
};
struct _Anchor {
inline _Alias Alias(const std::string content) { _Anchor(const std::string& content_) : content(content_) {}
return _Alias(content); std::string content;
} };
struct _Anchor { inline _Anchor Anchor(const std::string content) { return _Anchor(content); }
_Anchor(const std::string& content_): content(content_) {}
std::string content; struct _Tag {
}; struct Type {
enum value {
inline _Anchor Anchor(const std::string content) { Verbatim,
return _Anchor(content); PrimaryHandle,
} NamedHandle
struct _Tag {
struct Type { enum value { Verbatim, PrimaryHandle, NamedHandle }; };
explicit _Tag(const std::string& prefix_, const std::string& content_, Type::value type_)
: prefix(prefix_), content(content_), type(type_)
{
}
std::string prefix;
std::string content;
Type::value type;
};
inline _Tag VerbatimTag(const std::string content) {
return _Tag("", content, _Tag::Type::Verbatim);
}
inline _Tag LocalTag(const std::string content) {
return _Tag("", content, _Tag::Type::PrimaryHandle);
}
inline _Tag LocalTag(const std::string& prefix, const std::string content) {
return _Tag(prefix, content, _Tag::Type::NamedHandle);
}
inline _Tag SecondaryTag(const std::string content) {
return _Tag("", content, _Tag::Type::NamedHandle);
}
struct _Comment {
_Comment(const std::string& content_): content(content_) {}
std::string content;
};
inline _Comment Comment(const std::string content) {
return _Comment(content);
}
struct _Precision {
_Precision(int floatPrecision_, int doublePrecision_): floatPrecision(floatPrecision_), doublePrecision(doublePrecision_) {}
int floatPrecision;
int doublePrecision;
}; };
};
inline _Precision FloatPrecision(int n) {
return _Precision(n, -1); explicit _Tag(const std::string& prefix_, const std::string& content_,
} Type::value type_)
: prefix(prefix_), content(content_), type(type_) {}
inline _Precision DoublePrecision(int n) { std::string prefix;
return _Precision(-1, n); std::string content;
} Type::value type;
};
inline _Precision Precision(int n) {
return _Precision(n, n); inline _Tag VerbatimTag(const std::string content) {
} return _Tag("", content, _Tag::Type::Verbatim);
}
inline _Tag LocalTag(const std::string content) {
return _Tag("", content, _Tag::Type::PrimaryHandle);
}
inline _Tag LocalTag(const std::string& prefix, const std::string content) {
return _Tag(prefix, content, _Tag::Type::NamedHandle);
}
inline _Tag SecondaryTag(const std::string content) {
return _Tag("", content, _Tag::Type::NamedHandle);
}
struct _Comment {
_Comment(const std::string& content_) : content(content_) {}
std::string content;
};
inline _Comment Comment(const std::string content) { return _Comment(content); }
struct _Precision {
_Precision(int floatPrecision_, int doublePrecision_)
: floatPrecision(floatPrecision_), doublePrecision(doublePrecision_) {}
int floatPrecision;
int doublePrecision;
};
inline _Precision FloatPrecision(int n) { return _Precision(n, -1); }
inline _Precision DoublePrecision(int n) { return _Precision(-1, n); }
inline _Precision Precision(int n) { return _Precision(n, n); }
} }
#endif // EMITTERMANIP_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // EMITTERMANIP_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#ifndef EVENTHANDLER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef EVENTHANDLER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define EVENTHANDLER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define EVENTHANDLER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
#include "yaml-cpp/anchor.h" #include "yaml-cpp/anchor.h"
#include <string> #include <string>
namespace YAML namespace YAML {
{ struct Mark;
struct Mark;
class EventHandler {
class EventHandler public:
{ virtual ~EventHandler() {}
public:
virtual ~EventHandler() {} virtual void OnDocumentStart(const Mark& mark) = 0;
virtual void OnDocumentEnd() = 0;
virtual void OnDocumentStart(const Mark& mark) = 0;
virtual void OnDocumentEnd() = 0;
virtual void OnNull(const Mark& mark, anchor_t anchor) = 0;
virtual void OnAlias(const Mark& mark, anchor_t anchor) = 0;
virtual void OnScalar(const Mark& mark, const std::string& tag, anchor_t anchor, const std::string& value) = 0;
virtual void OnSequenceStart(const Mark& mark, const std::string& tag, anchor_t anchor) = 0;
virtual void OnSequenceEnd() = 0;
virtual void OnMapStart(const Mark& mark, const std::string& tag, anchor_t anchor) = 0;
virtual void OnMapEnd() = 0;
};
}
#endif // EVENTHANDLER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 virtual void OnNull(const Mark& mark, anchor_t anchor) = 0;
virtual void OnAlias(const Mark& mark, anchor_t anchor) = 0;
virtual void OnScalar(const Mark& mark, const std::string& tag,
anchor_t anchor, const std::string& value) = 0;
virtual void OnSequenceStart(const Mark& mark, const std::string& tag,
anchor_t anchor) = 0;
virtual void OnSequenceEnd() = 0;
virtual void OnMapStart(const Mark& mark, const std::string& tag,
anchor_t anchor) = 0;
virtual void OnMapEnd() = 0;
};
}
#endif // EVENTHANDLER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#ifndef EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
#include "yaml-cpp/mark.h" #include "yaml-cpp/mark.h"
#include "yaml-cpp/traits.h" #include "yaml-cpp/traits.h"
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
#include <sstream> #include <sstream>
namespace YAML namespace YAML {
{ // error messages
// error messages namespace ErrorMsg {
namespace ErrorMsg const char* const YAML_DIRECTIVE_ARGS =
{ "YAML directives must have exactly one argument";
const char * const YAML_DIRECTIVE_ARGS = "YAML directives must have exactly one argument"; const char* const YAML_VERSION = "bad YAML version: ";
const char * const YAML_VERSION = "bad YAML version: "; const char* const YAML_MAJOR_VERSION = "YAML major version too large";
const char * const YAML_MAJOR_VERSION = "YAML major version too large"; const char* const REPEATED_YAML_DIRECTIVE = "repeated YAML directive";
const char * const REPEATED_YAML_DIRECTIVE= "repeated YAML directive"; const char* const TAG_DIRECTIVE_ARGS =
const char * const TAG_DIRECTIVE_ARGS = "TAG directives must have exactly two arguments"; "TAG directives must have exactly two arguments";
const char * const REPEATED_TAG_DIRECTIVE = "repeated TAG directive"; const char* const REPEATED_TAG_DIRECTIVE = "repeated TAG directive";
const char * const CHAR_IN_TAG_HANDLE = "illegal character found while scanning tag handle"; const char* const CHAR_IN_TAG_HANDLE =
const char * const TAG_WITH_NO_SUFFIX = "tag handle with no suffix"; "illegal character found while scanning tag handle";
const char * const END_OF_VERBATIM_TAG = "end of verbatim tag not found"; const char* const TAG_WITH_NO_SUFFIX = "tag handle with no suffix";
const char * const END_OF_MAP = "end of map not found"; const char* const END_OF_VERBATIM_TAG = "end of verbatim tag not found";
const char * const END_OF_MAP_FLOW = "end of map flow not found"; const char* const END_OF_MAP = "end of map not found";
const char * const END_OF_SEQ = "end of sequence not found"; const char* const END_OF_MAP_FLOW = "end of map flow not found";
const char * const END_OF_SEQ_FLOW = "end of sequence flow not found"; const char* const END_OF_SEQ = "end of sequence not found";
const char * const MULTIPLE_TAGS = "cannot assign multiple tags to the same node"; const char* const END_OF_SEQ_FLOW = "end of sequence flow not found";
const char * const MULTIPLE_ANCHORS = "cannot assign multiple anchors to the same node"; const char* const MULTIPLE_TAGS =
const char * const MULTIPLE_ALIASES = "cannot assign multiple aliases to the same node"; "cannot assign multiple tags to the same node";
const char * const ALIAS_CONTENT = "aliases can't have any content, *including* tags"; const char* const MULTIPLE_ANCHORS =
const char * const INVALID_HEX = "bad character found while scanning hex number"; "cannot assign multiple anchors to the same node";
const char * const INVALID_UNICODE = "invalid unicode: "; const char* const MULTIPLE_ALIASES =
const char * const INVALID_ESCAPE = "unknown escape character: "; "cannot assign multiple aliases to the same node";
const char * const UNKNOWN_TOKEN = "unknown token"; const char* const ALIAS_CONTENT =
const char * const DOC_IN_SCALAR = "illegal document indicator in scalar"; "aliases can't have any content, *including* tags";
const char * const EOF_IN_SCALAR = "illegal EOF in scalar"; const char* const INVALID_HEX = "bad character found while scanning hex number";
const char * const CHAR_IN_SCALAR = "illegal character in scalar"; const char* const INVALID_UNICODE = "invalid unicode: ";
const char * const TAB_IN_INDENTATION = "illegal tab when looking for indentation"; const char* const INVALID_ESCAPE = "unknown escape character: ";
const char * const FLOW_END = "illegal flow end"; const char* const UNKNOWN_TOKEN = "unknown token";
const char * const BLOCK_ENTRY = "illegal block entry"; const char* const DOC_IN_SCALAR = "illegal document indicator in scalar";
const char * const MAP_KEY = "illegal map key"; const char* const EOF_IN_SCALAR = "illegal EOF in scalar";
const char * const MAP_VALUE = "illegal map value"; const char* const CHAR_IN_SCALAR = "illegal character in scalar";
const char * const ALIAS_NOT_FOUND = "alias not found after *"; const char* const TAB_IN_INDENTATION =
const char * const ANCHOR_NOT_FOUND = "anchor not found after &"; "illegal tab when looking for indentation";
const char * const CHAR_IN_ALIAS = "illegal character found while scanning alias"; const char* const FLOW_END = "illegal flow end";
const char * const CHAR_IN_ANCHOR = "illegal character found while scanning anchor"; const char* const BLOCK_ENTRY = "illegal block entry";
const char * const ZERO_INDENT_IN_BLOCK = "cannot set zero indentation for a block scalar"; const char* const MAP_KEY = "illegal map key";
const char * const CHAR_IN_BLOCK = "unexpected character in block scalar"; const char* const MAP_VALUE = "illegal map value";
const char * const AMBIGUOUS_ANCHOR = "cannot assign the same alias to multiple nodes"; const char* const ALIAS_NOT_FOUND = "alias not found after *";
const char * const UNKNOWN_ANCHOR = "the referenced anchor is not defined"; const char* const ANCHOR_NOT_FOUND = "anchor not found after &";
const char* const CHAR_IN_ALIAS =
"illegal character found while scanning alias";
const char* const CHAR_IN_ANCHOR =
"illegal character found while scanning anchor";
const char* const ZERO_INDENT_IN_BLOCK =
"cannot set zero indentation for a block scalar";
const char* const CHAR_IN_BLOCK = "unexpected character in block scalar";
const char* const AMBIGUOUS_ANCHOR =
"cannot assign the same alias to multiple nodes";
const char* const UNKNOWN_ANCHOR = "the referenced anchor is not defined";
const char * const UNMATCHED_GROUP_TAG = "unmatched group tag"; const char* const UNMATCHED_GROUP_TAG = "unmatched group tag";
const char * const UNEXPECTED_END_SEQ = "unexpected end sequence token"; const char* const UNEXPECTED_END_SEQ = "unexpected end sequence token";
const char * const UNEXPECTED_END_MAP = "unexpected end map token"; const char* const UNEXPECTED_END_MAP = "unexpected end map token";
const char * const SINGLE_QUOTED_CHAR = "invalid character in single-quoted string"; const char* const SINGLE_QUOTED_CHAR =
const char * const INVALID_ANCHOR = "invalid anchor"; "invalid character in single-quoted string";
const char * const INVALID_ALIAS = "invalid alias"; const char* const INVALID_ANCHOR = "invalid anchor";
const char * const INVALID_TAG = "invalid tag"; const char* const INVALID_ALIAS = "invalid alias";
} const char* const INVALID_TAG = "invalid tag";
}
class Exception: public std::runtime_error { class Exception : public std::runtime_error {
public: public:
Exception(const Mark& mark_, const std::string& msg_) Exception(const Mark& mark_, const std::string& msg_)
: std::runtime_error(build_what(mark_, msg_)), mark(mark_), msg(msg_) {} : std::runtime_error(build_what(mark_, msg_)), mark(mark_), msg(msg_) {}
virtual ~Exception() throw() {} virtual ~Exception() throw() {}
Mark mark; Mark mark;
std::string msg; std::string msg;
private: private:
static const std::string build_what(const Mark& mark, const std::string& msg) { static const std::string build_what(const Mark& mark,
std::stringstream output; const std::string& msg) {
output << "yaml-cpp: error at line " << mark.line+1 << ", column " << mark.column+1 << ": " << msg; std::stringstream output;
return output.str(); output << "yaml-cpp: error at line " << mark.line + 1 << ", column "
} << mark.column + 1 << ": " << msg;
}; return output.str();
}
};
class ParserException: public Exception { class ParserException : public Exception {
public: public:
ParserException(const Mark& mark_, const std::string& msg_) ParserException(const Mark& mark_, const std::string& msg_)
: Exception(mark_, msg_) {} : Exception(mark_, msg_) {}
}; };
class EmitterException: public Exception { class EmitterException : public Exception {
public: public:
EmitterException(const std::string& msg_) EmitterException(const std::string& msg_)
: Exception(Mark::null_mark(), msg_) {} : Exception(Mark::null_mark(), msg_) {}
}; };
} }
#endif // EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#ifndef MARK_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef MARK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define MARK_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define MARK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
#include "yaml-cpp/dll.h" #include "yaml-cpp/dll.h"
namespace YAML namespace YAML {
{ struct YAML_CPP_API Mark {
struct YAML_CPP_API Mark { Mark() : pos(0), line(0), column(0) {}
Mark(): pos(0), line(0), column(0) {}
static const Mark null_mark() { return Mark(-1, -1, -1); }
static const Mark null_mark() { return Mark(-1, -1, -1); }
int pos;
int pos; int line, column;
int line, column;
private:
private: Mark(int pos_, int line_, int column_)
Mark(int pos_, int line_, int column_): pos(pos_), line(line_), column(column_) {} : pos(pos_), line(line_), column(column_) {}
}; };
} }
#endif // MARK_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // MARK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#ifndef NONCOPYABLE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef NONCOPYABLE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define NONCOPYABLE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define NONCOPYABLE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
#include "yaml-cpp/dll.h" #include "yaml-cpp/dll.h"
namespace YAML namespace YAML {
{ // this is basically boost::noncopyable
// this is basically boost::noncopyable class YAML_CPP_API noncopyable {
class YAML_CPP_API noncopyable protected:
{ noncopyable() {}
protected: ~noncopyable() {}
noncopyable() {}
~noncopyable() {} private:
noncopyable(const noncopyable&);
private: const noncopyable& operator=(const noncopyable&);
noncopyable(const noncopyable&); };
const noncopyable& operator = (const noncopyable&);
};
} }
#endif // NONCOPYABLE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // NONCOPYABLE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#ifndef NULL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef NULL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define NULL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define NULL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
#include "yaml-cpp/dll.h" #include "yaml-cpp/dll.h"
namespace YAML namespace YAML {
{ class Node;
class Node;
struct YAML_CPP_API _Null {};
struct YAML_CPP_API _Null {}; inline bool operator==(const _Null&, const _Null&) { return true; }
inline bool operator == (const _Null&, const _Null&) { return true; } inline bool operator!=(const _Null&, const _Null&) { return false; }
inline bool operator != (const _Null&, const _Null&) { return false; }
YAML_CPP_API bool IsNull(const Node& node); // old API only
extern YAML_CPP_API _Null Null;
}
#endif // NULL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 YAML_CPP_API bool IsNull(const Node& node); // old API only
extern YAML_CPP_API _Null Null;
}
#endif // NULL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#ifndef OSTREAM_WRAPPER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef OSTREAM_WRAPPER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define OSTREAM_WRAPPER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define OSTREAM_WRAPPER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
#include <string> #include <string>
#include <vector> #include <vector>
namespace YAML namespace YAML {
{ class ostream_wrapper {
class ostream_wrapper public:
{ ostream_wrapper();
public: explicit ostream_wrapper(std::ostream& stream);
ostream_wrapper(); ~ostream_wrapper();
explicit ostream_wrapper(std::ostream& stream);
~ostream_wrapper();
void write(const std::string& str);
void write(const char *str, std::size_t size);
void set_comment() { m_comment = true; }
const char *str() const { void write(const std::string& str);
if(m_pStream) { void write(const char* str, std::size_t size);
return 0;
} else {
m_buffer[m_pos] = '\0';
return &m_buffer[0];
}
}
std::size_t row() const { return m_row; }
std::size_t col() const { return m_col; }
std::size_t pos() const { return m_pos; }
bool comment() const { return m_comment; }
private:
void update_pos(char ch);
private:
mutable std::vector<char> m_buffer;
std::ostream *m_pStream;
std::size_t m_pos; void set_comment() { m_comment = true; }
std::size_t m_row, m_col;
bool m_comment; const char* str() const {
}; if (m_pStream) {
return 0;
template<std::size_t N> } else {
inline ostream_wrapper& operator << (ostream_wrapper& stream, const char (&str)[N]) { m_buffer[m_pos] = '\0';
stream.write(str, N-1); return &m_buffer[0];
return stream;
}
inline ostream_wrapper& operator << (ostream_wrapper& stream, const std::string& str) {
stream.write(str);
return stream;
}
inline ostream_wrapper& operator << (ostream_wrapper& stream, char ch) {
stream.write(&ch, 1);
return stream;
} }
}
std::size_t row() const { return m_row; }
std::size_t col() const { return m_col; }
std::size_t pos() const { return m_pos; }
bool comment() const { return m_comment; }
private:
void update_pos(char ch);
private:
mutable std::vector<char> m_buffer;
std::ostream* m_pStream;
std::size_t m_pos;
std::size_t m_row, m_col;
bool m_comment;
};
template <std::size_t N>
inline ostream_wrapper& operator<<(ostream_wrapper& stream,
const char (&str)[N]) {
stream.write(str, N - 1);
return stream;
}
inline ostream_wrapper& operator<<(ostream_wrapper& stream,
const std::string& str) {
stream.write(str);
return stream;
}
inline ostream_wrapper& operator<<(ostream_wrapper& stream, char ch) {
stream.write(&ch, 1);
return stream;
}
} }
#endif // OSTREAM_WRAPPER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // OSTREAM_WRAPPER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#ifndef PARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef PARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define PARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define PARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
#include "yaml-cpp/dll.h" #include "yaml-cpp/dll.h"
#include "yaml-cpp/noncopyable.h" #include "yaml-cpp/noncopyable.h"
#include <ios> #include <ios>
#include <memory> #include <memory>
namespace YAML namespace YAML {
{ struct Directives;
struct Directives; struct Mark;
struct Mark; struct Token;
struct Token; class EventHandler;
class EventHandler; class Node;
class Node; class Scanner;
class Scanner;
class YAML_CPP_API Parser : private noncopyable {
class YAML_CPP_API Parser: private noncopyable public:
{ Parser();
public: Parser(std::istream& in);
Parser(); ~Parser();
Parser(std::istream& in);
~Parser(); operator bool() const;
operator bool() const; void Load(std::istream& in);
bool HandleNextDocument(EventHandler& eventHandler);
void Load(std::istream& in);
bool HandleNextDocument(EventHandler& eventHandler); void PrintTokens(std::ostream& out);
void PrintTokens(std::ostream& out); private:
void ParseDirectives();
private: void HandleDirective(const Token& token);
void ParseDirectives(); void HandleYamlDirective(const Token& token);
void HandleDirective(const Token& token); void HandleTagDirective(const Token& token);
void HandleYamlDirective(const Token& token);
void HandleTagDirective(const Token& token); private:
std::auto_ptr<Scanner> m_pScanner;
private: std::auto_ptr<Directives> m_pDirectives;
std::auto_ptr<Scanner> m_pScanner; };
std::auto_ptr<Directives> m_pDirectives;
};
} }
#endif // PARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // PARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#ifndef STLEMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef STLEMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define STLEMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define STLEMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
#include <vector> #include <vector>
#include <list> #include <list>
#include <set> #include <set>
#include <map> #include <map>
namespace YAML namespace YAML {
{ template <typename Seq>
template<typename Seq> inline Emitter& EmitSeq(Emitter& emitter, const Seq& seq) {
inline Emitter& EmitSeq(Emitter& emitter, const Seq& seq) { emitter << BeginSeq;
emitter << BeginSeq; for (typename Seq::const_iterator it = seq.begin(); it != seq.end(); ++it)
for(typename Seq::const_iterator it=seq.begin();it!=seq.end();++it) emitter << *it;
emitter << *it; emitter << EndSeq;
emitter << EndSeq; return emitter;
return emitter; }
}
template <typename T>
template<typename T> inline Emitter& operator<<(Emitter& emitter, const std::vector<T>& v) {
inline Emitter& operator << (Emitter& emitter, const std::vector<T>& v) { return EmitSeq(emitter, v);
return EmitSeq(emitter, v); }
}
template <typename T>
template<typename T> inline Emitter& operator<<(Emitter& emitter, const std::list<T>& v) {
inline Emitter& operator << (Emitter& emitter, const std::list<T>& v) { return EmitSeq(emitter, v);
return EmitSeq(emitter, v); }
}
template <typename T>
template<typename T> inline Emitter& operator<<(Emitter& emitter, const std::set<T>& v) {
inline Emitter& operator << (Emitter& emitter, const std::set<T>& v) { return EmitSeq(emitter, v);
return EmitSeq(emitter, v); }
}
template <typename K, typename V>
template <typename K, typename V> inline Emitter& operator<<(Emitter& emitter, const std::map<K, V>& m) {
inline Emitter& operator << (Emitter& emitter, const std::map<K, V>& m) { typedef typename std::map<K, V> map;
typedef typename std::map <K, V> map; emitter << BeginMap;
emitter << BeginMap; for (typename map::const_iterator it = m.begin(); it != m.end(); ++it)
for(typename map::const_iterator it=m.begin();it!=m.end();++it) emitter << Key << it->first << Value << it->second;
emitter << Key << it->first << Value << it->second; emitter << EndMap;
emitter << EndMap; return emitter;
return emitter; }
}
} }
#endif // STLEMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // STLEMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#ifndef TRAITS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef TRAITS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define TRAITS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define TRAITS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
namespace YAML {
template <typename>
struct is_numeric {
enum {
value = false
};
};
namespace YAML template <>
{ struct is_numeric<char> {
template <typename> enum {
struct is_numeric { enum { value = false }; }; value = true
};
template <> struct is_numeric <char> { enum { value = true }; }; };
template <> struct is_numeric <unsigned char> { enum { value = true }; }; template <>
template <> struct is_numeric <int> { enum { value = true }; }; struct is_numeric<unsigned char> {
template <> struct is_numeric <unsigned int> { enum { value = true }; }; enum {
template <> struct is_numeric <long int> { enum { value = true }; }; value = true
template <> struct is_numeric <unsigned long int> { enum { value = true }; }; };
template <> struct is_numeric <short int> { enum { value = true }; }; };
template <> struct is_numeric <unsigned short int> { enum { value = true }; }; template <>
struct is_numeric<int> {
enum {
value = true
};
};
template <>
struct is_numeric<unsigned int> {
enum {
value = true
};
};
template <>
struct is_numeric<long int> {
enum {
value = true
};
};
template <>
struct is_numeric<unsigned long int> {
enum {
value = true
};
};
template <>
struct is_numeric<short int> {
enum {
value = true
};
};
template <>
struct is_numeric<unsigned short int> {
enum {
value = true
};
};
#if defined(_MSC_VER) && (_MSC_VER < 1310) #if defined(_MSC_VER) && (_MSC_VER < 1310)
template <> struct is_numeric <__int64> { enum { value = true }; }; template <>
template <> struct is_numeric <unsigned __int64> { enum { value = true }; }; struct is_numeric<__int64> {
enum {
value = true
};
};
template <>
struct is_numeric<unsigned __int64> {
enum {
value = true
};
};
#else #else
template <> struct is_numeric <long long> { enum { value = true }; }; template <>
template <> struct is_numeric <unsigned long long> { enum { value = true }; }; struct is_numeric<long long> {
enum {
value = true
};
};
template <>
struct is_numeric<unsigned long long> {
enum {
value = true
};
};
#endif #endif
template <> struct is_numeric <float> { enum { value = true }; }; template <>
template <> struct is_numeric <double> { enum { value = true }; }; struct is_numeric<float> {
template <> struct is_numeric <long double> { enum { value = true }; }; enum {
value = true
};
};
template <>
struct is_numeric<double> {
enum {
value = true
};
};
template <>
struct is_numeric<long double> {
enum {
value = true
};
};
template <bool, class T = void> template <bool, class T = void>
struct enable_if_c { struct enable_if_c {
typedef T type; typedef T type;
}; };
template <class T> template <class T>
struct enable_if_c<false, T> {}; struct enable_if_c<false, T> {};
template <class Cond, class T = void> template <class Cond, class T = void>
struct enable_if : public enable_if_c<Cond::value, T> {}; struct enable_if : public enable_if_c<Cond::value, T> {};
template <bool, class T = void> template <bool, class T = void>
struct disable_if_c { struct disable_if_c {
typedef T type; typedef T type;
}; };
template <class T> template <class T>
struct disable_if_c<true, T> {}; struct disable_if_c<true, T> {};
template <class Cond, class T = void> template <class Cond, class T = void>
struct disable_if : public disable_if_c<Cond::value, T> {}; struct disable_if : public disable_if_c<Cond::value, T> {};
} }
#endif // TRAITS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // TRAITS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#ifndef YAML_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef YAML_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define YAML_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define YAML_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
...@@ -10,4 +12,4 @@ ...@@ -10,4 +12,4 @@
#include "yaml-cpp/stlemitter.h" #include "yaml-cpp/stlemitter.h"
#include "yaml-cpp/exceptions.h" #include "yaml-cpp/exceptions.h"
#endif // YAML_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // YAML_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#include "yaml-cpp/binary.h" #include "yaml-cpp/binary.h"
namespace YAML namespace YAML {
{ static const char encoding[] =
static const char encoding[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
std::string EncodeBase64(const unsigned char *data, std::size_t size) std::string EncodeBase64(const unsigned char *data, std::size_t size) {
{ const char PAD = '=';
const char PAD = '=';
std::string ret;
std::string ret; ret.resize(4 * size / 3 + 3);
ret.resize(4 * size / 3 + 3); char *out = &ret[0];
char *out = &ret[0];
std::size_t chunks = size / 3;
std::size_t chunks = size / 3; std::size_t remainder = size % 3;
std::size_t remainder = size % 3;
for (std::size_t i = 0; i < chunks; i++, data += 3) {
for(std::size_t i=0;i<chunks;i++, data += 3) { *out++ = encoding[data[0] >> 2];
*out++ = encoding[data[0] >> 2]; *out++ = encoding[((data[0] & 0x3) << 4) | (data[1] >> 4)];
*out++ = encoding[((data[0] & 0x3) << 4) | (data[1] >> 4)]; *out++ = encoding[((data[1] & 0xf) << 2) | (data[2] >> 6)];
*out++ = encoding[((data[1] & 0xf) << 2) | (data[2] >> 6)]; *out++ = encoding[data[2] & 0x3f];
*out++ = encoding[data[2] & 0x3f]; }
}
switch (remainder) {
switch(remainder) { case 0:
case 0: break;
break; case 1:
case 1: *out++ = encoding[data[0] >> 2];
*out++ = encoding[data[0] >> 2]; *out++ = encoding[((data[0] & 0x3) << 4)];
*out++ = encoding[((data[0] & 0x3) << 4)]; *out++ = PAD;
*out++ = PAD; *out++ = PAD;
*out++ = PAD; break;
break; case 2:
case 2: *out++ = encoding[data[0] >> 2];
*out++ = encoding[data[0] >> 2]; *out++ = encoding[((data[0] & 0x3) << 4) | (data[1] >> 4)];
*out++ = encoding[((data[0] & 0x3) << 4) | (data[1] >> 4)]; *out++ = encoding[((data[1] & 0xf) << 2)];
*out++ = encoding[((data[1] & 0xf) << 2)]; *out++ = PAD;
*out++ = PAD; break;
break; }
}
ret.resize(out - &ret[0]);
ret.resize(out - &ret[0]); return ret;
return ret; }
}
static const unsigned char decoding[] = {
static const unsigned char decoding[] = { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 62, 255,
255,255,255,255,255,255,255,255,255,255,255, 62,255,255,255, 63, 255, 255, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61,255,255,255, 0,255,255, 255, 0, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,255,255,255,255,255, 25, 255, 255, 255, 255, 255, 255, 26, 27, 28, 29, 30, 31, 32, 33,
255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,255,255,255,255,255, 49, 50, 51, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
}; 255, };
std::vector<unsigned char> DecodeBase64(const std::string &input) {
typedef std::vector<unsigned char> ret_type;
if (input.empty())
return ret_type();
std::vector<unsigned char> DecodeBase64(const std::string& input) ret_type ret(3 * input.size() / 4 + 1);
{ unsigned char *out = &ret[0];
typedef std::vector<unsigned char> ret_type;
if(input.empty())
return ret_type();
ret_type ret(3 * input.size() / 4 + 1);
unsigned char *out = &ret[0];
unsigned value = 0;
for(std::size_t i=0;i<input.size();i++) {
unsigned char d = decoding[static_cast<unsigned>(input[i])];
if(d == 255)
return ret_type();
value = (value << 6) | d; unsigned value = 0;
if(i % 4 == 3) { for (std::size_t i = 0; i < input.size(); i++) {
*out++ = value >> 16; unsigned char d = decoding[static_cast<unsigned>(input[i])];
if(i > 0 && input[i - 1] != '=') if (d == 255)
*out++ = value >> 8; return ret_type();
if(input[i] != '=')
*out++ = value; value = (value << 6) | d;
} if (i % 4 == 3) {
} *out++ = value >> 16;
if (i > 0 && input[i - 1] != '=')
ret.resize(out - &ret[0]); *out++ = value >> 8;
return ret; if (input[i] != '=')
*out++ = value;
} }
}
ret.resize(out - &ret[0]);
return ret;
}
} }
#ifndef COLLECTIONSTACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef COLLECTIONSTACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define COLLECTIONSTACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define COLLECTIONSTACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
#include <stack> #include <stack>
#include <cassert> #include <cassert>
namespace YAML namespace YAML {
{ struct CollectionType {
struct CollectionType { enum value {
enum value { None, BlockMap, BlockSeq, FlowMap, FlowSeq, CompactMap }; None,
}; BlockMap,
BlockSeq,
FlowMap,
FlowSeq,
CompactMap
};
};
class CollectionStack {
public:
CollectionType::value GetCurCollectionType() const {
if (collectionStack.empty())
return CollectionType::None;
return collectionStack.top();
}
void PushCollectionType(CollectionType::value type) {
collectionStack.push(type);
}
void PopCollectionType(CollectionType::value type) {
assert(type == GetCurCollectionType());
collectionStack.pop();
}
class CollectionStack private:
{ std::stack<CollectionType::value> collectionStack;
public: };
CollectionType::value GetCurCollectionType() const {
if(collectionStack.empty())
return CollectionType::None;
return collectionStack.top();
}
void PushCollectionType(CollectionType::value type) { collectionStack.push(type); }
void PopCollectionType(CollectionType::value type) { assert(type == GetCurCollectionType()); collectionStack.pop(); }
private:
std::stack<CollectionType::value> collectionStack;
};
} }
#endif // COLLECTIONSTACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // COLLECTIONSTACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
...@@ -2,15 +2,14 @@ ...@@ -2,15 +2,14 @@
#include "yaml-cpp/contrib/graphbuilder.h" #include "yaml-cpp/contrib/graphbuilder.h"
#include "graphbuilderadapter.h" #include "graphbuilderadapter.h"
namespace YAML namespace YAML {
{ void* BuildGraphOfNextDocument(Parser& parser,
void *BuildGraphOfNextDocument(Parser& parser, GraphBuilderInterface& graphBuilder) GraphBuilderInterface& graphBuilder) {
{ GraphBuilderAdapter eventHandler(graphBuilder);
GraphBuilderAdapter eventHandler(graphBuilder); if (parser.HandleNextDocument(eventHandler)) {
if (parser.HandleNextDocument(eventHandler)) { return eventHandler.RootNode();
return eventHandler.RootNode(); } else {
} else { return NULL;
return NULL;
}
} }
} }
}
#include "graphbuilderadapter.h" #include "graphbuilderadapter.h"
namespace YAML namespace YAML {
{ int GraphBuilderAdapter::ContainerFrame::sequenceMarker;
int GraphBuilderAdapter::ContainerFrame::sequenceMarker;
void GraphBuilderAdapter::OnNull(const Mark &mark, anchor_t anchor) {
void GraphBuilderAdapter::OnNull(const Mark& mark, anchor_t anchor) void *pParent = GetCurrentParent();
{ void *pNode = m_builder.NewNull(mark, pParent);
void *pParent = GetCurrentParent(); RegisterAnchor(anchor, pNode);
void *pNode = m_builder.NewNull(mark, pParent);
RegisterAnchor(anchor, pNode); DispositionNode(pNode);
}
DispositionNode(pNode);
} void GraphBuilderAdapter::OnAlias(const Mark &mark, anchor_t anchor) {
void *pReffedNode = m_anchors.Get(anchor);
void GraphBuilderAdapter::OnAlias(const Mark& mark, anchor_t anchor) DispositionNode(m_builder.AnchorReference(mark, pReffedNode));
{ }
void *pReffedNode = m_anchors.Get(anchor);
DispositionNode(m_builder.AnchorReference(mark, pReffedNode)); void GraphBuilderAdapter::OnScalar(const Mark &mark, const std::string &tag,
} anchor_t anchor, const std::string &value) {
void *pParent = GetCurrentParent();
void GraphBuilderAdapter::OnScalar(const Mark& mark, const std::string& tag, anchor_t anchor, const std::string& value) void *pNode = m_builder.NewScalar(mark, tag, pParent, value);
{ RegisterAnchor(anchor, pNode);
void *pParent = GetCurrentParent();
void *pNode = m_builder.NewScalar(mark, tag, pParent, value); DispositionNode(pNode);
RegisterAnchor(anchor, pNode); }
DispositionNode(pNode); void GraphBuilderAdapter::OnSequenceStart(const Mark &mark,
} const std::string &tag,
anchor_t anchor) {
void GraphBuilderAdapter::OnSequenceStart(const Mark& mark, const std::string& tag, anchor_t anchor) void *pNode = m_builder.NewSequence(mark, tag, GetCurrentParent());
{ m_containers.push(ContainerFrame(pNode));
void *pNode = m_builder.NewSequence(mark, tag, GetCurrentParent()); RegisterAnchor(anchor, pNode);
m_containers.push(ContainerFrame(pNode)); }
RegisterAnchor(anchor, pNode);
} void GraphBuilderAdapter::OnSequenceEnd() {
void *pSequence = m_containers.top().pContainer;
void GraphBuilderAdapter::OnSequenceEnd() m_containers.pop();
{
void *pSequence = m_containers.top().pContainer; DispositionNode(pSequence);
m_containers.pop(); }
DispositionNode(pSequence); void GraphBuilderAdapter::OnMapStart(const Mark &mark, const std::string &tag,
} anchor_t anchor) {
void *pNode = m_builder.NewMap(mark, tag, GetCurrentParent());
void GraphBuilderAdapter::OnMapStart(const Mark& mark, const std::string& tag, anchor_t anchor) m_containers.push(ContainerFrame(pNode, m_pKeyNode));
{ m_pKeyNode = NULL;
void *pNode = m_builder.NewMap(mark, tag, GetCurrentParent()); RegisterAnchor(anchor, pNode);
m_containers.push(ContainerFrame(pNode, m_pKeyNode)); }
m_pKeyNode = NULL;
RegisterAnchor(anchor, pNode); void GraphBuilderAdapter::OnMapEnd() {
} void *pMap = m_containers.top().pContainer;
m_pKeyNode = m_containers.top().pPrevKeyNode;
void GraphBuilderAdapter::OnMapEnd() m_containers.pop();
{ DispositionNode(pMap);
void *pMap = m_containers.top().pContainer; }
m_pKeyNode = m_containers.top().pPrevKeyNode;
m_containers.pop(); void *GraphBuilderAdapter::GetCurrentParent() const {
DispositionNode(pMap); if (m_containers.empty()) {
return NULL;
} }
return m_containers.top().pContainer;
void *GraphBuilderAdapter::GetCurrentParent() const }
{
if (m_containers.empty()) { void GraphBuilderAdapter::RegisterAnchor(anchor_t anchor, void *pNode) {
return NULL; if (anchor) {
} m_anchors.Register(anchor, pNode);
return m_containers.top().pContainer;
} }
}
void GraphBuilderAdapter::RegisterAnchor(anchor_t anchor, void *pNode)
{ void GraphBuilderAdapter::DispositionNode(void *pNode) {
if (anchor) { if (m_containers.empty()) {
m_anchors.Register(anchor, pNode); m_pRootNode = pNode;
} return;
} }
void GraphBuilderAdapter::DispositionNode(void *pNode) void *pContainer = m_containers.top().pContainer;
{ if (m_containers.top().isMap()) {
if (m_containers.empty()) { if (m_pKeyNode) {
m_pRootNode = pNode; m_builder.AssignInMap(pContainer, m_pKeyNode, pNode);
return; m_pKeyNode = NULL;
}
void *pContainer = m_containers.top().pContainer;
if (m_containers.top().isMap()) {
if (m_pKeyNode) {
m_builder.AssignInMap(pContainer, m_pKeyNode, pNode);
m_pKeyNode = NULL;
} else {
m_pKeyNode = pNode;
}
} else { } else {
m_builder.AppendToSequence(pContainer, pNode); m_pKeyNode = pNode;
} }
} else {
m_builder.AppendToSequence(pContainer, pNode);
} }
} }
}
#ifndef GRAPHBUILDERADAPTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef GRAPHBUILDERADAPTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define GRAPHBUILDERADAPTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define GRAPHBUILDERADAPTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
...@@ -12,62 +14,58 @@ ...@@ -12,62 +14,58 @@
#include "yaml-cpp/contrib/anchordict.h" #include "yaml-cpp/contrib/anchordict.h"
#include "yaml-cpp/contrib/graphbuilder.h" #include "yaml-cpp/contrib/graphbuilder.h"
namespace YAML namespace YAML {
{ class GraphBuilderAdapter : public EventHandler {
class GraphBuilderAdapter : public EventHandler public:
{ GraphBuilderAdapter(GraphBuilderInterface& builder)
public: : m_builder(builder), m_pRootNode(NULL), m_pKeyNode(NULL) {}
GraphBuilderAdapter(GraphBuilderInterface& builder)
: m_builder(builder), m_pRootNode(NULL), m_pKeyNode(NULL) virtual void OnDocumentStart(const Mark& mark) { (void)mark; }
{ virtual void OnDocumentEnd() {}
}
virtual void OnNull(const Mark& mark, anchor_t anchor);
virtual void OnDocumentStart(const Mark& mark) {(void)mark;} virtual void OnAlias(const Mark& mark, anchor_t anchor);
virtual void OnDocumentEnd() {} virtual void OnScalar(const Mark& mark, const std::string& tag,
anchor_t anchor, const std::string& value);
virtual void OnNull(const Mark& mark, anchor_t anchor);
virtual void OnAlias(const Mark& mark, anchor_t anchor); virtual void OnSequenceStart(const Mark& mark, const std::string& tag,
virtual void OnScalar(const Mark& mark, const std::string& tag, anchor_t anchor, const std::string& value); anchor_t anchor);
virtual void OnSequenceEnd();
virtual void OnSequenceStart(const Mark& mark, const std::string& tag, anchor_t anchor);
virtual void OnSequenceEnd(); virtual void OnMapStart(const Mark& mark, const std::string& tag,
anchor_t anchor);
virtual void OnMapStart(const Mark& mark, const std::string& tag, anchor_t anchor); virtual void OnMapEnd();
virtual void OnMapEnd();
void* RootNode() const { return m_pRootNode; }
void *RootNode() const {return m_pRootNode;}
private:
private: struct ContainerFrame {
struct ContainerFrame ContainerFrame(void* pSequence)
{ : pContainer(pSequence), pPrevKeyNode(&sequenceMarker) {}
ContainerFrame(void *pSequence) ContainerFrame(void* pMap, void* pPrevKeyNode)
: pContainer(pSequence), pPrevKeyNode(&sequenceMarker) : pContainer(pMap), pPrevKeyNode(pPrevKeyNode) {}
{}
ContainerFrame(void *pMap, void* pPrevKeyNode) void* pContainer;
: pContainer(pMap), pPrevKeyNode(pPrevKeyNode) void* pPrevKeyNode;
{}
bool isMap() const { return pPrevKeyNode != &sequenceMarker; }
void *pContainer;
void *pPrevKeyNode; private:
static int sequenceMarker;
bool isMap() const {return pPrevKeyNode != &sequenceMarker;}
private:
static int sequenceMarker;
};
typedef std::stack<ContainerFrame> ContainerStack;
typedef AnchorDict<void*> AnchorMap;
GraphBuilderInterface& m_builder;
ContainerStack m_containers;
AnchorMap m_anchors;
void *m_pRootNode;
void *m_pKeyNode;
void *GetCurrentParent() const;
void RegisterAnchor(anchor_t anchor, void *pNode);
void DispositionNode(void *pNode);
}; };
typedef std::stack<ContainerFrame> ContainerStack;
typedef AnchorDict<void*> AnchorMap;
GraphBuilderInterface& m_builder;
ContainerStack m_containers;
AnchorMap m_anchors;
void* m_pRootNode;
void* m_pKeyNode;
void* GetCurrentParent() const;
void RegisterAnchor(anchor_t anchor, void* pNode);
void DispositionNode(void* pNode);
};
} }
#endif // GRAPHBUILDERADAPTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // GRAPHBUILDERADAPTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#include "directives.h" #include "directives.h"
namespace YAML namespace YAML {
{ Directives::Directives() {
Directives::Directives() // version
{ version.isDefault = true;
// version version.major = 1;
version.isDefault = true; version.minor = 2;
version.major = 1; }
version.minor = 2;
} const std::string Directives::TranslateTagHandle(const std::string& handle)
const {
const std::string Directives::TranslateTagHandle(const std::string& handle) const std::map<std::string, std::string>::const_iterator it = tags.find(handle);
{ if (it == tags.end()) {
std::map <std::string, std::string>::const_iterator it = tags.find(handle); if (handle == "!!")
if(it == tags.end()) { return "tag:yaml.org,2002:";
if(handle == "!!") return handle;
return "tag:yaml.org,2002:"; }
return handle;
} return it->second;
}
return it->second;
}
} }
#ifndef DIRECTIVES_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef DIRECTIVES_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define DIRECTIVES_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define DIRECTIVES_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
#include <string> #include <string>
#include <map> #include <map>
namespace YAML namespace YAML {
{ struct Version {
struct Version { bool isDefault;
bool isDefault; int major, minor;
int major, minor; };
};
struct Directives {
struct Directives { Directives();
Directives();
const std::string TranslateTagHandle(const std::string& handle) const;
const std::string TranslateTagHandle(const std::string& handle) const;
Version version; Version version;
std::map<std::string, std::string> tags; std::map<std::string, std::string> tags;
}; };
} }
#endif // DIRECTIVES_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // DIRECTIVES_H_62B23520_7C8E_11DE_8A39_0800200C9A66
...@@ -5,101 +5,88 @@ ...@@ -5,101 +5,88 @@
#include <sstream> #include <sstream>
namespace { namespace {
std::string ToString(YAML::anchor_t anchor) { std::string ToString(YAML::anchor_t anchor) {
std::stringstream stream; std::stringstream stream;
stream << anchor; stream << anchor;
return stream.str(); return stream.str();
} }
}
namespace YAML {
EmitFromEvents::EmitFromEvents(Emitter& emitter) : m_emitter(emitter) {}
void EmitFromEvents::OnDocumentStart(const Mark&) {}
void EmitFromEvents::OnDocumentEnd() {}
void EmitFromEvents::OnNull(const Mark&, anchor_t anchor) {
BeginNode();
EmitProps("", anchor);
m_emitter << Null;
}
void EmitFromEvents::OnAlias(const Mark&, anchor_t anchor) {
BeginNode();
m_emitter << Alias(ToString(anchor));
}
void EmitFromEvents::OnScalar(const Mark&, const std::string& tag,
anchor_t anchor, const std::string& value) {
BeginNode();
EmitProps(tag, anchor);
m_emitter << value;
} }
namespace YAML void EmitFromEvents::OnSequenceStart(const Mark&, const std::string& tag,
{ anchor_t anchor) {
EmitFromEvents::EmitFromEvents(Emitter& emitter): m_emitter(emitter) BeginNode();
{ EmitProps(tag, anchor);
} m_emitter << BeginSeq;
m_stateStack.push(State::WaitingForSequenceEntry);
void EmitFromEvents::OnDocumentStart(const Mark&) }
{
} void EmitFromEvents::OnSequenceEnd() {
m_emitter << EndSeq;
void EmitFromEvents::OnDocumentEnd() assert(m_stateStack.top() == State::WaitingForSequenceEntry);
{ m_stateStack.pop();
} }
void EmitFromEvents::OnNull(const Mark&, anchor_t anchor) void EmitFromEvents::OnMapStart(const Mark&, const std::string& tag,
{ anchor_t anchor) {
BeginNode(); BeginNode();
EmitProps("", anchor); EmitProps(tag, anchor);
m_emitter << Null; m_emitter << BeginMap;
} m_stateStack.push(State::WaitingForKey);
}
void EmitFromEvents::OnAlias(const Mark&, anchor_t anchor)
{
BeginNode();
m_emitter << Alias(ToString(anchor));
}
void EmitFromEvents::OnScalar(const Mark&, const std::string& tag, anchor_t anchor, const std::string& value)
{
BeginNode();
EmitProps(tag, anchor);
m_emitter << value;
}
void EmitFromEvents::OnSequenceStart(const Mark&, const std::string& tag, anchor_t anchor)
{
BeginNode();
EmitProps(tag, anchor);
m_emitter << BeginSeq;
m_stateStack.push(State::WaitingForSequenceEntry);
}
void EmitFromEvents::OnSequenceEnd()
{
m_emitter << EndSeq;
assert(m_stateStack.top() == State::WaitingForSequenceEntry);
m_stateStack.pop();
}
void EmitFromEvents::OnMapStart(const Mark&, const std::string& tag, anchor_t anchor)
{
BeginNode();
EmitProps(tag, anchor);
m_emitter << BeginMap;
m_stateStack.push(State::WaitingForKey);
}
void EmitFromEvents::OnMapEnd() void EmitFromEvents::OnMapEnd() {
{ m_emitter << EndMap;
m_emitter << EndMap; assert(m_stateStack.top() == State::WaitingForKey);
assert(m_stateStack.top() == State::WaitingForKey); m_stateStack.pop();
m_stateStack.pop(); }
}
void EmitFromEvents::BeginNode() {
if (m_stateStack.empty())
return;
void EmitFromEvents::BeginNode() switch (m_stateStack.top()) {
{ case State::WaitingForKey:
if(m_stateStack.empty()) m_emitter << Key;
return; m_stateStack.top() = State::WaitingForValue;
break;
switch(m_stateStack.top()) { case State::WaitingForValue:
case State::WaitingForKey: m_emitter << Value;
m_emitter << Key; m_stateStack.top() = State::WaitingForKey;
m_stateStack.top() = State::WaitingForValue; break;
break; default:
case State::WaitingForValue: break;
m_emitter << Value; }
m_stateStack.top() = State::WaitingForKey; }
break;
default: void EmitFromEvents::EmitProps(const std::string& tag, anchor_t anchor) {
break; if (!tag.empty() && tag != "?")
} m_emitter << VerbatimTag(tag);
} if (anchor)
m_emitter << Anchor(ToString(anchor));
void EmitFromEvents::EmitProps(const std::string& tag, anchor_t anchor) }
{
if(!tag.empty() && tag != "?")
m_emitter << VerbatimTag(tag);
if(anchor)
m_emitter << Anchor(ToString(anchor));
}
} }
#ifndef EMITTERUTILS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef EMITTERUTILS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define EMITTERUTILS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define EMITTERUTILS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
#include "emitterstate.h" #include "emitterstate.h"
#include "yaml-cpp/ostream_wrapper.h" #include "yaml-cpp/ostream_wrapper.h"
#include <string> #include <string>
namespace YAML namespace YAML {
{ class Binary;
class Binary;
struct StringFormat {
struct StringFormat { enum value { Plain, SingleQuoted, DoubleQuoted, Literal }; }; enum value {
Plain,
SingleQuoted,
DoubleQuoted,
Literal
};
};
namespace Utils namespace Utils {
{ StringFormat::value ComputeStringFormat(const std::string& str,
StringFormat::value ComputeStringFormat(const std::string& str, EMITTER_MANIP strFormat, FlowType::value flowType, bool escapeNonAscii); EMITTER_MANIP strFormat,
FlowType::value flowType,
bool WriteSingleQuotedString(ostream_wrapper& out, const std::string& str); bool escapeNonAscii);
bool WriteDoubleQuotedString(ostream_wrapper& out, const std::string& str, bool escapeNonAscii);
bool WriteLiteralString(ostream_wrapper& out, const std::string& str, int indent); bool WriteSingleQuotedString(ostream_wrapper& out, const std::string& str);
bool WriteChar(ostream_wrapper& out, char ch); bool WriteDoubleQuotedString(ostream_wrapper& out, const std::string& str,
bool WriteComment(ostream_wrapper& out, const std::string& str, int postCommentIndent); bool escapeNonAscii);
bool WriteAlias(ostream_wrapper& out, const std::string& str); bool WriteLiteralString(ostream_wrapper& out, const std::string& str,
bool WriteAnchor(ostream_wrapper& out, const std::string& str); int indent);
bool WriteTag(ostream_wrapper& out, const std::string& str, bool verbatim); bool WriteChar(ostream_wrapper& out, char ch);
bool WriteTagWithPrefix(ostream_wrapper& out, const std::string& prefix, const std::string& tag); bool WriteComment(ostream_wrapper& out, const std::string& str,
bool WriteBinary(ostream_wrapper& out, const Binary& binary); int postCommentIndent);
} bool WriteAlias(ostream_wrapper& out, const std::string& str);
bool WriteAnchor(ostream_wrapper& out, const std::string& str);
bool WriteTag(ostream_wrapper& out, const std::string& str, bool verbatim);
bool WriteTagWithPrefix(ostream_wrapper& out, const std::string& prefix,
const std::string& tag);
bool WriteBinary(ostream_wrapper& out, const Binary& binary);
}
} }
#endif // EMITTERUTILS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // EMITTERUTILS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
...@@ -2,112 +2,129 @@ ...@@ -2,112 +2,129 @@
#include "yaml-cpp/exceptions.h" #include "yaml-cpp/exceptions.h"
#include <sstream> #include <sstream>
namespace YAML namespace YAML {
{ namespace Exp {
namespace Exp unsigned ParseHex(const std::string& str, const Mark& mark) {
{ unsigned value = 0;
unsigned ParseHex(const std::string& str, const Mark& mark) for (std::size_t i = 0; i < str.size(); i++) {
{ char ch = str[i];
unsigned value = 0; int digit = 0;
for(std::size_t i=0;i<str.size();i++) { if ('a' <= ch && ch <= 'f')
char ch = str[i]; digit = ch - 'a' + 10;
int digit = 0; else if ('A' <= ch && ch <= 'F')
if('a' <= ch && ch <= 'f') digit = ch - 'A' + 10;
digit = ch - 'a' + 10; else if ('0' <= ch && ch <= '9')
else if('A' <= ch && ch <= 'F') digit = ch - '0';
digit = ch - 'A' + 10; else
else if('0' <= ch && ch <= '9') throw ParserException(mark, ErrorMsg::INVALID_HEX);
digit = ch - '0';
else
throw ParserException(mark, ErrorMsg::INVALID_HEX);
value = (value << 4) + digit; value = (value << 4) + digit;
} }
return value; return value;
} }
std::string Str(unsigned ch) std::string Str(unsigned ch) { return std::string(1, static_cast<char>(ch)); }
{
return std::string(1, static_cast<char>(ch));
}
// Escape // Escape
// . Translates the next 'codeLength' characters into a hex number and returns the result. // . Translates the next 'codeLength' characters into a hex number and returns
// . Throws if it's not actually hex. // the result.
std::string Escape(Stream& in, int codeLength) // . Throws if it's not actually hex.
{ std::string Escape(Stream& in, int codeLength) {
// grab string // grab string
std::string str; std::string str;
for(int i=0;i<codeLength;i++) for (int i = 0; i < codeLength; i++)
str += in.get(); str += in.get();
// get the value // get the value
unsigned value = ParseHex(str, in.mark()); unsigned value = ParseHex(str, in.mark());
// legal unicode? // legal unicode?
if((value >= 0xD800 && value <= 0xDFFF) || value > 0x10FFFF) { if ((value >= 0xD800 && value <= 0xDFFF) || value > 0x10FFFF) {
std::stringstream msg; std::stringstream msg;
msg << ErrorMsg::INVALID_UNICODE << value; msg << ErrorMsg::INVALID_UNICODE << value;
throw ParserException(in.mark(), msg.str()); throw ParserException(in.mark(), msg.str());
} }
// now break it up into chars // now break it up into chars
if(value <= 0x7F) if (value <= 0x7F)
return Str(value); return Str(value);
else if(value <= 0x7FF) else if (value <= 0x7FF)
return Str(0xC0 + (value >> 6)) + Str(0x80 + (value & 0x3F)); return Str(0xC0 + (value >> 6)) + Str(0x80 + (value & 0x3F));
else if(value <= 0xFFFF) else if (value <= 0xFFFF)
return Str(0xE0 + (value >> 12)) + Str(0x80 + ((value >> 6) & 0x3F)) + Str(0x80 + (value & 0x3F)); return Str(0xE0 + (value >> 12)) + Str(0x80 + ((value >> 6) & 0x3F)) +
else Str(0x80 + (value & 0x3F));
return Str(0xF0 + (value >> 18)) + Str(0x80 + ((value >> 12) & 0x3F)) + else
Str(0x80 + ((value >> 6) & 0x3F)) + Str(0x80 + (value & 0x3F)); return Str(0xF0 + (value >> 18)) + Str(0x80 + ((value >> 12) & 0x3F)) +
} Str(0x80 + ((value >> 6) & 0x3F)) + Str(0x80 + (value & 0x3F));
}
// Escape // Escape
// . Escapes the sequence starting 'in' (it must begin with a '\' or single quote) // . Escapes the sequence starting 'in' (it must begin with a '\' or single
// and returns the result. // quote)
// . Throws if it's an unknown escape character. // and returns the result.
std::string Escape(Stream& in) // . Throws if it's an unknown escape character.
{ std::string Escape(Stream& in) {
// eat slash // eat slash
char escape = in.get(); char escape = in.get();
// switch on escape character // switch on escape character
char ch = in.get(); char ch = in.get();
// first do single quote, since it's easier // first do single quote, since it's easier
if(escape == '\'' && ch == '\'') if (escape == '\'' && ch == '\'')
return "\'"; return "\'";
// now do the slash (we're not gonna check if it's a slash - you better pass one!) // now do the slash (we're not gonna check if it's a slash - you better pass
switch(ch) { // one!)
case '0': return std::string(1, '\x00'); switch (ch) {
case 'a': return "\x07"; case '0':
case 'b': return "\x08"; return std::string(1, '\x00');
case 't': case 'a':
case '\t': return "\x09"; return "\x07";
case 'n': return "\x0A"; case 'b':
case 'v': return "\x0B"; return "\x08";
case 'f': return "\x0C"; case 't':
case 'r': return "\x0D"; case '\t':
case 'e': return "\x1B"; return "\x09";
case ' ': return "\x20"; case 'n':
case '\"': return "\""; return "\x0A";
case '\'': return "\'"; case 'v':
case '\\': return "\\"; return "\x0B";
case '/': return "/"; case 'f':
case 'N': return "\x85"; return "\x0C";
case '_': return "\xA0"; case 'r':
case 'L': return "\xE2\x80\xA8"; // LS (#x2028) return "\x0D";
case 'P': return "\xE2\x80\xA9"; // PS (#x2029) case 'e':
case 'x': return Escape(in, 2); return "\x1B";
case 'u': return Escape(in, 4); case ' ':
case 'U': return Escape(in, 8); return "\x20";
} case '\"':
return "\"";
case '\'':
return "\'";
case '\\':
return "\\";
case '/':
return "/";
case 'N':
return "\x85";
case '_':
return "\xA0";
case 'L':
return "\xE2\x80\xA8"; // LS (#x2028)
case 'P':
return "\xE2\x80\xA9"; // PS (#x2029)
case 'x':
return Escape(in, 2);
case 'u':
return Escape(in, 4);
case 'U':
return Escape(in, 8);
}
std::stringstream msg; std::stringstream msg;
throw ParserException(in.mark(), std::string(ErrorMsg::INVALID_ESCAPE) + ch); throw ParserException(in.mark(), std::string(ErrorMsg::INVALID_ESCAPE) + ch);
} }
} }
} }
#ifndef INDENTATION_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef INDENTATION_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define INDENTATION_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define INDENTATION_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
#include "yaml-cpp/ostream_wrapper.h" #include "yaml-cpp/ostream_wrapper.h"
#include <iostream> #include <iostream>
namespace YAML namespace YAML {
{ struct Indentation {
struct Indentation { Indentation(unsigned n_) : n(n_) {}
Indentation(unsigned n_): n(n_) {} unsigned n;
unsigned n; };
};
inline ostream_wrapper& operator << (ostream_wrapper& out, const Indentation& indent) {
for(unsigned i=0;i<indent.n;i++)
out << ' ';
return out;
}
struct IndentTo { inline ostream_wrapper& operator<<(ostream_wrapper& out,
IndentTo(unsigned n_): n(n_) {} const Indentation& indent) {
unsigned n; for (unsigned i = 0; i < indent.n; i++)
}; out << ' ';
return out;
inline ostream_wrapper& operator << (ostream_wrapper& out, const IndentTo& indent) {
while(out.col() < indent.n)
out << ' ';
return out;
}
} }
struct IndentTo {
IndentTo(unsigned n_) : n(n_) {}
unsigned n;
};
inline ostream_wrapper& operator<<(ostream_wrapper& out,
const IndentTo& indent) {
while (out.col() < indent.n)
out << ' ';
return out;
}
}
#endif // INDENTATION_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // INDENTATION_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#include "yaml-cpp/null.h" #include "yaml-cpp/null.h"
namespace YAML namespace YAML {
{ _Null Null;
_Null Null;
} }
...@@ -2,55 +2,47 @@ ...@@ -2,55 +2,47 @@
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
namespace YAML namespace YAML {
{ ostream_wrapper::ostream_wrapper()
ostream_wrapper::ostream_wrapper(): m_pStream(0), m_pos(0), m_row(0), m_col(0), m_comment(false) : m_pStream(0), m_pos(0), m_row(0), m_col(0), m_comment(false) {}
{
} ostream_wrapper::ostream_wrapper(std::ostream& stream)
: m_pStream(&stream), m_pos(0), m_row(0), m_col(0), m_comment(false) {}
ostream_wrapper::ostream_wrapper(std::ostream& stream): m_pStream(&stream), m_pos(0), m_row(0), m_col(0), m_comment(false)
{ ostream_wrapper::~ostream_wrapper() {}
}
void ostream_wrapper::write(const std::string& str) {
ostream_wrapper::~ostream_wrapper() if (m_pStream) {
{ m_pStream->write(str.c_str(), str.size());
} } else {
m_buffer.resize(std::max(m_buffer.size(), m_pos + str.size() + 1));
void ostream_wrapper::write(const std::string& str) std::copy(str.begin(), str.end(), &m_buffer[m_pos]);
{ }
if(m_pStream) {
m_pStream->write(str.c_str(), str.size()); for (std::size_t i = 0; i < str.size(); i++)
} else { update_pos(str[i]);
m_buffer.resize(std::max(m_buffer.size(), m_pos + str.size() + 1)); }
std::copy(str.begin(), str.end(), &m_buffer[m_pos]);
} void ostream_wrapper::write(const char* str, std::size_t size) {
if (m_pStream) {
for(std::size_t i=0;i<str.size();i++) m_pStream->write(str, size);
update_pos(str[i]); } else {
} m_buffer.resize(std::max(m_buffer.size(), m_pos + size + 1));
std::copy(str, str + size, &m_buffer[m_pos]);
void ostream_wrapper::write(const char *str, std::size_t size) }
{
if(m_pStream) { for (std::size_t i = 0; i < size; i++)
m_pStream->write(str, size); update_pos(str[i]);
} else { }
m_buffer.resize(std::max(m_buffer.size(), m_pos + size + 1));
std::copy(str, str + size, &m_buffer[m_pos]); void ostream_wrapper::update_pos(char ch) {
} m_pos++;
m_col++;
for(std::size_t i=0;i<size;i++)
update_pos(str[i]); if (ch == '\n') {
} m_row++;
m_col = 0;
void ostream_wrapper::update_pos(char ch) m_comment = false;
{ }
m_pos++; }
m_col++;
if(ch == '\n') {
m_row++;
m_col = 0;
m_comment = false;
}
}
} }
...@@ -9,133 +9,119 @@ ...@@ -9,133 +9,119 @@
#include <sstream> #include <sstream>
#include <cstdio> #include <cstdio>
namespace YAML namespace YAML {
{ Parser::Parser() {}
Parser::Parser()
{ Parser::Parser(std::istream& in) { Load(in); }
}
Parser::~Parser() {}
Parser::Parser(std::istream& in)
{ Parser::operator bool() const {
Load(in); return m_pScanner.get() && !m_pScanner->empty();
} }
Parser::~Parser() void Parser::Load(std::istream& in) {
{ m_pScanner.reset(new Scanner(in));
} m_pDirectives.reset(new Directives);
}
Parser::operator bool() const
{ // HandleNextDocument
return m_pScanner.get() && !m_pScanner->empty(); // . Handles the next document
} // . Throws a ParserException on error.
// . Returns false if there are no more documents
void Parser::Load(std::istream& in) bool Parser::HandleNextDocument(EventHandler& eventHandler) {
{ if (!m_pScanner.get())
m_pScanner.reset(new Scanner(in)); return false;
m_pDirectives.reset(new Directives);
} ParseDirectives();
if (m_pScanner->empty())
// HandleNextDocument return false;
// . Handles the next document
// . Throws a ParserException on error. SingleDocParser sdp(*m_pScanner, *m_pDirectives);
// . Returns false if there are no more documents sdp.HandleDocument(eventHandler);
bool Parser::HandleNextDocument(EventHandler& eventHandler) return true;
{ }
if(!m_pScanner.get())
return false; // ParseDirectives
// . Reads any directives that are next in the queue.
ParseDirectives(); void Parser::ParseDirectives() {
if(m_pScanner->empty()) bool readDirective = false;
return false;
while (1) {
SingleDocParser sdp(*m_pScanner, *m_pDirectives); if (m_pScanner->empty())
sdp.HandleDocument(eventHandler); break;
return true;
} Token& token = m_pScanner->peek();
if (token.type != Token::DIRECTIVE)
// ParseDirectives break;
// . Reads any directives that are next in the queue.
void Parser::ParseDirectives() // we keep the directives from the last document if none are specified;
{ // but if any directives are specific, then we reset them
bool readDirective = false; if (!readDirective)
m_pDirectives.reset(new Directives);
while(1) {
if(m_pScanner->empty()) readDirective = true;
break; HandleDirective(token);
m_pScanner->pop();
Token& token = m_pScanner->peek(); }
if(token.type != Token::DIRECTIVE) }
break;
void Parser::HandleDirective(const Token& token) {
// we keep the directives from the last document if none are specified; if (token.value == "YAML")
// but if any directives are specific, then we reset them HandleYamlDirective(token);
if(!readDirective) else if (token.value == "TAG")
m_pDirectives.reset(new Directives); HandleTagDirective(token);
}
readDirective = true;
HandleDirective(token); // HandleYamlDirective
m_pScanner->pop(); // . Should be of the form 'major.minor' (like a version number)
} void Parser::HandleYamlDirective(const Token& token) {
} if (token.params.size() != 1)
throw ParserException(token.mark, ErrorMsg::YAML_DIRECTIVE_ARGS);
void Parser::HandleDirective(const Token& token)
{ if (!m_pDirectives->version.isDefault)
if(token.value == "YAML") throw ParserException(token.mark, ErrorMsg::REPEATED_YAML_DIRECTIVE);
HandleYamlDirective(token);
else if(token.value == "TAG") std::stringstream str(token.params[0]);
HandleTagDirective(token); str >> m_pDirectives->version.major;
} str.get();
str >> m_pDirectives->version.minor;
// HandleYamlDirective if (!str || str.peek() != EOF)
// . Should be of the form 'major.minor' (like a version number) throw ParserException(
void Parser::HandleYamlDirective(const Token& token) token.mark, std::string(ErrorMsg::YAML_VERSION) + token.params[0]);
{
if(token.params.size() != 1) if (m_pDirectives->version.major > 1)
throw ParserException(token.mark, ErrorMsg::YAML_DIRECTIVE_ARGS); throw ParserException(token.mark, ErrorMsg::YAML_MAJOR_VERSION);
if(!m_pDirectives->version.isDefault) m_pDirectives->version.isDefault = false;
throw ParserException(token.mark, ErrorMsg::REPEATED_YAML_DIRECTIVE); // TODO: warning on major == 1, minor > 2?
}
std::stringstream str(token.params[0]);
str >> m_pDirectives->version.major; // HandleTagDirective
str.get(); // . Should be of the form 'handle prefix', where 'handle' is converted to
str >> m_pDirectives->version.minor; // 'prefix' in the file.
if(!str || str.peek() != EOF) void Parser::HandleTagDirective(const Token& token) {
throw ParserException(token.mark, std::string(ErrorMsg::YAML_VERSION) + token.params[0]); if (token.params.size() != 2)
throw ParserException(token.mark, ErrorMsg::TAG_DIRECTIVE_ARGS);
if(m_pDirectives->version.major > 1)
throw ParserException(token.mark, ErrorMsg::YAML_MAJOR_VERSION); const std::string& handle = token.params[0];
const std::string& prefix = token.params[1];
m_pDirectives->version.isDefault = false; if (m_pDirectives->tags.find(handle) != m_pDirectives->tags.end())
// TODO: warning on major == 1, minor > 2? throw ParserException(token.mark, ErrorMsg::REPEATED_TAG_DIRECTIVE);
}
m_pDirectives->tags[handle] = prefix;
// HandleTagDirective }
// . Should be of the form 'handle prefix', where 'handle' is converted to 'prefix' in the file.
void Parser::HandleTagDirective(const Token& token) void Parser::PrintTokens(std::ostream& out) {
{ if (!m_pScanner.get())
if(token.params.size() != 2) return;
throw ParserException(token.mark, ErrorMsg::TAG_DIRECTIVE_ARGS);
while (1) {
const std::string& handle = token.params[0]; if (m_pScanner->empty())
const std::string& prefix = token.params[1]; break;
if(m_pDirectives->tags.find(handle) != m_pDirectives->tags.end())
throw ParserException(token.mark, ErrorMsg::REPEATED_TAG_DIRECTIVE); out << m_pScanner->peek() << "\n";
m_pScanner->pop();
m_pDirectives->tags[handle] = prefix; }
} }
void Parser::PrintTokens(std::ostream& out)
{
if(!m_pScanner.get())
return;
while(1) {
if(m_pScanner->empty())
break;
out << m_pScanner->peek() << "\n";
m_pScanner->pop();
}
}
} }
#ifndef PTR_STACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef PTR_STACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define PTR_STACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define PTR_STACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
...@@ -12,38 +14,39 @@ ...@@ -12,38 +14,39 @@
#include <vector> #include <vector>
template <typename T> template <typename T>
class ptr_stack: private YAML::noncopyable class ptr_stack : private YAML::noncopyable {
{ public:
public: ptr_stack() {}
ptr_stack() {} ~ptr_stack() { clear(); }
~ptr_stack() { clear(); }
void clear() {
void clear() { for (unsigned i = 0; i < m_data.size(); i++)
for(unsigned i=0;i<m_data.size();i++) delete m_data[i];
delete m_data[i]; m_data.clear();
m_data.clear(); }
}
std::size_t size() const { return m_data.size(); }
std::size_t size() const { return m_data.size(); } bool empty() const { return m_data.empty(); }
bool empty() const { return m_data.empty(); }
void push(std::auto_ptr<T> t) {
void push(std::auto_ptr<T> t) { m_data.push_back(NULL);
m_data.push_back(NULL); m_data.back() = t.release();
m_data.back() = t.release(); }
} std::auto_ptr<T> pop() {
std::auto_ptr<T> pop() { std::auto_ptr<T> t(m_data.back());
std::auto_ptr<T> t(m_data.back()); m_data.pop_back();
m_data.pop_back(); return t;
return t; }
} T& top() { return *m_data.back(); }
T& top() { return *m_data.back(); } const T& top() const { return *m_data.back(); }
const T& top() const { return *m_data.back(); }
T& top(std::ptrdiff_t diff) { return **(m_data.end() - 1 + diff); }
T& top(std::ptrdiff_t diff) { return **(m_data.end() - 1 + diff); } const T& top(std::ptrdiff_t diff) const {
const T& top(std::ptrdiff_t diff) const { return **(m_data.end() - 1 + diff); } return **(m_data.end() - 1 + diff);
}
private:
std::vector<T*> m_data; private:
std::vector<T*> m_data;
}; };
#endif // PTR_STACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // PTR_STACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#ifndef PTR_VECTOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef PTR_VECTOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define PTR_VECTOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define PTR_VECTOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
...@@ -12,36 +14,35 @@ ...@@ -12,36 +14,35 @@
#include <vector> #include <vector>
namespace YAML { namespace YAML {
template <typename T> template <typename T>
class ptr_vector: private YAML::noncopyable class ptr_vector : private YAML::noncopyable {
{ public:
public: ptr_vector() {}
ptr_vector() {} ~ptr_vector() { clear(); }
~ptr_vector() { clear(); }
void clear() {
void clear() { for (unsigned i = 0; i < m_data.size(); i++)
for(unsigned i=0;i<m_data.size();i++) delete m_data[i];
delete m_data[i]; m_data.clear();
m_data.clear(); }
}
std::size_t size() const { return m_data.size(); }
std::size_t size() const { return m_data.size(); } bool empty() const { return m_data.empty(); }
bool empty() const { return m_data.empty(); }
void push_back(std::auto_ptr<T> t) {
void push_back(std::auto_ptr<T> t) { m_data.push_back(NULL);
m_data.push_back(NULL); m_data.back() = t.release();
m_data.back() = t.release(); }
} T& operator[](std::size_t i) { return *m_data[i]; }
T& operator[](std::size_t i) { return *m_data[i]; } const T& operator[](std::size_t i) const { return *m_data[i]; }
const T& operator[](std::size_t i) const { return *m_data[i]; }
T& back() { return *m_data.back(); }
T& back() { return *m_data.back(); } const T& back() const { return *m_data.back(); }
const T& back() const { return *m_data.back(); }
private:
private: std::vector<T*> m_data;
std::vector<T*> m_data; };
};
} }
#endif // PTR_VECTOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // PTR_VECTOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#include "regex.h" #include "regex.h"
namespace YAML namespace YAML {
{ // constructors
// constructors RegEx::RegEx() : m_op(REGEX_EMPTY) {}
RegEx::RegEx(): m_op(REGEX_EMPTY)
{ RegEx::RegEx(REGEX_OP op) : m_op(op) {}
}
RegEx::RegEx(char ch) : m_op(REGEX_MATCH), m_a(ch) {}
RegEx::RegEx(REGEX_OP op): m_op(op)
{ RegEx::RegEx(char a, char z) : m_op(REGEX_RANGE), m_a(a), m_z(z) {}
}
RegEx::RegEx(const std::string& str, REGEX_OP op) : m_op(op) {
RegEx::RegEx(char ch): m_op(REGEX_MATCH), m_a(ch) for (std::size_t i = 0; i < str.size(); i++)
{ m_params.push_back(RegEx(str[i]));
} }
RegEx::RegEx(char a, char z): m_op(REGEX_RANGE), m_a(a), m_z(z) // combination constructors
{ RegEx operator!(const RegEx & ex) {
} RegEx ret(REGEX_NOT);
ret.m_params.push_back(ex);
RegEx::RegEx(const std::string& str, REGEX_OP op): m_op(op) return ret;
{
for(std::size_t i=0;i<str.size();i++)
m_params.push_back(RegEx(str[i]));
}
// combination constructors
RegEx operator ! (const RegEx& ex)
{
RegEx ret(REGEX_NOT);
ret.m_params.push_back(ex);
return ret;
}
RegEx operator || (const RegEx& ex1, const RegEx& ex2)
{
RegEx ret(REGEX_OR);
ret.m_params.push_back(ex1);
ret.m_params.push_back(ex2);
return ret;
}
RegEx operator && (const RegEx& ex1, const RegEx& ex2)
{
RegEx ret(REGEX_AND);
ret.m_params.push_back(ex1);
ret.m_params.push_back(ex2);
return ret;
}
RegEx operator + (const RegEx& ex1, const RegEx& ex2)
{
RegEx ret(REGEX_SEQ);
ret.m_params.push_back(ex1);
ret.m_params.push_back(ex2);
return ret;
}
} }
RegEx operator||(const RegEx& ex1, const RegEx& ex2) {
RegEx ret(REGEX_OR);
ret.m_params.push_back(ex1);
ret.m_params.push_back(ex2);
return ret;
}
RegEx operator&&(const RegEx& ex1, const RegEx& ex2) {
RegEx ret(REGEX_AND);
ret.m_params.push_back(ex1);
ret.m_params.push_back(ex2);
return ret;
}
RegEx operator+(const RegEx& ex1, const RegEx& ex2) {
RegEx ret(REGEX_SEQ);
ret.m_params.push_back(ex1);
ret.m_params.push_back(ex2);
return ret;
}
}
#ifndef REGEX_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef REGEX_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define REGEX_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define REGEX_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
#include <vector> #include <vector>
#include <string> #include <string>
namespace YAML namespace YAML {
{ class Stream;
class Stream;
enum REGEX_OP {
REGEX_EMPTY,
REGEX_MATCH,
REGEX_RANGE,
REGEX_OR,
REGEX_AND,
REGEX_NOT,
REGEX_SEQ
};
// simplified regular expressions
// . Only straightforward matches (no repeated characters)
// . Only matches from start of string
class RegEx {
public:
RegEx();
RegEx(char ch);
RegEx(char a, char z);
RegEx(const std::string& str, REGEX_OP op = REGEX_SEQ);
~RegEx() {}
enum REGEX_OP { REGEX_EMPTY, REGEX_MATCH, REGEX_RANGE, REGEX_OR, REGEX_AND, REGEX_NOT, REGEX_SEQ }; friend RegEx operator!(const RegEx & ex);
friend RegEx operator||(const RegEx& ex1, const RegEx& ex2);
friend RegEx operator&&(const RegEx& ex1, const RegEx& ex2);
friend RegEx operator+(const RegEx& ex1, const RegEx& ex2);
// simplified regular expressions bool Matches(char ch) const;
// . Only straightforward matches (no repeated characters) bool Matches(const std::string& str) const;
// . Only matches from start of string bool Matches(const Stream& in) const;
class RegEx template <typename Source>
{ bool Matches(const Source& source) const;
public:
RegEx();
RegEx(char ch);
RegEx(char a, char z);
RegEx(const std::string& str, REGEX_OP op = REGEX_SEQ);
~RegEx() {}
friend RegEx operator ! (const RegEx& ex); int Match(const std::string& str) const;
friend RegEx operator || (const RegEx& ex1, const RegEx& ex2); int Match(const Stream& in) const;
friend RegEx operator && (const RegEx& ex1, const RegEx& ex2); template <typename Source>
friend RegEx operator + (const RegEx& ex1, const RegEx& ex2); int Match(const Source& source) const;
bool Matches(char ch) const;
bool Matches(const std::string& str) const;
bool Matches(const Stream& in) const;
template <typename Source> bool Matches(const Source& source) const;
int Match(const std::string& str) const; private:
int Match(const Stream& in) const; RegEx(REGEX_OP op);
template <typename Source> int Match(const Source& source) const;
private: template <typename Source>
RegEx(REGEX_OP op); bool IsValidSource(const Source& source) const;
template <typename Source>
template <typename Source> bool IsValidSource(const Source& source) const; int MatchUnchecked(const Source& source) const;
template <typename Source> int MatchUnchecked(const Source& source) const;
template <typename Source> int MatchOpEmpty(const Source& source) const; template <typename Source>
template <typename Source> int MatchOpMatch(const Source& source) const; int MatchOpEmpty(const Source& source) const;
template <typename Source> int MatchOpRange(const Source& source) const; template <typename Source>
template <typename Source> int MatchOpOr(const Source& source) const; int MatchOpMatch(const Source& source) const;
template <typename Source> int MatchOpAnd(const Source& source) const; template <typename Source>
template <typename Source> int MatchOpNot(const Source& source) const; int MatchOpRange(const Source& source) const;
template <typename Source> int MatchOpSeq(const Source& source) const; template <typename Source>
int MatchOpOr(const Source& source) const;
template <typename Source>
int MatchOpAnd(const Source& source) const;
template <typename Source>
int MatchOpNot(const Source& source) const;
template <typename Source>
int MatchOpSeq(const Source& source) const;
private: private:
REGEX_OP m_op; REGEX_OP m_op;
char m_a, m_z; char m_a, m_z;
std::vector <RegEx> m_params; std::vector<RegEx> m_params;
}; };
} }
#include "regeximpl.h" #include "regeximpl.h"
#endif // REGEX_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // REGEX_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#ifndef REGEXIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef REGEXIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define REGEXIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define REGEXIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
#include "stream.h" #include "stream.h"
#include "stringsource.h" #include "stringsource.h"
#include "streamcharsource.h" #include "streamcharsource.h"
namespace YAML namespace YAML {
{ // query matches
// query matches inline bool RegEx::Matches(char ch) const {
inline bool RegEx::Matches(char ch) const { std::string str;
std::string str; str += ch;
str += ch; return Matches(str);
return Matches(str); }
}
inline bool RegEx::Matches(const std::string& str) const {
inline bool RegEx::Matches(const std::string& str) const { return Match(str) >= 0;
return Match(str) >= 0; }
}
inline bool RegEx::Matches(const Stream& in) const { return Match(in) >= 0; }
inline bool RegEx::Matches(const Stream& in) const {
return Match(in) >= 0; template <typename Source>
} inline bool RegEx::Matches(const Source& source) const {
return Match(source) >= 0;
template <typename Source> }
inline bool RegEx::Matches(const Source& source) const {
return Match(source) >= 0; // Match
} // . Matches the given string against this regular expression.
// . Returns the number of characters matched.
// Match // . Returns -1 if no characters were matched (the reason for
// . Matches the given string against this regular expression. // not returning zero is that we may have an empty regex
// . Returns the number of characters matched. // which is ALWAYS successful at matching zero characters).
// . Returns -1 if no characters were matched (the reason for // . REMEMBER that we only match from the start of the buffer!
// not returning zero is that we may have an empty regex inline int RegEx::Match(const std::string& str) const {
// which is ALWAYS successful at matching zero characters). StringCharSource source(str.c_str(), str.size());
// . REMEMBER that we only match from the start of the buffer! return Match(source);
inline int RegEx::Match(const std::string& str) const }
{
StringCharSource source(str.c_str(), str.size()); inline int RegEx::Match(const Stream& in) const {
return Match(source); StreamCharSource source(in);
} return Match(source);
}
inline int RegEx::Match(const Stream& in) const
{ template <typename Source>
StreamCharSource source(in); inline bool RegEx::IsValidSource(const Source& source) const {
return Match(source); return source;
} }
template <typename Source> template <>
inline bool RegEx::IsValidSource(const Source& source) const inline bool RegEx::IsValidSource<StringCharSource>(
{ const StringCharSource& source) const {
return source; switch (m_op) {
} case REGEX_MATCH:
case REGEX_RANGE:
template<> return source;
inline bool RegEx::IsValidSource<StringCharSource>(const StringCharSource&source) const default:
{ return true;
switch(m_op) { }
case REGEX_MATCH: }
case REGEX_RANGE:
return source; template <typename Source>
default: inline int RegEx::Match(const Source& source) const {
return true; return IsValidSource(source) ? MatchUnchecked(source) : -1;
} }
}
template <typename Source>
template <typename Source> inline int RegEx::MatchUnchecked(const Source& source) const {
inline int RegEx::Match(const Source& source) const switch (m_op) {
{ case REGEX_EMPTY:
return IsValidSource(source) ? MatchUnchecked(source) : -1; return MatchOpEmpty(source);
} case REGEX_MATCH:
return MatchOpMatch(source);
template <typename Source> case REGEX_RANGE:
inline int RegEx::MatchUnchecked(const Source& source) const return MatchOpRange(source);
{ case REGEX_OR:
switch(m_op) { return MatchOpOr(source);
case REGEX_EMPTY: case REGEX_AND:
return MatchOpEmpty(source); return MatchOpAnd(source);
case REGEX_MATCH: case REGEX_NOT:
return MatchOpMatch(source); return MatchOpNot(source);
case REGEX_RANGE: case REGEX_SEQ:
return MatchOpRange(source); return MatchOpSeq(source);
case REGEX_OR: }
return MatchOpOr(source);
case REGEX_AND: return -1;
return MatchOpAnd(source); }
case REGEX_NOT:
return MatchOpNot(source); //////////////////////////////////////////////////////////////////////////////
case REGEX_SEQ: // Operators
return MatchOpSeq(source); // Note: the convention MatchOp*<Source> is that we can assume
} // IsSourceValid(source).
// So we do all our checks *before* we call these functions
return -1;
} // EmptyOperator
template <typename Source>
////////////////////////////////////////////////////////////////////////////// inline int RegEx::MatchOpEmpty(const Source& source) const {
// Operators return source[0] == Stream::eof() ? 0 : -1;
// Note: the convention MatchOp*<Source> is that we can assume IsSourceValid(source). }
// So we do all our checks *before* we call these functions
template <>
// EmptyOperator inline int RegEx::MatchOpEmpty<StringCharSource>(const StringCharSource& source)
template <typename Source> const {
inline int RegEx::MatchOpEmpty(const Source& source) const { return !source
return source[0] == Stream::eof() ? 0 : -1; ? 0
} : -1; // the empty regex only is successful on the empty string
}
template <>
inline int RegEx::MatchOpEmpty<StringCharSource>(const StringCharSource& source) const { // MatchOperator
return !source ? 0 : -1; // the empty regex only is successful on the empty string template <typename Source>
} inline int RegEx::MatchOpMatch(const Source& source) const {
if (source[0] != m_a)
// MatchOperator return -1;
template <typename Source> return 1;
inline int RegEx::MatchOpMatch(const Source& source) const { }
if(source[0] != m_a)
return -1; // RangeOperator
return 1; template <typename Source>
} inline int RegEx::MatchOpRange(const Source& source) const {
if (m_a > source[0] || m_z < source[0])
// RangeOperator return -1;
template <typename Source> return 1;
inline int RegEx::MatchOpRange(const Source& source) const { }
if(m_a > source[0] || m_z < source[0])
return -1; // OrOperator
return 1; template <typename Source>
} inline int RegEx::MatchOpOr(const Source& source) const {
for (std::size_t i = 0; i < m_params.size(); i++) {
// OrOperator int n = m_params[i].MatchUnchecked(source);
template <typename Source> if (n >= 0)
inline int RegEx::MatchOpOr(const Source& source) const { return n;
for(std::size_t i=0;i<m_params.size();i++) { }
int n = m_params[i].MatchUnchecked(source); return -1;
if(n >= 0) }
return n;
} // AndOperator
return -1; // Note: 'AND' is a little funny, since we may be required to match things
} // of different lengths. If we find a match, we return the length of
// the FIRST entry on the list.
// AndOperator template <typename Source>
// Note: 'AND' is a little funny, since we may be required to match things inline int RegEx::MatchOpAnd(const Source& source) const {
// of different lengths. If we find a match, we return the length of int first = -1;
// the FIRST entry on the list. for (std::size_t i = 0; i < m_params.size(); i++) {
template <typename Source> int n = m_params[i].MatchUnchecked(source);
inline int RegEx::MatchOpAnd(const Source& source) const { if (n == -1)
int first = -1; return -1;
for(std::size_t i=0;i<m_params.size();i++) { if (i == 0)
int n = m_params[i].MatchUnchecked(source); first = n;
if(n == -1) }
return -1; return first;
if(i == 0) }
first = n;
} // NotOperator
return first; template <typename Source>
} inline int RegEx::MatchOpNot(const Source& source) const {
if (m_params.empty())
// NotOperator return -1;
template <typename Source> if (m_params[0].MatchUnchecked(source) >= 0)
inline int RegEx::MatchOpNot(const Source& source) const { return -1;
if(m_params.empty()) return 1;
return -1; }
if(m_params[0].MatchUnchecked(source) >= 0)
return -1; // SeqOperator
return 1; template <typename Source>
} inline int RegEx::MatchOpSeq(const Source& source) const {
int offset = 0;
// SeqOperator for (std::size_t i = 0; i < m_params.size(); i++) {
template <typename Source> int n = m_params[i].Match(source + offset); // note Match, not
inline int RegEx::MatchOpSeq(const Source& source) const { // MatchUnchecked because we
int offset = 0; // need to check validity after
for(std::size_t i=0;i<m_params.size();i++) { // the offset
int n = m_params[i].Match(source + offset); // note Match, not MatchUnchecked because we need to check validity after the offset if (n == -1)
if(n == -1) return -1;
return -1; offset += n;
offset += n; }
}
return offset;
return offset; }
} }
}
#endif // REGEXIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#endif // REGEXIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#ifndef SCANNER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef SCANNER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define SCANNER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define SCANNER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
#include <ios> #include <ios>
#include <string> #include <string>
#include <queue> #include <queue>
...@@ -16,118 +17,127 @@ ...@@ -16,118 +17,127 @@
#include "stream.h" #include "stream.h"
#include "token.h" #include "token.h"
namespace YAML namespace YAML {
{ class Node;
class Node; class RegEx;
class RegEx;
class Scanner {
class Scanner public:
{ Scanner(std::istream &in);
public: ~Scanner();
Scanner(std::istream& in);
~Scanner(); // token queue management (hopefully this looks kinda stl-ish)
bool empty();
// token queue management (hopefully this looks kinda stl-ish) void pop();
bool empty(); Token &peek();
void pop(); Mark mark() const;
Token& peek();
Mark mark() const; private:
struct IndentMarker {
private: enum INDENT_TYPE {
struct IndentMarker { MAP,
enum INDENT_TYPE { MAP, SEQ, NONE }; SEQ,
enum STATUS { VALID, INVALID, UNKNOWN }; NONE
IndentMarker(int column_, INDENT_TYPE type_): column(column_), type(type_), status(VALID), pStartToken(0) {} };
enum STATUS {
int column; VALID,
INDENT_TYPE type; INVALID,
STATUS status; UNKNOWN
Token *pStartToken; };
}; IndentMarker(int column_, INDENT_TYPE type_)
: column(column_), type(type_), status(VALID), pStartToken(0) {}
enum FLOW_MARKER { FLOW_MAP, FLOW_SEQ };
int column;
private: INDENT_TYPE type;
// scanning STATUS status;
void EnsureTokensInQueue(); Token *pStartToken;
void ScanNextToken(); };
void ScanToNextToken();
void StartStream(); enum FLOW_MARKER {
void EndStream(); FLOW_MAP,
Token *PushToken(Token::TYPE type); FLOW_SEQ
};
bool InFlowContext() const { return !m_flows.empty(); }
bool InBlockContext() const { return m_flows.empty(); } private:
int GetFlowLevel() const { return m_flows.size(); } // scanning
void EnsureTokensInQueue();
Token::TYPE GetStartTokenFor(IndentMarker::INDENT_TYPE type) const; void ScanNextToken();
IndentMarker *PushIndentTo(int column, IndentMarker::INDENT_TYPE type); void ScanToNextToken();
void PopIndentToHere(); void StartStream();
void PopAllIndents(); void EndStream();
void PopIndent(); Token *PushToken(Token::TYPE type);
int GetTopIndent() const;
bool InFlowContext() const { return !m_flows.empty(); }
// checking input bool InBlockContext() const { return m_flows.empty(); }
bool CanInsertPotentialSimpleKey() const; int GetFlowLevel() const { return m_flows.size(); }
bool ExistsActiveSimpleKey() const;
void InsertPotentialSimpleKey(); Token::TYPE GetStartTokenFor(IndentMarker::INDENT_TYPE type) const;
void InvalidateSimpleKey(); IndentMarker *PushIndentTo(int column, IndentMarker::INDENT_TYPE type);
bool VerifySimpleKey(); void PopIndentToHere();
void PopAllSimpleKeys(); void PopAllIndents();
void PopIndent();
void ThrowParserException(const std::string& msg) const; int GetTopIndent() const;
bool IsWhitespaceToBeEaten(char ch); // checking input
const RegEx& GetValueRegex() const; bool CanInsertPotentialSimpleKey() const;
bool ExistsActiveSimpleKey() const;
struct SimpleKey { void InsertPotentialSimpleKey();
SimpleKey(const Mark& mark_, int flowLevel_); void InvalidateSimpleKey();
bool VerifySimpleKey();
void Validate(); void PopAllSimpleKeys();
void Invalidate();
void ThrowParserException(const std::string &msg) const;
Mark mark;
int flowLevel; bool IsWhitespaceToBeEaten(char ch);
IndentMarker *pIndent; const RegEx &GetValueRegex() const;
Token *pMapStart, *pKey;
}; struct SimpleKey {
SimpleKey(const Mark &mark_, int flowLevel_);
// and the tokens
void ScanDirective(); void Validate();
void ScanDocStart(); void Invalidate();
void ScanDocEnd();
void ScanBlockSeqStart(); Mark mark;
void ScanBlockMapSTart(); int flowLevel;
void ScanBlockEnd(); IndentMarker *pIndent;
void ScanBlockEntry(); Token *pMapStart, *pKey;
void ScanFlowStart(); };
void ScanFlowEnd();
void ScanFlowEntry(); // and the tokens
void ScanKey(); void ScanDirective();
void ScanValue(); void ScanDocStart();
void ScanAnchorOrAlias(); void ScanDocEnd();
void ScanTag(); void ScanBlockSeqStart();
void ScanPlainScalar(); void ScanBlockMapSTart();
void ScanQuotedScalar(); void ScanBlockEnd();
void ScanBlockScalar(); void ScanBlockEntry();
void ScanFlowStart();
private: void ScanFlowEnd();
// the stream void ScanFlowEntry();
Stream INPUT; void ScanKey();
void ScanValue();
// the output (tokens) void ScanAnchorOrAlias();
std::queue<Token> m_tokens; void ScanTag();
void ScanPlainScalar();
// state info void ScanQuotedScalar();
bool m_startedStream, m_endedStream; void ScanBlockScalar();
bool m_simpleKeyAllowed;
bool m_canBeJSONFlow; private:
std::stack<SimpleKey> m_simpleKeys; // the stream
std::stack<IndentMarker *> m_indents; Stream INPUT;
ptr_vector<IndentMarker> m_indentRefs; // for "garbage collection"
std::stack<FLOW_MARKER> m_flows; // the output (tokens)
}; std::queue<Token> m_tokens;
// state info
bool m_startedStream, m_endedStream;
bool m_simpleKeyAllowed;
bool m_canBeJSONFlow;
std::stack<SimpleKey> m_simpleKeys;
std::stack<IndentMarker *> m_indents;
ptr_vector<IndentMarker> m_indentRefs; // for "garbage collection"
std::stack<FLOW_MARKER> m_flows;
};
} }
#endif // SCANNER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // SCANNER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#ifndef SCANSCALAR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef SCANSCALAR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define SCANSCALAR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define SCANSCALAR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
#include <string> #include <string>
#include "regex.h" #include "regex.h"
#include "stream.h" #include "stream.h"
namespace YAML namespace YAML {
{ enum CHOMP {
enum CHOMP { STRIP = -1, CLIP, KEEP }; STRIP = -1,
enum ACTION { NONE, BREAK, THROW }; CLIP,
enum FOLD { DONT_FOLD, FOLD_BLOCK, FOLD_FLOW }; KEEP
};
struct ScanScalarParams { enum ACTION {
ScanScalarParams(): eatEnd(false), indent(0), detectIndent(false), eatLeadingWhitespace(0), escape(0), fold(DONT_FOLD), NONE,
trimTrailingSpaces(0), chomp(CLIP), onDocIndicator(NONE), onTabInIndentation(NONE), leadingSpaces(false) {} BREAK,
THROW
// input: };
RegEx end; // what condition ends this scalar? enum FOLD {
bool eatEnd; // should we eat that condition when we see it? DONT_FOLD,
int indent; // what level of indentation should be eaten and ignored? FOLD_BLOCK,
bool detectIndent; // should we try to autodetect the indent? FOLD_FLOW
bool eatLeadingWhitespace; // should we continue eating this delicious indentation after 'indent' spaces? };
char escape; // what character do we escape on (i.e., slash or single quote) (0 for none)
FOLD fold; // how do we fold line ends? struct ScanScalarParams {
bool trimTrailingSpaces; // do we remove all trailing spaces (at the very end) ScanScalarParams()
CHOMP chomp; // do we strip, clip, or keep trailing newlines (at the very end) : eatEnd(false),
// Note: strip means kill all, clip means keep at most one, keep means keep all indent(0),
ACTION onDocIndicator; // what do we do if we see a document indicator? detectIndent(false),
ACTION onTabInIndentation; // what do we do if we see a tab where we should be seeing indentation spaces eatLeadingWhitespace(0),
escape(0),
// output: fold(DONT_FOLD),
bool leadingSpaces; trimTrailingSpaces(0),
}; chomp(CLIP),
onDocIndicator(NONE),
std::string ScanScalar(Stream& INPUT, ScanScalarParams& info); onTabInIndentation(NONE),
} leadingSpaces(false) {}
#endif // SCANSCALAR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 // input:
RegEx end; // what condition ends this scalar?
bool eatEnd; // should we eat that condition when we see it?
int indent; // what level of indentation should be eaten and ignored?
bool detectIndent; // should we try to autodetect the indent?
bool eatLeadingWhitespace; // should we continue eating this delicious
// indentation after 'indent' spaces?
char escape; // what character do we escape on (i.e., slash or single quote)
// (0 for none)
FOLD fold; // how do we fold line ends?
bool trimTrailingSpaces; // do we remove all trailing spaces (at the very
// end)
CHOMP chomp; // do we strip, clip, or keep trailing newlines (at the very
// end)
// Note: strip means kill all, clip means keep at most one, keep means keep
// all
ACTION onDocIndicator; // what do we do if we see a document indicator?
ACTION onTabInIndentation; // what do we do if we see a tab where we should
// be seeing indentation spaces
// output:
bool leadingSpaces;
};
std::string ScanScalar(Stream& INPUT, ScanScalarParams& info);
}
#endif // SCANSCALAR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
...@@ -3,82 +3,77 @@ ...@@ -3,82 +3,77 @@
#include "exp.h" #include "exp.h"
#include "yaml-cpp/exceptions.h" #include "yaml-cpp/exceptions.h"
namespace YAML namespace YAML {
{ const std::string ScanVerbatimTag(Stream& INPUT) {
const std::string ScanVerbatimTag(Stream& INPUT) std::string tag;
{
std::string tag; // eat the start character
INPUT.get();
// eat the start character
INPUT.get(); while (INPUT) {
if (INPUT.peek() == Keys::VerbatimTagEnd) {
while(INPUT) { // eat the end character
if(INPUT.peek() == Keys::VerbatimTagEnd) { INPUT.get();
// eat the end character return tag;
INPUT.get(); }
return tag;
} int n = Exp::URI().Match(INPUT);
if (n <= 0)
int n = Exp::URI().Match(INPUT); break;
if(n <= 0)
break; tag += INPUT.get(n);
}
tag += INPUT.get(n);
} throw ParserException(INPUT.mark(), ErrorMsg::END_OF_VERBATIM_TAG);
throw ParserException(INPUT.mark(), ErrorMsg::END_OF_VERBATIM_TAG);
}
const std::string ScanTagHandle(Stream& INPUT, bool& canBeHandle)
{
std::string tag;
canBeHandle = true;
Mark firstNonWordChar;
while(INPUT) {
if(INPUT.peek() == Keys::Tag) {
if(!canBeHandle)
throw ParserException(firstNonWordChar, ErrorMsg::CHAR_IN_TAG_HANDLE);
break;
}
int n = 0;
if(canBeHandle) {
n = Exp::Word().Match(INPUT);
if(n <= 0) {
canBeHandle = false;
firstNonWordChar = INPUT.mark();
}
}
if(!canBeHandle)
n = Exp::Tag().Match(INPUT);
if(n <= 0)
break;
tag += INPUT.get(n);
}
return tag;
}
const std::string ScanTagSuffix(Stream& INPUT)
{
std::string tag;
while(INPUT) {
int n = Exp::Tag().Match(INPUT);
if(n <= 0)
break;
tag += INPUT.get(n);
}
if(tag.empty())
throw ParserException(INPUT.mark(), ErrorMsg::TAG_WITH_NO_SUFFIX);
return tag;
}
} }
const std::string ScanTagHandle(Stream& INPUT, bool& canBeHandle) {
std::string tag;
canBeHandle = true;
Mark firstNonWordChar;
while (INPUT) {
if (INPUT.peek() == Keys::Tag) {
if (!canBeHandle)
throw ParserException(firstNonWordChar, ErrorMsg::CHAR_IN_TAG_HANDLE);
break;
}
int n = 0;
if (canBeHandle) {
n = Exp::Word().Match(INPUT);
if (n <= 0) {
canBeHandle = false;
firstNonWordChar = INPUT.mark();
}
}
if (!canBeHandle)
n = Exp::Tag().Match(INPUT);
if (n <= 0)
break;
tag += INPUT.get(n);
}
return tag;
}
const std::string ScanTagSuffix(Stream& INPUT) {
std::string tag;
while (INPUT) {
int n = Exp::Tag().Match(INPUT);
if (n <= 0)
break;
tag += INPUT.get(n);
}
if (tag.empty())
throw ParserException(INPUT.mark(), ErrorMsg::TAG_WITH_NO_SUFFIX);
return tag;
}
}
#ifndef SCANTAG_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef SCANTAG_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define SCANTAG_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define SCANTAG_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
#include <string> #include <string>
#include "stream.h" #include "stream.h"
namespace YAML namespace YAML {
{ const std::string ScanVerbatimTag(Stream& INPUT);
const std::string ScanVerbatimTag(Stream& INPUT); const std::string ScanTagHandle(Stream& INPUT, bool& canBeHandle);
const std::string ScanTagHandle(Stream& INPUT, bool& canBeHandle); const std::string ScanTagSuffix(Stream& INPUT);
const std::string ScanTagSuffix(Stream& INPUT);
} }
#endif // SCANTAG_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // SCANTAG_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#ifndef SETTING_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef SETTING_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define SETTING_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define SETTING_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "yaml-cpp/noncopyable.h" #include "yaml-cpp/noncopyable.h"
namespace YAML namespace YAML {
{ class SettingChangeBase;
class SettingChangeBase;
template <typename T>
template <typename T> class Setting {
class Setting public:
{ Setting() : m_value() {}
public:
Setting(): m_value() {} const T get() const { return m_value; }
std::auto_ptr<SettingChangeBase> set(const T& value);
const T get() const { return m_value; } void restore(const Setting<T>& oldSetting) { m_value = oldSetting.get(); }
std::auto_ptr <SettingChangeBase> set(const T& value);
void restore(const Setting<T>& oldSetting) { private:
m_value = oldSetting.get(); T m_value;
} };
private: class SettingChangeBase {
T m_value; public:
}; virtual ~SettingChangeBase() {}
virtual void pop() = 0;
class SettingChangeBase };
{
public: template <typename T>
virtual ~SettingChangeBase() {} class SettingChange : public SettingChangeBase {
virtual void pop() = 0; public:
}; SettingChange(Setting<T>* pSetting) : m_pCurSetting(pSetting) {
// copy old setting to save its state
template <typename T> m_oldSetting = *pSetting;
class SettingChange: public SettingChangeBase }
{
public: virtual void pop() { m_pCurSetting->restore(m_oldSetting); }
SettingChange(Setting<T> *pSetting): m_pCurSetting(pSetting) {
// copy old setting to save its state private:
m_oldSetting = *pSetting; Setting<T>* m_pCurSetting;
} Setting<T> m_oldSetting;
};
virtual void pop() {
m_pCurSetting->restore(m_oldSetting); template <typename T>
} inline std::auto_ptr<SettingChangeBase> Setting<T>::set(const T& value) {
std::auto_ptr<SettingChangeBase> pChange(new SettingChange<T>(this));
private: m_value = value;
Setting<T> *m_pCurSetting; return pChange;
Setting<T> m_oldSetting; }
};
class SettingChanges : private noncopyable {
template <typename T> public:
inline std::auto_ptr <SettingChangeBase> Setting<T>::set(const T& value) { SettingChanges() {}
std::auto_ptr <SettingChangeBase> pChange(new SettingChange<T> (this)); ~SettingChanges() { clear(); }
m_value = value;
return pChange; void clear() {
} restore();
class SettingChanges: private noncopyable for (setting_changes::const_iterator it = m_settingChanges.begin();
{ it != m_settingChanges.end(); ++it)
public: delete *it;
SettingChanges() {} m_settingChanges.clear();
~SettingChanges() { clear(); } }
void clear() { void restore() {
restore(); for (setting_changes::const_iterator it = m_settingChanges.begin();
it != m_settingChanges.end(); ++it)
for(setting_changes::const_iterator it=m_settingChanges.begin();it!=m_settingChanges.end();++it) (*it)->pop();
delete *it; }
m_settingChanges.clear();
} void push(std::auto_ptr<SettingChangeBase> pSettingChange) {
m_settingChanges.push_back(pSettingChange.release());
void restore() { }
for(setting_changes::const_iterator it=m_settingChanges.begin();it!=m_settingChanges.end();++it)
(*it)->pop(); // like std::auto_ptr - assignment is transfer of ownership
} SettingChanges& operator=(SettingChanges& rhs) {
if (this == &rhs)
void push(std::auto_ptr <SettingChangeBase> pSettingChange) { return *this;
m_settingChanges.push_back(pSettingChange.release());
} clear();
m_settingChanges = rhs.m_settingChanges;
// like std::auto_ptr - assignment is transfer of ownership rhs.m_settingChanges.clear();
SettingChanges& operator = (SettingChanges& rhs) { return *this;
if(this == &rhs) }
return *this;
private:
clear(); typedef std::vector<SettingChangeBase*> setting_changes;
m_settingChanges = rhs.m_settingChanges; setting_changes m_settingChanges;
rhs.m_settingChanges.clear(); };
return *this;
}
private:
typedef std::vector <SettingChangeBase *> setting_changes;
setting_changes m_settingChanges;
};
} }
#endif // SETTING_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // SETTING_H_62B23520_7C8E_11DE_8A39_0800200C9A66
...@@ -3,137 +3,126 @@ ...@@ -3,137 +3,126 @@
#include "yaml-cpp/exceptions.h" #include "yaml-cpp/exceptions.h"
#include "exp.h" #include "exp.h"
namespace YAML namespace YAML {
{ Scanner::SimpleKey::SimpleKey(const Mark& mark_, int flowLevel_)
Scanner::SimpleKey::SimpleKey(const Mark& mark_, int flowLevel_) : mark(mark_), flowLevel(flowLevel_), pIndent(0), pMapStart(0), pKey(0) {}
: mark(mark_), flowLevel(flowLevel_), pIndent(0), pMapStart(0), pKey(0)
{ void Scanner::SimpleKey::Validate() {
} // Note: pIndent will *not* be garbage here;
// we "garbage collect" them so we can
void Scanner::SimpleKey::Validate() // always refer to them
{ if (pIndent)
// Note: pIndent will *not* be garbage here; pIndent->status = IndentMarker::VALID;
// we "garbage collect" them so we can if (pMapStart)
// always refer to them pMapStart->status = Token::VALID;
if(pIndent) if (pKey)
pIndent->status = IndentMarker::VALID; pKey->status = Token::VALID;
if(pMapStart)
pMapStart->status = Token::VALID;
if(pKey)
pKey->status = Token::VALID;
}
void Scanner::SimpleKey::Invalidate()
{
if(pIndent)
pIndent->status = IndentMarker::INVALID;
if(pMapStart)
pMapStart->status = Token::INVALID;
if(pKey)
pKey->status = Token::INVALID;
}
// CanInsertPotentialSimpleKey
bool Scanner::CanInsertPotentialSimpleKey() const
{
if(!m_simpleKeyAllowed)
return false;
return !ExistsActiveSimpleKey();
}
// ExistsActiveSimpleKey
// . Returns true if there's a potential simple key at our flow level
// (there's allowed at most one per flow level, i.e., at the start of the flow start token)
bool Scanner::ExistsActiveSimpleKey() const
{
if(m_simpleKeys.empty())
return false;
const SimpleKey& key = m_simpleKeys.top();
return key.flowLevel == GetFlowLevel();
}
// InsertPotentialSimpleKey
// . If we can, add a potential simple key to the queue,
// and save it on a stack.
void Scanner::InsertPotentialSimpleKey()
{
if(!CanInsertPotentialSimpleKey())
return;
SimpleKey key(INPUT.mark(), GetFlowLevel());
// first add a map start, if necessary
if(InBlockContext()) {
key.pIndent = PushIndentTo(INPUT.column(), IndentMarker::MAP);
if(key.pIndent) {
key.pIndent->status = IndentMarker::UNKNOWN;
key.pMapStart = key.pIndent->pStartToken;
key.pMapStart->status = Token::UNVERIFIED;
}
}
// then add the (now unverified) key
m_tokens.push(Token(Token::KEY, INPUT.mark()));
key.pKey = &m_tokens.back();
key.pKey->status = Token::UNVERIFIED;
m_simpleKeys.push(key);
}
// InvalidateSimpleKey
// . Automatically invalidate the simple key in our flow level
void Scanner::InvalidateSimpleKey()
{
if(m_simpleKeys.empty())
return;
// grab top key
SimpleKey& key = m_simpleKeys.top();
if(key.flowLevel != GetFlowLevel())
return;
key.Invalidate();
m_simpleKeys.pop();
}
// VerifySimpleKey
// . Determines whether the latest simple key to be added is valid,
// and if so, makes it valid.
bool Scanner::VerifySimpleKey()
{
if(m_simpleKeys.empty())
return false;
// grab top key
SimpleKey key = m_simpleKeys.top();
// only validate if we're in the correct flow level
if(key.flowLevel != GetFlowLevel())
return false;
m_simpleKeys.pop();
bool isValid = true;
// needs to be less than 1024 characters and inline
if(INPUT.line() != key.mark.line || INPUT.pos() - key.mark.pos > 1024)
isValid = false;
// invalidate key
if(isValid)
key.Validate();
else
key.Invalidate();
return isValid;
}
void Scanner::PopAllSimpleKeys()
{
while(!m_simpleKeys.empty())
m_simpleKeys.pop();
}
} }
void Scanner::SimpleKey::Invalidate() {
if (pIndent)
pIndent->status = IndentMarker::INVALID;
if (pMapStart)
pMapStart->status = Token::INVALID;
if (pKey)
pKey->status = Token::INVALID;
}
// CanInsertPotentialSimpleKey
bool Scanner::CanInsertPotentialSimpleKey() const {
if (!m_simpleKeyAllowed)
return false;
return !ExistsActiveSimpleKey();
}
// ExistsActiveSimpleKey
// . Returns true if there's a potential simple key at our flow level
// (there's allowed at most one per flow level, i.e., at the start of the flow
// start token)
bool Scanner::ExistsActiveSimpleKey() const {
if (m_simpleKeys.empty())
return false;
const SimpleKey& key = m_simpleKeys.top();
return key.flowLevel == GetFlowLevel();
}
// InsertPotentialSimpleKey
// . If we can, add a potential simple key to the queue,
// and save it on a stack.
void Scanner::InsertPotentialSimpleKey() {
if (!CanInsertPotentialSimpleKey())
return;
SimpleKey key(INPUT.mark(), GetFlowLevel());
// first add a map start, if necessary
if (InBlockContext()) {
key.pIndent = PushIndentTo(INPUT.column(), IndentMarker::MAP);
if (key.pIndent) {
key.pIndent->status = IndentMarker::UNKNOWN;
key.pMapStart = key.pIndent->pStartToken;
key.pMapStart->status = Token::UNVERIFIED;
}
}
// then add the (now unverified) key
m_tokens.push(Token(Token::KEY, INPUT.mark()));
key.pKey = &m_tokens.back();
key.pKey->status = Token::UNVERIFIED;
m_simpleKeys.push(key);
}
// InvalidateSimpleKey
// . Automatically invalidate the simple key in our flow level
void Scanner::InvalidateSimpleKey() {
if (m_simpleKeys.empty())
return;
// grab top key
SimpleKey& key = m_simpleKeys.top();
if (key.flowLevel != GetFlowLevel())
return;
key.Invalidate();
m_simpleKeys.pop();
}
// VerifySimpleKey
// . Determines whether the latest simple key to be added is valid,
// and if so, makes it valid.
bool Scanner::VerifySimpleKey() {
if (m_simpleKeys.empty())
return false;
// grab top key
SimpleKey key = m_simpleKeys.top();
// only validate if we're in the correct flow level
if (key.flowLevel != GetFlowLevel())
return false;
m_simpleKeys.pop();
bool isValid = true;
// needs to be less than 1024 characters and inline
if (INPUT.line() != key.mark.line || INPUT.pos() - key.mark.pos > 1024)
isValid = false;
// invalidate key
if (isValid)
key.Validate();
else
key.Invalidate();
return isValid;
}
void Scanner::PopAllSimpleKeys() {
while (!m_simpleKeys.empty())
m_simpleKeys.pop();
}
}
#ifndef SINGLEDOCPARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef SINGLEDOCPARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define SINGLEDOCPARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define SINGLEDOCPARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
#endif #endif
#include "yaml-cpp/anchor.h" #include "yaml-cpp/anchor.h"
#include "yaml-cpp/noncopyable.h" #include "yaml-cpp/noncopyable.h"
#include <string> #include <string>
#include <map> #include <map>
#include <memory> #include <memory>
namespace YAML namespace YAML {
{ struct Directives;
struct Directives; struct Mark;
struct Mark; struct Token;
struct Token; class CollectionStack;
class CollectionStack; class EventHandler;
class EventHandler; class Node;
class Node; class Scanner;
class Scanner;
class SingleDocParser : private noncopyable {
class SingleDocParser: private noncopyable public:
{ SingleDocParser(Scanner& scanner, const Directives& directives);
public: ~SingleDocParser();
SingleDocParser(Scanner& scanner, const Directives& directives);
~SingleDocParser(); void HandleDocument(EventHandler& eventHandler);
private:
void HandleNode(EventHandler& eventHandler);
void HandleSequence(EventHandler& eventHandler);
void HandleBlockSequence(EventHandler& eventHandler);
void HandleFlowSequence(EventHandler& eventHandler);
void HandleMap(EventHandler& eventHandler);
void HandleBlockMap(EventHandler& eventHandler);
void HandleFlowMap(EventHandler& eventHandler);
void HandleCompactMap(EventHandler& eventHandler);
void HandleCompactMapWithNoKey(EventHandler& eventHandler);
void ParseProperties(std::string& tag, anchor_t& anchor);
void ParseTag(std::string& tag);
void ParseAnchor(anchor_t& anchor);
anchor_t RegisterAnchor(const std::string& name);
anchor_t LookupAnchor(const Mark& mark, const std::string& name) const;
private:
Scanner& m_scanner;
const Directives& m_directives;
std::auto_ptr<CollectionStack> m_pCollectionStack;
void HandleDocument(EventHandler& eventHandler); typedef std::map<std::string, anchor_t> Anchors;
Anchors m_anchors;
private: anchor_t m_curAnchor;
void HandleNode(EventHandler& eventHandler); };
void HandleSequence(EventHandler& eventHandler);
void HandleBlockSequence(EventHandler& eventHandler);
void HandleFlowSequence(EventHandler& eventHandler);
void HandleMap(EventHandler& eventHandler);
void HandleBlockMap(EventHandler& eventHandler);
void HandleFlowMap(EventHandler& eventHandler);
void HandleCompactMap(EventHandler& eventHandler);
void HandleCompactMapWithNoKey(EventHandler& eventHandler);
void ParseProperties(std::string& tag, anchor_t& anchor);
void ParseTag(std::string& tag);
void ParseAnchor(anchor_t& anchor);
anchor_t RegisterAnchor(const std::string& name);
anchor_t LookupAnchor(const Mark& mark, const std::string& name) const;
private:
Scanner& m_scanner;
const Directives& m_directives;
std::auto_ptr<CollectionStack> m_pCollectionStack;
typedef std::map<std::string, anchor_t> Anchors;
Anchors m_anchors;
anchor_t m_curAnchor;
};
} }
#endif // SINGLEDOCPARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // SINGLEDOCPARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
This source diff could not be displayed because it is too large. You can view the blob instead.
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