Commit 3355bbb3 authored by Jesse Beder's avatar Jesse Beder
Browse files

Merge clang-format from core

parents 5b889311 9b4db068
#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 GRAPHBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef GRAPHBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define GRAPHBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define GRAPHBUILDER_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 <string> #include <string>
namespace YAML namespace YAML {
{ class Parser;
class Parser;
// GraphBuilderInterface
// GraphBuilderInterface // . Abstraction of node creation
// . Abstraction of node creation // . pParentNode is always NULL or the return value of one of the NewXXX()
// . pParentNode is always NULL or the return value of one of the NewXXX() // functions.
// functions. class GraphBuilderInterface {
class GraphBuilderInterface public:
{ // Create and return a new node with a null value.
public: virtual void *NewNull(const Mark &mark, void *pParentNode) = 0;
// Create and return a new node with a null value.
virtual void *NewNull(const Mark& mark, void *pParentNode) = 0; // Create and return a new node with the given tag and value.
virtual void *NewScalar(const Mark &mark, const std::string &tag,
// Create and return a new node with the given tag and value. void *pParentNode, const std::string &value) = 0;
virtual void *NewScalar(const Mark& mark, const std::string& tag, void *pParentNode, const std::string& value) = 0;
// Create and return a new sequence node
// Create and return a new sequence node virtual void *NewSequence(const Mark &mark, const std::string &tag,
virtual void *NewSequence(const Mark& mark, const std::string& tag, void *pParentNode) = 0; void *pParentNode) = 0;
// Add pNode to pSequence. pNode was created with one of the NewXxx()
// functions and pSequence with NewSequence(). // Add pNode to pSequence. pNode was created with one of the NewXxx()
virtual void AppendToSequence(void *pSequence, void *pNode) = 0; // functions and pSequence with NewSequence().
// Note that no moew entries will be added to pSequence virtual void AppendToSequence(void *pSequence, void *pNode) = 0;
virtual void SequenceComplete(void *pSequence) {(void)pSequence;}
// Note that no moew entries will be added to pSequence
// Create and return a new map node virtual void SequenceComplete(void *pSequence) { (void)pSequence; }
virtual void *NewMap(const Mark& mark, const std::string& tag, void *pParentNode) = 0;
// Add the pKeyNode => pValueNode mapping to pMap. pKeyNode and pValueNode // Create and return a new map node
// were created with one of the NewXxx() methods and pMap with NewMap(). virtual void *NewMap(const Mark &mark, const std::string &tag,
virtual void AssignInMap(void *pMap, void *pKeyNode, void *pValueNode) = 0; void *pParentNode) = 0;
// Note that no more assignments will be made in pMap
virtual void MapComplete(void *pMap) {(void)pMap;} // Add the pKeyNode => pValueNode mapping to pMap. pKeyNode and pValueNode
// were created with one of the NewXxx() methods and pMap with NewMap().
// Return the node that should be used in place of an alias referencing virtual void AssignInMap(void *pMap, void *pKeyNode, void *pValueNode) = 0;
// pNode (pNode by default)
virtual void *AnchorReference(const Mark& mark, void *pNode) {(void)mark; return pNode;} // Note that no more assignments will be made in pMap
}; virtual void MapComplete(void *pMap) { (void)pMap; }
// Typesafe wrapper for GraphBuilderInterface. Assumes that Impl defines // Return the node that should be used in place of an alias referencing
// Node, Sequence, and Map types. Sequence and Map must derive from Node // pNode (pNode by default)
// (unless Node is defined as void). Impl must also implement function with virtual void *AnchorReference(const Mark &mark, void *pNode) {
// all of the same names as the virtual functions in GraphBuilderInterface (void)mark;
// -- including the ones with default implementations -- but with the return pNode;
// prototypes changed to accept an explicit Node*, Sequence*, or Map* where }
// appropriate. };
template <class Impl>
class GraphBuilder : public GraphBuilderInterface // Typesafe wrapper for GraphBuilderInterface. Assumes that Impl defines
{ // Node, Sequence, and Map types. Sequence and Map must derive from Node
public: // (unless Node is defined as void). Impl must also implement function with
typedef typename Impl::Node Node; // all of the same names as the virtual functions in GraphBuilderInterface
typedef typename Impl::Sequence Sequence; // -- including the ones with default implementations -- but with the
typedef typename Impl::Map Map; // prototypes changed to accept an explicit Node*, Sequence*, or Map* where
// appropriate.
GraphBuilder(Impl& impl) : m_impl(impl) template <class Impl>
{ class GraphBuilder : public GraphBuilderInterface {
Map* pMap = NULL; public:
Sequence* pSeq = NULL; typedef typename Impl::Node Node;
Node* pNode = NULL; typedef typename Impl::Sequence Sequence;
typedef typename Impl::Map Map;
// Type consistency checks
pNode = pMap; GraphBuilder(Impl &impl) : m_impl(impl) {
pNode = pSeq; Map *pMap = NULL;
} Sequence *pSeq = NULL;
Node *pNode = NULL;
GraphBuilderInterface& AsBuilderInterface() {return *this;}
// Type consistency checks
virtual void *NewNull(const Mark& mark, void* pParentNode) { pNode = pMap;
return CheckType<Node>(m_impl.NewNull(mark, AsNode(pParentNode))); pNode = pSeq;
} }
virtual void *NewScalar(const Mark& mark, const std::string& tag, void *pParentNode, const std::string& value) { GraphBuilderInterface &AsBuilderInterface() { return *this; }
return CheckType<Node>(m_impl.NewScalar(mark, tag, AsNode(pParentNode), value));
} virtual void *NewNull(const Mark &mark, void *pParentNode) {
return CheckType<Node>(m_impl.NewNull(mark, AsNode(pParentNode)));
virtual void *NewSequence(const Mark& mark, const std::string& tag, void *pParentNode) { }
return CheckType<Sequence>(m_impl.NewSequence(mark, tag, AsNode(pParentNode)));
} virtual void *NewScalar(const Mark &mark, const std::string &tag,
virtual void AppendToSequence(void *pSequence, void *pNode) { void *pParentNode, const std::string &value) {
m_impl.AppendToSequence(AsSequence(pSequence), AsNode(pNode)); return CheckType<Node>(
} m_impl.NewScalar(mark, tag, AsNode(pParentNode), value));
virtual void SequenceComplete(void *pSequence) {
m_impl.SequenceComplete(AsSequence(pSequence));
}
virtual void *NewMap(const Mark& mark, const std::string& tag, void *pParentNode) {
return CheckType<Map>(m_impl.NewMap(mark, tag, AsNode(pParentNode)));
}
virtual void AssignInMap(void *pMap, void *pKeyNode, void *pValueNode) {
m_impl.AssignInMap(AsMap(pMap), AsNode(pKeyNode), AsNode(pValueNode));
}
virtual void MapComplete(void *pMap) {
m_impl.MapComplete(AsMap(pMap));
}
virtual void *AnchorReference(const Mark& mark, void *pNode) {
return CheckType<Node>(m_impl.AnchorReference(mark, AsNode(pNode)));
}
private:
Impl& m_impl;
// Static check for pointer to T
template <class T, class U>
static T* CheckType(U* p) {return p;}
static Node *AsNode(void *pNode) {return static_cast<Node*>(pNode);}
static Sequence *AsSequence(void *pSeq) {return static_cast<Sequence*>(pSeq);}
static Map *AsMap(void *pMap) {return static_cast<Map*>(pMap);}
};
void *BuildGraphOfNextDocument(Parser& parser, GraphBuilderInterface& graphBuilder);
template <class Impl>
typename Impl::Node *BuildGraphOfNextDocument(Parser& parser, Impl& impl)
{
GraphBuilder<Impl> graphBuilder(impl);
return static_cast<typename Impl::Node *>(BuildGraphOfNextDocument(
parser, graphBuilder
));
} }
virtual void *NewSequence(const Mark &mark, const std::string &tag,
void *pParentNode) {
return CheckType<Sequence>(
m_impl.NewSequence(mark, tag, AsNode(pParentNode)));
}
virtual void AppendToSequence(void *pSequence, void *pNode) {
m_impl.AppendToSequence(AsSequence(pSequence), AsNode(pNode));
}
virtual void SequenceComplete(void *pSequence) {
m_impl.SequenceComplete(AsSequence(pSequence));
}
virtual void *NewMap(const Mark &mark, const std::string &tag,
void *pParentNode) {
return CheckType<Map>(m_impl.NewMap(mark, tag, AsNode(pParentNode)));
}
virtual void AssignInMap(void *pMap, void *pKeyNode, void *pValueNode) {
m_impl.AssignInMap(AsMap(pMap), AsNode(pKeyNode), AsNode(pValueNode));
}
virtual void MapComplete(void *pMap) { m_impl.MapComplete(AsMap(pMap)); }
virtual void *AnchorReference(const Mark &mark, void *pNode) {
return CheckType<Node>(m_impl.AnchorReference(mark, AsNode(pNode)));
}
private:
Impl &m_impl;
// Static check for pointer to T
template <class T, class U>
static T *CheckType(U *p) {
return p;
}
static Node *AsNode(void *pNode) { return static_cast<Node *>(pNode); }
static Sequence *AsSequence(void *pSeq) {
return static_cast<Sequence *>(pSeq);
}
static Map *AsMap(void *pMap) { return static_cast<Map *>(pMap); }
};
void *BuildGraphOfNextDocument(Parser &parser,
GraphBuilderInterface &graphBuilder);
template <class Impl>
typename Impl::Node *BuildGraphOfNextDocument(Parser &parser, Impl &impl) {
GraphBuilder<Impl> graphBuilder(impl);
return static_cast<typename Impl::Node *>(
BuildGraphOfNextDocument(parser, graphBuilder));
}
} }
#endif // GRAPHBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // GRAPHBUILDER_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 EMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef EMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define EMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define EMITTER_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/binary.h" #include "yaml-cpp/binary.h"
#include "yaml-cpp/emitterdef.h" #include "yaml-cpp/emitterdef.h"
...@@ -17,193 +18,230 @@ ...@@ -17,193 +18,230 @@
#include <string> #include <string>
#include <sstream> #include <sstream>
namespace YAML namespace YAML {
{ class EmitterState;
class EmitterState;
class YAML_CPP_API Emitter : private noncopyable {
class YAML_CPP_API Emitter: private noncopyable public:
{ Emitter();
public: explicit Emitter(std::ostream& stream);
Emitter(); ~Emitter();
explicit Emitter(std::ostream& stream);
~Emitter(); // output
const char* c_str() const;
// output std::size_t size() const;
const char *c_str() const;
std::size_t size() const; // state checking
bool good() const;
// state checking const std::string GetLastError() const;
bool good() const;
const std::string GetLastError() const; // global setters
bool SetOutputCharset(EMITTER_MANIP value);
// global setters bool SetStringFormat(EMITTER_MANIP value);
bool SetOutputCharset(EMITTER_MANIP value); bool SetBoolFormat(EMITTER_MANIP value);
bool SetStringFormat(EMITTER_MANIP value); bool SetIntBase(EMITTER_MANIP value);
bool SetBoolFormat(EMITTER_MANIP value); bool SetSeqFormat(EMITTER_MANIP value);
bool SetIntBase(EMITTER_MANIP value); bool SetMapFormat(EMITTER_MANIP value);
bool SetSeqFormat(EMITTER_MANIP value); bool SetIndent(unsigned n);
bool SetMapFormat(EMITTER_MANIP value); bool SetPreCommentIndent(unsigned n);
bool SetIndent(unsigned n); bool SetPostCommentIndent(unsigned n);
bool SetPreCommentIndent(unsigned n); bool SetFloatPrecision(unsigned n);
bool SetPostCommentIndent(unsigned n); bool SetDoublePrecision(unsigned n);
bool SetFloatPrecision(unsigned n);
bool SetDoublePrecision(unsigned n); // local setters
Emitter& SetLocalValue(EMITTER_MANIP value);
// local setters Emitter& SetLocalIndent(const _Indent& indent);
Emitter& SetLocalValue(EMITTER_MANIP value); Emitter& SetLocalPrecision(const _Precision& precision);
Emitter& SetLocalIndent(const _Indent& indent);
Emitter& SetLocalPrecision(const _Precision& precision); // overloads of write
Emitter& Write(const std::string& str);
// overloads of write Emitter& Write(bool b);
Emitter& Write(const std::string& str); Emitter& Write(char ch);
Emitter& Write(bool b); Emitter& Write(const _Alias& alias);
Emitter& Write(char ch); Emitter& Write(const _Anchor& anchor);
Emitter& Write(const _Alias& alias); Emitter& Write(const _Tag& tag);
Emitter& Write(const _Anchor& anchor); Emitter& Write(const _Comment& comment);
Emitter& Write(const _Tag& tag); Emitter& Write(const _Null& n);
Emitter& Write(const _Comment& comment); Emitter& Write(const Binary& binary);
Emitter& Write(const _Null& n);
Emitter& Write(const Binary& binary); template <typename T>
Emitter& WriteIntegralType(T value);
template <typename T>
Emitter& WriteIntegralType(T value); template <typename T>
Emitter& WriteStreamable(T value);
template <typename T>
Emitter& WriteStreamable(T value); private:
template <typename T>
private: void SetStreamablePrecision(std::stringstream&) {}
template<typename T> void SetStreamablePrecision(std::stringstream&) {} unsigned GetFloatPrecision() const;
unsigned GetFloatPrecision() const; unsigned GetDoublePrecision() const;
unsigned GetDoublePrecision() const;
void PrepareIntegralStream(std::stringstream& stream) const;
void PrepareIntegralStream(std::stringstream& stream) const; void StartedScalar();
void StartedScalar();
private:
private: void EmitBeginDoc();
void EmitBeginDoc(); void EmitEndDoc();
void EmitEndDoc(); void EmitBeginSeq();
void EmitBeginSeq(); void EmitEndSeq();
void EmitEndSeq(); void EmitBeginMap();
void EmitBeginMap(); void EmitEndMap();
void EmitEndMap(); void EmitNewline();
void EmitNewline(); void EmitKindTag();
void EmitKindTag(); void EmitTag(bool verbatim, const _Tag& tag);
void EmitTag(bool verbatim, const _Tag& tag);
void PrepareNode(EmitterNodeType::value child);
void PrepareNode(EmitterNodeType::value child); void PrepareTopNode(EmitterNodeType::value child);
void PrepareTopNode(EmitterNodeType::value child); void FlowSeqPrepareNode(EmitterNodeType::value child);
void FlowSeqPrepareNode(EmitterNodeType::value child); void BlockSeqPrepareNode(EmitterNodeType::value child);
void BlockSeqPrepareNode(EmitterNodeType::value child);
void FlowMapPrepareNode(EmitterNodeType::value child);
void FlowMapPrepareNode(EmitterNodeType::value child);
void FlowMapPrepareLongKey(EmitterNodeType::value child);
void FlowMapPrepareLongKey(EmitterNodeType::value child); void FlowMapPrepareLongKeyValue(EmitterNodeType::value child);
void FlowMapPrepareLongKeyValue(EmitterNodeType::value child); void FlowMapPrepareSimpleKey(EmitterNodeType::value child);
void FlowMapPrepareSimpleKey(EmitterNodeType::value child); void FlowMapPrepareSimpleKeyValue(EmitterNodeType::value child);
void FlowMapPrepareSimpleKeyValue(EmitterNodeType::value child);
void BlockMapPrepareNode(EmitterNodeType::value child);
void BlockMapPrepareNode(EmitterNodeType::value child);
void BlockMapPrepareLongKey(EmitterNodeType::value child);
void BlockMapPrepareLongKey(EmitterNodeType::value child); void BlockMapPrepareLongKeyValue(EmitterNodeType::value child);
void BlockMapPrepareLongKeyValue(EmitterNodeType::value child); void BlockMapPrepareSimpleKey(EmitterNodeType::value child);
void BlockMapPrepareSimpleKey(EmitterNodeType::value child); void BlockMapPrepareSimpleKeyValue(EmitterNodeType::value child);
void BlockMapPrepareSimpleKeyValue(EmitterNodeType::value child);
void SpaceOrIndentTo(bool requireSpace, unsigned indent);
void SpaceOrIndentTo(bool requireSpace, unsigned indent);
const char* ComputeFullBoolName(bool b) const;
const char *ComputeFullBoolName(bool b) const; bool CanEmitNewline() const;
bool CanEmitNewline() const;
private:
private: std::auto_ptr<EmitterState> m_pState;
std::auto_ptr<EmitterState> m_pState; ostream_wrapper m_stream;
ostream_wrapper m_stream; };
};
template <typename T>
template <typename T> inline Emitter& Emitter::WriteIntegralType(T value) {
inline Emitter& Emitter::WriteIntegralType(T value) if (!good())
{ return *this;
if(!good())
return *this; PrepareNode(EmitterNodeType::Scalar);
PrepareNode(EmitterNodeType::Scalar); std::stringstream stream;
PrepareIntegralStream(stream);
std::stringstream stream; stream << value;
PrepareIntegralStream(stream); m_stream << stream.str();
stream << value;
m_stream << stream.str(); StartedScalar();
StartedScalar(); return *this;
}
return *this;
} template <typename T>
inline Emitter& Emitter::WriteStreamable(T value) {
template <typename T> if (!good())
inline Emitter& Emitter::WriteStreamable(T value) return *this;
{
if(!good()) PrepareNode(EmitterNodeType::Scalar);
return *this;
std::stringstream stream;
PrepareNode(EmitterNodeType::Scalar); SetStreamablePrecision<T>(stream);
stream << value;
std::stringstream stream; m_stream << stream.str();
SetStreamablePrecision<T>(stream);
stream << value; StartedScalar();
m_stream << stream.str();
return *this;
StartedScalar(); }
return *this; template <>
} inline void Emitter::SetStreamablePrecision<float>(std::stringstream& stream) {
stream.precision(GetFloatPrecision());
template<> }
inline void Emitter::SetStreamablePrecision<float>(std::stringstream& stream)
{ template <>
stream.precision(GetFloatPrecision()); inline void Emitter::SetStreamablePrecision<double>(std::stringstream& stream) {
} stream.precision(GetDoublePrecision());
}
template<>
inline void Emitter::SetStreamablePrecision<double>(std::stringstream& stream) // overloads of insertion
{ inline Emitter& operator<<(Emitter& emitter, const std::string& v) {
stream.precision(GetDoublePrecision()); return emitter.Write(v);
} }
inline Emitter& operator<<(Emitter& emitter, bool v) {
// overloads of insertion return emitter.Write(v);
inline Emitter& operator << (Emitter& emitter, const std::string& v) { return emitter.Write(v); } }
inline Emitter& operator << (Emitter& emitter, bool v) { return emitter.Write(v); } inline Emitter& operator<<(Emitter& emitter, char v) {
inline Emitter& operator << (Emitter& emitter, char v) { return emitter.Write(v); } return emitter.Write(v);
inline Emitter& operator << (Emitter& emitter, unsigned char v) { return emitter.Write(static_cast<char>(v)); } }
inline Emitter& operator << (Emitter& emitter, const _Alias& v) { return emitter.Write(v); } inline Emitter& operator<<(Emitter& emitter, unsigned char v) {
inline Emitter& operator << (Emitter& emitter, const _Anchor& v) { return emitter.Write(v); } return emitter.Write(static_cast<char>(v));
inline Emitter& operator << (Emitter& emitter, const _Tag& v) { return emitter.Write(v); } }
inline Emitter& operator << (Emitter& emitter, const _Comment& v) { return emitter.Write(v); } inline Emitter& operator<<(Emitter& emitter, const _Alias& v) {
inline Emitter& operator << (Emitter& emitter, const _Null& v) { return emitter.Write(v); } return emitter.Write(v);
inline Emitter& operator << (Emitter& emitter, const Binary& b) { return emitter.Write(b); } }
inline Emitter& operator<<(Emitter& emitter, const _Anchor& v) {
inline Emitter& operator << (Emitter& emitter, const char *v) { return emitter.Write(std::string(v)); } return emitter.Write(v);
}
inline Emitter& operator << (Emitter& emitter, int v) { return emitter.WriteIntegralType(v); } inline Emitter& operator<<(Emitter& emitter, const _Tag& v) {
inline Emitter& operator << (Emitter& emitter, unsigned int v) { return emitter.WriteIntegralType(v); } return emitter.Write(v);
inline Emitter& operator << (Emitter& emitter, short v) { return emitter.WriteIntegralType(v); } }
inline Emitter& operator << (Emitter& emitter, unsigned short v) { return emitter.WriteIntegralType(v); } inline Emitter& operator<<(Emitter& emitter, const _Comment& v) {
inline Emitter& operator << (Emitter& emitter, long v) { return emitter.WriteIntegralType(v); } return emitter.Write(v);
inline Emitter& operator << (Emitter& emitter, unsigned long v) { return emitter.WriteIntegralType(v); } }
inline Emitter& operator << (Emitter& emitter, long long v) { return emitter.WriteIntegralType(v); } inline Emitter& operator<<(Emitter& emitter, const _Null& v) {
inline Emitter& operator << (Emitter& emitter, unsigned long long v) { return emitter.WriteIntegralType(v); } return emitter.Write(v);
}
inline Emitter& operator << (Emitter& emitter, float v) { return emitter.WriteStreamable(v); } inline Emitter& operator<<(Emitter& emitter, const Binary& b) {
inline Emitter& operator << (Emitter& emitter, double v) { return emitter.WriteStreamable(v); } return emitter.Write(b);
}
inline Emitter& operator << (Emitter& emitter, EMITTER_MANIP value) {
return emitter.SetLocalValue(value); inline Emitter& operator<<(Emitter& emitter, const char* v) {
} return emitter.Write(std::string(v));
}
inline Emitter& operator << (Emitter& emitter, _Indent indent) {
return emitter.SetLocalIndent(indent); inline Emitter& operator<<(Emitter& emitter, int v) {
} return emitter.WriteIntegralType(v);
}
inline Emitter& operator << (Emitter& emitter, _Precision precision) { inline Emitter& operator<<(Emitter& emitter, unsigned int v) {
return emitter.SetLocalPrecision(precision); return emitter.WriteIntegralType(v);
} }
} inline Emitter& operator<<(Emitter& emitter, short v) {
return emitter.WriteIntegralType(v);
#endif // EMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 }
inline Emitter& operator<<(Emitter& emitter, unsigned short v) {
return emitter.WriteIntegralType(v);
}
inline Emitter& operator<<(Emitter& emitter, long v) {
return emitter.WriteIntegralType(v);
}
inline Emitter& operator<<(Emitter& emitter, unsigned long v) {
return emitter.WriteIntegralType(v);
}
inline Emitter& operator<<(Emitter& emitter, long long v) {
return emitter.WriteIntegralType(v);
}
inline Emitter& operator<<(Emitter& emitter, unsigned long long v) {
return emitter.WriteIntegralType(v);
}
inline Emitter& operator<<(Emitter& emitter, float v) {
return emitter.WriteStreamable(v);
}
inline Emitter& operator<<(Emitter& emitter, double v) {
return emitter.WriteStreamable(v);
}
inline Emitter& operator<<(Emitter& emitter, EMITTER_MANIP value) {
return emitter.SetLocalValue(value);
}
inline Emitter& operator<<(Emitter& emitter, _Indent indent) {
return emitter.SetLocalIndent(indent);
}
inline Emitter& operator<<(Emitter& emitter, _Precision precision) {
return emitter.SetLocalPrecision(precision);
}
}
#endif // EMITTER_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 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 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
#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);
} }
} }
}
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