mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-10 04:51:17 +00:00
Merged r444:449 from the node refactoring branch to the trunk
This commit is contained in:
@@ -1,83 +0,0 @@
|
||||
#include "aliascontent.h"
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
AliasContent::AliasContent(Content* pNodeContent): m_pRef(pNodeContent)
|
||||
{
|
||||
}
|
||||
|
||||
bool AliasContent::GetBegin(std::vector <Node *>::const_iterator& i) const
|
||||
{
|
||||
return m_pRef->GetBegin(i);
|
||||
}
|
||||
|
||||
bool AliasContent::GetBegin(std::map <Node *, Node *, ltnode>::const_iterator& i) const
|
||||
{
|
||||
return m_pRef->GetBegin(i);
|
||||
}
|
||||
|
||||
bool AliasContent::GetEnd(std::vector <Node *>::const_iterator& i) const
|
||||
{
|
||||
return m_pRef->GetEnd(i);
|
||||
}
|
||||
|
||||
bool AliasContent::GetEnd(std::map <Node *, Node *, ltnode>::const_iterator& i) const
|
||||
{
|
||||
return m_pRef->GetEnd(i);
|
||||
}
|
||||
|
||||
Node* AliasContent::GetNode(std::size_t n) const
|
||||
{
|
||||
return m_pRef->GetNode(n);
|
||||
}
|
||||
|
||||
std::size_t AliasContent::GetSize() const
|
||||
{
|
||||
return m_pRef->GetSize();
|
||||
}
|
||||
|
||||
bool AliasContent::IsScalar() const
|
||||
{
|
||||
return m_pRef->IsScalar();
|
||||
}
|
||||
|
||||
bool AliasContent::IsMap() const
|
||||
{
|
||||
return m_pRef->IsMap();
|
||||
}
|
||||
|
||||
bool AliasContent::IsSequence() const
|
||||
{
|
||||
return m_pRef->IsSequence();
|
||||
}
|
||||
|
||||
bool AliasContent::GetScalar(std::string& scalar) const
|
||||
{
|
||||
return m_pRef->GetScalar(scalar);
|
||||
}
|
||||
|
||||
void AliasContent::EmitEvents(AliasManager& am, EventHandler& eventHandler, const Mark& mark, const std::string& tag, anchor_t anchor) const
|
||||
{
|
||||
m_pRef->EmitEvents(am, eventHandler, mark, tag, anchor);
|
||||
}
|
||||
|
||||
int AliasContent::Compare(Content *pContent)
|
||||
{
|
||||
return m_pRef->Compare(pContent);
|
||||
}
|
||||
|
||||
int AliasContent::Compare(Scalar *pScalar)
|
||||
{
|
||||
return m_pRef->Compare(pScalar);
|
||||
}
|
||||
|
||||
int AliasContent::Compare(Sequence *pSequence)
|
||||
{
|
||||
return m_pRef->Compare(pSequence);
|
||||
}
|
||||
|
||||
int AliasContent::Compare(Map *pMap)
|
||||
{
|
||||
return m_pRef->Compare(pMap);
|
||||
}
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
#ifndef ALIASCONTENT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
#define ALIASCONTENT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include "content.h"
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
class AliasContent : public Content
|
||||
{
|
||||
public:
|
||||
AliasContent(Content *pNodeContent);
|
||||
|
||||
virtual bool GetBegin(std::vector <Node *>::const_iterator&) const;
|
||||
virtual bool GetBegin(std::map <Node *, Node *, ltnode>::const_iterator&) const;
|
||||
virtual bool GetEnd(std::vector <Node *>::const_iterator&) const;
|
||||
virtual bool GetEnd(std::map <Node *, Node *, ltnode>::const_iterator&) const;
|
||||
virtual Node* GetNode(std::size_t) const;
|
||||
virtual std::size_t GetSize() const;
|
||||
virtual bool IsScalar() const;
|
||||
virtual bool IsMap() const;
|
||||
virtual bool IsSequence() const;
|
||||
|
||||
virtual bool GetScalar(std::string& s) const;
|
||||
virtual void EmitEvents(AliasManager& am, EventHandler& eventHandler, const Mark& mark, const std::string& tag, anchor_t anchor) const;
|
||||
|
||||
virtual int Compare(Content *);
|
||||
virtual int Compare(Scalar *);
|
||||
virtual int Compare(Sequence *);
|
||||
virtual int Compare(Map *);
|
||||
|
||||
private:
|
||||
Content* m_pRef;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // ALIASCONTENT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
@@ -11,33 +11,17 @@ namespace YAML
|
||||
|
||||
void AliasManager::RegisterReference(const Node& node)
|
||||
{
|
||||
const Node *pIdentity = node.Identity();
|
||||
m_newIdentityByOldIdentity.insert(std::make_pair(pIdentity, &node));
|
||||
m_anchorByIdentity.insert(std::make_pair(&node, _CreateNewAnchor()));
|
||||
}
|
||||
|
||||
const Node *AliasManager::LookupReference(const Node& node) const
|
||||
{
|
||||
const Node *pIdentity = node.Identity();
|
||||
return _LookupReference(*pIdentity);
|
||||
}
|
||||
|
||||
|
||||
anchor_t AliasManager::LookupAnchor(const Node& node) const
|
||||
{
|
||||
AnchorByIdentity::const_iterator it = m_anchorByIdentity.find(&node);
|
||||
if(it == m_anchorByIdentity.end())
|
||||
assert(false); // TODO: throw
|
||||
return it->second;
|
||||
}
|
||||
|
||||
const Node *AliasManager::_LookupReference(const Node& oldIdentity) const
|
||||
{
|
||||
NodeByNode::const_iterator it = m_newIdentityByOldIdentity.find(&oldIdentity);
|
||||
if(it == m_newIdentityByOldIdentity.end())
|
||||
return 0;
|
||||
return it->second;
|
||||
}
|
||||
|
||||
|
||||
anchor_t AliasManager::_CreateNewAnchor()
|
||||
{
|
||||
return ++m_curAnchor;
|
||||
|
@@ -1,21 +0,0 @@
|
||||
#include "content.h"
|
||||
#include "yaml-cpp/node.h"
|
||||
#include <cassert>
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
void Content::SetData(const std::string&)
|
||||
{
|
||||
assert(false); // TODO: throw
|
||||
}
|
||||
|
||||
void Content::Append(std::auto_ptr<Node>)
|
||||
{
|
||||
assert(false); // TODO: throw
|
||||
}
|
||||
|
||||
void Content::Insert(std::auto_ptr<Node>, std::auto_ptr<Node>)
|
||||
{
|
||||
assert(false); // TODO: throw
|
||||
}
|
||||
}
|
@@ -1,62 +0,0 @@
|
||||
#ifndef CONTENT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
#define CONTENT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include "yaml-cpp/anchor.h"
|
||||
#include "yaml-cpp/exceptions.h"
|
||||
#include "ltnode.h"
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
struct Mark;
|
||||
struct NodeProperties;
|
||||
class AliasManager;
|
||||
class EventHandler;
|
||||
class Map;
|
||||
class Node;
|
||||
class Scalar;
|
||||
class Scanner;
|
||||
class Sequence;
|
||||
|
||||
class Content
|
||||
{
|
||||
public:
|
||||
Content() {}
|
||||
virtual ~Content() {}
|
||||
|
||||
virtual bool GetBegin(std::vector <Node *>::const_iterator&) const { return false; }
|
||||
virtual bool GetBegin(std::map <Node *, Node *, ltnode>::const_iterator&) const { return false; }
|
||||
virtual bool GetEnd(std::vector <Node *>::const_iterator&) const { return false; }
|
||||
virtual bool GetEnd(std::map <Node *, Node *, ltnode>::const_iterator&) const { return false; }
|
||||
virtual Node *GetNode(std::size_t) const { return 0; }
|
||||
virtual std::size_t GetSize() const { return 0; }
|
||||
virtual bool IsScalar() const { return false; }
|
||||
virtual bool IsMap() const { return false; }
|
||||
virtual bool IsSequence() const { return false; }
|
||||
|
||||
virtual void SetData(const std::string& data);
|
||||
virtual void Append(std::auto_ptr<Node> pNode);
|
||||
virtual void Insert(std::auto_ptr<Node> pKey, std::auto_ptr<Node> pValue);
|
||||
virtual void EmitEvents(AliasManager& am, EventHandler& eventHandler, const Mark& mark, const std::string& tag, anchor_t anchor) const = 0;
|
||||
|
||||
// extraction
|
||||
virtual bool GetScalar(std::string&) const { return false; }
|
||||
|
||||
// ordering
|
||||
virtual int Compare(Content *) { return 0; }
|
||||
virtual int Compare(Scalar *) { return 0; }
|
||||
virtual int Compare(Sequence *) { return 0; }
|
||||
virtual int Compare(Map *) { return 0; }
|
||||
|
||||
protected:
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CONTENT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
@@ -4,10 +4,10 @@ namespace YAML
|
||||
{
|
||||
int GraphBuilderAdapter::ContainerFrame::sequenceMarker;
|
||||
|
||||
void GraphBuilderAdapter::OnNull(const std::string& tag, anchor_t anchor)
|
||||
void GraphBuilderAdapter::OnNull(const Mark& mark, anchor_t anchor)
|
||||
{
|
||||
void *pParent = GetCurrentParent();
|
||||
void *pNode = m_builder.NewNull(tag, pParent);
|
||||
void *pNode = m_builder.NewNull(mark, pParent);
|
||||
RegisterAnchor(anchor, pNode);
|
||||
|
||||
DispositionNode(pNode);
|
||||
|
@@ -24,7 +24,7 @@ namespace YAML
|
||||
virtual void OnDocumentStart(const Mark& mark) {(void)mark;}
|
||||
virtual void OnDocumentEnd() {}
|
||||
|
||||
virtual void OnNull(const std::string& tag, anchor_t anchor);
|
||||
virtual void OnNull(const Mark& mark, anchor_t anchor);
|
||||
virtual void OnAlias(const Mark& mark, anchor_t anchor);
|
||||
virtual void OnScalar(const Mark& mark, const std::string& tag, anchor_t anchor, const std::string& value);
|
||||
|
||||
|
@@ -26,12 +26,11 @@ namespace YAML
|
||||
{
|
||||
}
|
||||
|
||||
void EmitFromEvents::OnNull(const std::string& tag, anchor_t anchor)
|
||||
void EmitFromEvents::OnNull(const Mark&, anchor_t anchor)
|
||||
{
|
||||
BeginNode();
|
||||
EmitProps(tag, anchor);
|
||||
if(tag.empty())
|
||||
m_emitter << Null;
|
||||
EmitProps("", anchor);
|
||||
m_emitter << Null;
|
||||
}
|
||||
|
||||
void EmitFromEvents::OnAlias(const Mark&, anchor_t anchor)
|
||||
|
@@ -4,18 +4,16 @@
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
Iterator::Iterator(): m_pData(0)
|
||||
{
|
||||
m_pData = new IterPriv;
|
||||
}
|
||||
|
||||
Iterator::Iterator(IterPriv *pData): m_pData(pData)
|
||||
Iterator::Iterator(): m_pData(new IterPriv)
|
||||
{
|
||||
}
|
||||
|
||||
Iterator::Iterator(const Iterator& rhs): m_pData(0)
|
||||
Iterator::Iterator(std::auto_ptr<IterPriv> pData): m_pData(pData)
|
||||
{
|
||||
}
|
||||
|
||||
Iterator::Iterator(const Iterator& rhs): m_pData(new IterPriv(*rhs.m_pData))
|
||||
{
|
||||
m_pData = new IterPriv(*rhs.m_pData);
|
||||
}
|
||||
|
||||
Iterator& Iterator::operator = (const Iterator& rhs)
|
||||
@@ -23,14 +21,12 @@ namespace YAML
|
||||
if(this == &rhs)
|
||||
return *this;
|
||||
|
||||
delete m_pData;
|
||||
m_pData = new IterPriv(*rhs.m_pData);
|
||||
m_pData.reset(new IterPriv(*rhs.m_pData));
|
||||
return *this;
|
||||
}
|
||||
|
||||
Iterator::~Iterator()
|
||||
{
|
||||
delete m_pData;
|
||||
}
|
||||
|
||||
Iterator& Iterator::operator ++ ()
|
||||
|
@@ -6,7 +6,7 @@
|
||||
#endif
|
||||
|
||||
|
||||
#include "ltnode.h"
|
||||
#include "yaml-cpp/ltnode.h"
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
|
18
src/ltnode.h
18
src/ltnode.h
@@ -1,18 +0,0 @@
|
||||
#ifndef LTNODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
#define LTNODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
class Node;
|
||||
|
||||
struct ltnode {
|
||||
bool operator()(const Node *pNode1, const Node *pNode2) const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // LTNODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
91
src/map.cpp
91
src/map.cpp
@@ -1,91 +0,0 @@
|
||||
#include "map.h"
|
||||
#include "yaml-cpp/node.h"
|
||||
#include "yaml-cpp/eventhandler.h"
|
||||
#include "yaml-cpp/exceptions.h"
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
Map::Map()
|
||||
{
|
||||
}
|
||||
|
||||
Map::~Map()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
void Map::Clear()
|
||||
{
|
||||
for(node_map::const_iterator it=m_data.begin();it!=m_data.end();++it) {
|
||||
delete it->first;
|
||||
delete it->second;
|
||||
}
|
||||
m_data.clear();
|
||||
}
|
||||
|
||||
bool Map::GetBegin(std::map <Node *, Node *, ltnode>::const_iterator& it) const
|
||||
{
|
||||
it = m_data.begin();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Map::GetEnd(std::map <Node *, Node *, ltnode>::const_iterator& it) const
|
||||
{
|
||||
it = m_data.end();
|
||||
return true;
|
||||
}
|
||||
|
||||
std::size_t Map::GetSize() const
|
||||
{
|
||||
return m_data.size();
|
||||
}
|
||||
|
||||
void Map::Insert(std::auto_ptr<Node> pKey, std::auto_ptr<Node> pValue)
|
||||
{
|
||||
node_map::const_iterator it = m_data.find(pKey.get());
|
||||
if(it != m_data.end())
|
||||
return;
|
||||
|
||||
m_data[pKey.release()] = pValue.release();
|
||||
}
|
||||
|
||||
void Map::EmitEvents(AliasManager& am, EventHandler& eventHandler, const Mark& mark, const std::string& tag, anchor_t anchor) const
|
||||
{
|
||||
eventHandler.OnMapStart(mark, tag, anchor);
|
||||
for(node_map::const_iterator it=m_data.begin();it!=m_data.end();++it) {
|
||||
it->first->EmitEvents(am, eventHandler);
|
||||
it->second->EmitEvents(am, eventHandler);
|
||||
}
|
||||
eventHandler.OnMapEnd();
|
||||
}
|
||||
|
||||
int Map::Compare(Content *pContent)
|
||||
{
|
||||
return -pContent->Compare(this);
|
||||
}
|
||||
|
||||
int Map::Compare(Map *pMap)
|
||||
{
|
||||
node_map::const_iterator it = m_data.begin(), jt = pMap->m_data.begin();
|
||||
while(1) {
|
||||
if(it == m_data.end()) {
|
||||
if(jt == pMap->m_data.end())
|
||||
return 0;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
if(jt == pMap->m_data.end())
|
||||
return 1;
|
||||
|
||||
int cmp = it->first->Compare(*jt->first);
|
||||
if(cmp != 0)
|
||||
return cmp;
|
||||
|
||||
cmp = it->second->Compare(*jt->second);
|
||||
if(cmp != 0)
|
||||
return cmp;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
48
src/map.h
48
src/map.h
@@ -1,48 +0,0 @@
|
||||
#ifndef MAP_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
#define MAP_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include "content.h"
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
class Node;
|
||||
|
||||
class Map: public Content
|
||||
{
|
||||
private:
|
||||
typedef std::map <Node *, Node *, ltnode> node_map;
|
||||
|
||||
public:
|
||||
Map();
|
||||
virtual ~Map();
|
||||
|
||||
void Clear();
|
||||
|
||||
virtual bool GetBegin(std::map <Node *, Node *, ltnode>::const_iterator& it) const;
|
||||
virtual bool GetEnd(std::map <Node *, Node *, ltnode>::const_iterator& it) const;
|
||||
virtual std::size_t GetSize() const;
|
||||
|
||||
virtual void Insert(std::auto_ptr<Node> pKey, std::auto_ptr<Node> pValue);
|
||||
virtual void EmitEvents(AliasManager& am, EventHandler& eventHandler, const Mark& mark, const std::string& tag, anchor_t anchor) const;
|
||||
|
||||
virtual bool IsMap() const { return true; }
|
||||
|
||||
// ordering
|
||||
virtual int Compare(Content *pContent);
|
||||
virtual int Compare(Scalar *) { return 1; }
|
||||
virtual int Compare(Sequence *) { return 1; }
|
||||
virtual int Compare(Map *pMap);
|
||||
|
||||
private:
|
||||
node_map m_data;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // MAP_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
280
src/node.cpp
280
src/node.cpp
@@ -1,33 +1,29 @@
|
||||
#include "yaml-cpp/node.h"
|
||||
#include "aliascontent.h"
|
||||
#include "iterpriv.h"
|
||||
#include "nodebuilder.h"
|
||||
#include "nodeownership.h"
|
||||
#include "scanner.h"
|
||||
#include "tag.h"
|
||||
#include "token.h"
|
||||
#include "yaml-cpp/aliasmanager.h"
|
||||
#include "content.h"
|
||||
#include "yaml-cpp/emitfromevents.h"
|
||||
#include "yaml-cpp/emitter.h"
|
||||
#include "yaml-cpp/eventhandler.h"
|
||||
#include "iterpriv.h"
|
||||
#include "map.h"
|
||||
#include "nodebuilder.h"
|
||||
#include "yaml-cpp/nodeproperties.h"
|
||||
#include "scalar.h"
|
||||
#include "scanner.h"
|
||||
#include "sequence.h"
|
||||
#include "tag.h"
|
||||
#include "token.h"
|
||||
#include <cassert>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
// the ordering!
|
||||
bool ltnode::operator ()(const Node *pNode1, const Node *pNode2) const
|
||||
{
|
||||
bool ltnode::operator()(const Node *pNode1, const Node *pNode2) const {
|
||||
return *pNode1 < *pNode2;
|
||||
}
|
||||
|
||||
Node::Node(): m_type(CT_NONE), m_pContent(0), m_alias(false), m_referenced(false)
|
||||
Node::Node(): m_pOwnership(new NodeOwnership), m_type(NodeType::Null)
|
||||
{
|
||||
}
|
||||
|
||||
Node::Node(NodeOwnership& owner): m_pOwnership(new NodeOwnership(&owner)), m_type(NodeType::Null)
|
||||
{
|
||||
m_pIdentity = this;
|
||||
}
|
||||
|
||||
Node::~Node()
|
||||
@@ -37,14 +33,24 @@ namespace YAML
|
||||
|
||||
void Node::Clear()
|
||||
{
|
||||
delete m_pContent;
|
||||
m_type = CT_NONE;
|
||||
m_pContent = 0;
|
||||
m_alias = false;
|
||||
m_referenced = false;
|
||||
m_pOwnership.reset(new NodeOwnership);
|
||||
m_type = NodeType::Null;
|
||||
m_tag.clear();
|
||||
m_scalarData.clear();
|
||||
m_seqData.clear();
|
||||
m_mapData.clear();
|
||||
}
|
||||
|
||||
bool Node::IsAliased() const
|
||||
{
|
||||
return m_pOwnership->IsAliased(*this);
|
||||
}
|
||||
|
||||
Node& Node::CreateNode()
|
||||
{
|
||||
return m_pOwnership->Create();
|
||||
}
|
||||
|
||||
std::auto_ptr<Node> Node::Clone() const
|
||||
{
|
||||
std::auto_ptr<Node> pNode(new Node);
|
||||
@@ -64,9 +70,10 @@ namespace YAML
|
||||
void Node::EmitEvents(AliasManager& am, EventHandler& eventHandler) const
|
||||
{
|
||||
anchor_t anchor = NullAnchor;
|
||||
if(m_referenced || m_alias) {
|
||||
if(const Node *pOther = am.LookupReference(*this)) {
|
||||
eventHandler.OnAlias(m_mark, am.LookupAnchor(*pOther));
|
||||
if(IsAliased()) {
|
||||
anchor = am.LookupAnchor(*this);
|
||||
if(anchor) {
|
||||
eventHandler.OnAlias(m_mark, anchor);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -74,93 +81,76 @@ namespace YAML
|
||||
anchor = am.LookupAnchor(*this);
|
||||
}
|
||||
|
||||
if(m_pContent)
|
||||
m_pContent->EmitEvents(am, eventHandler, m_mark, GetTag(), anchor);
|
||||
else
|
||||
eventHandler.OnNull(GetTag(), anchor);
|
||||
switch(m_type) {
|
||||
case NodeType::Null:
|
||||
eventHandler.OnNull(m_mark, anchor);
|
||||
break;
|
||||
case NodeType::Scalar:
|
||||
eventHandler.OnScalar(m_mark, m_tag, anchor, m_scalarData);
|
||||
break;
|
||||
case NodeType::Sequence:
|
||||
eventHandler.OnSequenceStart(m_mark, m_tag, anchor);
|
||||
for(std::size_t i=0;i<m_seqData.size();i++)
|
||||
m_seqData[i]->EmitEvents(am, eventHandler);
|
||||
eventHandler.OnSequenceEnd();
|
||||
break;
|
||||
case NodeType::Map:
|
||||
eventHandler.OnMapStart(m_mark, m_tag, anchor);
|
||||
for(node_map::const_iterator it=m_mapData.begin();it!=m_mapData.end();++it) {
|
||||
it->first->EmitEvents(am, eventHandler);
|
||||
it->second->EmitEvents(am, eventHandler);
|
||||
}
|
||||
eventHandler.OnMapEnd();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Node::Init(CONTENT_TYPE type, const Mark& mark, const std::string& tag)
|
||||
void Node::Init(NodeType::value type, const Mark& mark, const std::string& tag)
|
||||
{
|
||||
Clear();
|
||||
m_mark = mark;
|
||||
m_type = type;
|
||||
m_tag = tag;
|
||||
m_alias = false;
|
||||
m_pIdentity = this;
|
||||
m_referenced = false;
|
||||
|
||||
switch(type) {
|
||||
case CT_SCALAR:
|
||||
m_pContent = new Scalar;
|
||||
break;
|
||||
case CT_SEQUENCE:
|
||||
m_pContent = new Sequence;
|
||||
break;
|
||||
case CT_MAP:
|
||||
m_pContent = new Map;
|
||||
break;
|
||||
default:
|
||||
m_pContent = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Node::InitNull(const std::string& tag)
|
||||
void Node::MarkAsAliased()
|
||||
{
|
||||
Clear();
|
||||
m_tag = tag;
|
||||
m_alias = false;
|
||||
m_pIdentity = this;
|
||||
m_referenced = false;
|
||||
}
|
||||
|
||||
void Node::InitAlias(const Mark& mark, const Node& identity)
|
||||
{
|
||||
Clear();
|
||||
m_mark = mark;
|
||||
m_alias = true;
|
||||
m_pIdentity = &identity;
|
||||
if(identity.m_pContent) {
|
||||
m_pContent = new AliasContent(identity.m_pContent);
|
||||
m_type = identity.GetType();
|
||||
}
|
||||
identity.m_referenced = true;
|
||||
}
|
||||
|
||||
void Node::SetData(const std::string& data)
|
||||
{
|
||||
assert(m_pContent); // TODO: throw
|
||||
m_pContent->SetData(data);
|
||||
}
|
||||
|
||||
void Node::Append(std::auto_ptr<Node> pNode)
|
||||
{
|
||||
assert(m_pContent); // TODO: throw
|
||||
m_pContent->Append(pNode);
|
||||
m_pOwnership->MarkAsAliased(*this);
|
||||
}
|
||||
|
||||
void Node::Insert(std::auto_ptr<Node> pKey, std::auto_ptr<Node> pValue)
|
||||
void Node::SetScalarData(const std::string& data)
|
||||
{
|
||||
assert(m_pContent); // TODO: throw
|
||||
m_pContent->Insert(pKey, pValue);
|
||||
assert(m_type == NodeType::Scalar); // TODO: throw?
|
||||
m_scalarData = data;
|
||||
}
|
||||
|
||||
void Node::Append(Node& node)
|
||||
{
|
||||
assert(m_type == NodeType::Sequence); // TODO: throw?
|
||||
m_seqData.push_back(&node);
|
||||
}
|
||||
|
||||
void Node::Insert(Node& key, Node& value)
|
||||
{
|
||||
assert(m_type == NodeType::Map); // TODO: throw?
|
||||
m_mapData[&key] = &value;
|
||||
}
|
||||
|
||||
// begin
|
||||
// Returns an iterator to the beginning of this (sequence or map).
|
||||
Iterator Node::begin() const
|
||||
{
|
||||
if(!m_pContent)
|
||||
return Iterator();
|
||||
|
||||
std::vector <Node *>::const_iterator seqIter;
|
||||
if(m_pContent->GetBegin(seqIter))
|
||||
return Iterator(new IterPriv(seqIter));
|
||||
|
||||
std::map <Node *, Node *, ltnode>::const_iterator mapIter;
|
||||
if(m_pContent->GetBegin(mapIter))
|
||||
return Iterator(new IterPriv(mapIter));
|
||||
|
||||
switch(m_type) {
|
||||
case NodeType::Null:
|
||||
case NodeType::Scalar:
|
||||
return Iterator();
|
||||
case NodeType::Sequence:
|
||||
return Iterator(std::auto_ptr<IterPriv>(new IterPriv(m_seqData.begin())));
|
||||
case NodeType::Map:
|
||||
return Iterator(std::auto_ptr<IterPriv>(new IterPriv(m_mapData.begin())));
|
||||
}
|
||||
|
||||
assert(false);
|
||||
return Iterator();
|
||||
}
|
||||
|
||||
@@ -168,50 +158,62 @@ namespace YAML
|
||||
// . Returns an iterator to the end of this (sequence or map).
|
||||
Iterator Node::end() const
|
||||
{
|
||||
if(!m_pContent)
|
||||
return Iterator();
|
||||
|
||||
std::vector <Node *>::const_iterator seqIter;
|
||||
if(m_pContent->GetEnd(seqIter))
|
||||
return Iterator(new IterPriv(seqIter));
|
||||
|
||||
std::map <Node *, Node *, ltnode>::const_iterator mapIter;
|
||||
if(m_pContent->GetEnd(mapIter))
|
||||
return Iterator(new IterPriv(mapIter));
|
||||
|
||||
switch(m_type) {
|
||||
case NodeType::Null:
|
||||
case NodeType::Scalar:
|
||||
return Iterator();
|
||||
case NodeType::Sequence:
|
||||
return Iterator(std::auto_ptr<IterPriv>(new IterPriv(m_seqData.end())));
|
||||
case NodeType::Map:
|
||||
return Iterator(std::auto_ptr<IterPriv>(new IterPriv(m_mapData.end())));
|
||||
}
|
||||
|
||||
assert(false);
|
||||
return Iterator();
|
||||
}
|
||||
|
||||
// size
|
||||
// . Returns the size of this node, if it's a sequence node.
|
||||
// . Returns the size of a sequence or map node
|
||||
// . Otherwise, returns zero.
|
||||
std::size_t Node::size() const
|
||||
{
|
||||
if(!m_pContent)
|
||||
return 0;
|
||||
|
||||
return m_pContent->GetSize();
|
||||
switch(m_type) {
|
||||
case NodeType::Null:
|
||||
case NodeType::Scalar:
|
||||
return 0;
|
||||
case NodeType::Sequence:
|
||||
return m_seqData.size();
|
||||
case NodeType::Map:
|
||||
return m_mapData.size();
|
||||
}
|
||||
|
||||
assert(false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const Node *Node::FindAtIndex(std::size_t i) const
|
||||
{
|
||||
if(!m_pContent)
|
||||
return 0;
|
||||
|
||||
return m_pContent->GetNode(i);
|
||||
if(m_type == NodeType::Sequence)
|
||||
return m_seqData[i];
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Node::GetScalar(std::string& s) const
|
||||
{
|
||||
if(!m_pContent) {
|
||||
if(m_tag.empty())
|
||||
switch(m_type) {
|
||||
case NodeType::Null:
|
||||
s = "~";
|
||||
else
|
||||
s = "";
|
||||
return true;
|
||||
return true;
|
||||
case NodeType::Scalar:
|
||||
s = m_scalarData;
|
||||
return true;
|
||||
case NodeType::Sequence:
|
||||
case NodeType::Map:
|
||||
return false;
|
||||
}
|
||||
|
||||
return m_pContent->GetScalar(s);
|
||||
assert(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
Emitter& operator << (Emitter& out, const Node& node)
|
||||
@@ -223,17 +225,41 @@ namespace YAML
|
||||
|
||||
int Node::Compare(const Node& rhs) const
|
||||
{
|
||||
// Step 1: no content is the smallest
|
||||
if(!m_pContent) {
|
||||
if(rhs.m_pContent)
|
||||
return -1;
|
||||
else
|
||||
if(m_type != rhs.m_type)
|
||||
return rhs.m_type - m_type;
|
||||
|
||||
switch(m_type) {
|
||||
case NodeType::Null:
|
||||
return 0;
|
||||
case NodeType::Scalar:
|
||||
return m_scalarData.compare(rhs.m_scalarData);
|
||||
case NodeType::Sequence:
|
||||
if(m_seqData.size() < rhs.m_seqData.size())
|
||||
return 1;
|
||||
else if(m_seqData.size() > rhs.m_seqData.size())
|
||||
return -1;
|
||||
for(std::size_t i=0;i<m_seqData.size();i++)
|
||||
if(int cmp = m_seqData[i]->Compare(*rhs.m_seqData[i]))
|
||||
return cmp;
|
||||
return 0;
|
||||
case NodeType::Map:
|
||||
if(m_mapData.size() < rhs.m_mapData.size())
|
||||
return 1;
|
||||
else if(m_mapData.size() > rhs.m_mapData.size())
|
||||
return -1;
|
||||
node_map::const_iterator it = m_mapData.begin();
|
||||
node_map::const_iterator jt = rhs.m_mapData.begin();
|
||||
for(;it!=m_mapData.end() && jt!=rhs.m_mapData.end();it++, jt++) {
|
||||
if(int cmp = it->first->Compare(*jt->first))
|
||||
return cmp;
|
||||
if(int cmp = it->second->Compare(*jt->second))
|
||||
return cmp;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if(!rhs.m_pContent)
|
||||
return 1;
|
||||
|
||||
return m_pContent->Compare(rhs.m_pContent);
|
||||
|
||||
assert(false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool operator < (const Node& n1, const Node& n2)
|
||||
|
@@ -1,7 +1,6 @@
|
||||
#include "nodebuilder.h"
|
||||
#include "yaml-cpp/mark.h"
|
||||
#include "yaml-cpp/node.h"
|
||||
#include "yaml-cpp/nodeproperties.h"
|
||||
#include <cassert>
|
||||
|
||||
namespace YAML
|
||||
@@ -25,32 +24,32 @@ namespace YAML
|
||||
assert(m_finished);
|
||||
}
|
||||
|
||||
void NodeBuilder::OnNull(const std::string& tag, anchor_t anchor)
|
||||
void NodeBuilder::OnNull(const Mark& mark, anchor_t anchor)
|
||||
{
|
||||
Node& node = Push(anchor);
|
||||
node.InitNull(tag);
|
||||
node.Init(NodeType::Null, mark, "");
|
||||
Pop();
|
||||
}
|
||||
|
||||
void NodeBuilder::OnAlias(const Mark& mark, anchor_t anchor)
|
||||
void NodeBuilder::OnAlias(const Mark& /*mark*/, anchor_t anchor)
|
||||
{
|
||||
Node& node = Push();
|
||||
node.InitAlias(mark, *m_anchors[anchor]);
|
||||
Pop();
|
||||
Node& node = *m_anchors[anchor];
|
||||
Insert(node);
|
||||
node.MarkAsAliased();
|
||||
}
|
||||
|
||||
void NodeBuilder::OnScalar(const Mark& mark, const std::string& tag, anchor_t anchor, const std::string& value)
|
||||
{
|
||||
Node& node = Push(anchor);
|
||||
node.Init(CT_SCALAR, mark, tag);
|
||||
node.SetData(value);
|
||||
node.Init(NodeType::Scalar, mark, tag);
|
||||
node.SetScalarData(value);
|
||||
Pop();
|
||||
}
|
||||
|
||||
void NodeBuilder::OnSequenceStart(const Mark& mark, const std::string& tag, anchor_t anchor)
|
||||
{
|
||||
Node& node = Push(anchor);
|
||||
node.Init(CT_SEQUENCE, mark, tag);
|
||||
node.Init(NodeType::Sequence, mark, tag);
|
||||
}
|
||||
|
||||
void NodeBuilder::OnSequenceEnd()
|
||||
@@ -61,7 +60,7 @@ namespace YAML
|
||||
void NodeBuilder::OnMapStart(const Mark& mark, const std::string& tag, anchor_t anchor)
|
||||
{
|
||||
Node& node = Push(anchor);
|
||||
node.Init(CT_MAP, mark, tag);
|
||||
node.Init(NodeType::Map, mark, tag);
|
||||
m_didPushKey.push(false);
|
||||
}
|
||||
|
||||
@@ -85,14 +84,14 @@ namespace YAML
|
||||
return m_root;
|
||||
}
|
||||
|
||||
std::auto_ptr<Node> pNode(new Node);
|
||||
m_stack.push(pNode);
|
||||
return m_stack.top();
|
||||
Node& node = m_root.CreateNode();
|
||||
m_stack.push(&node);
|
||||
return node;
|
||||
}
|
||||
|
||||
Node& NodeBuilder::Top()
|
||||
{
|
||||
return m_stack.empty() ? m_root : m_stack.top();
|
||||
return m_stack.empty() ? m_root : *m_stack.top();
|
||||
}
|
||||
|
||||
void NodeBuilder::Pop()
|
||||
@@ -103,36 +102,40 @@ namespace YAML
|
||||
return;
|
||||
}
|
||||
|
||||
std::auto_ptr<Node> pNode = m_stack.pop();
|
||||
Insert(pNode);
|
||||
Node& node = *m_stack.top();
|
||||
m_stack.pop();
|
||||
Insert(node);
|
||||
}
|
||||
|
||||
void NodeBuilder::Insert(std::auto_ptr<Node> pNode)
|
||||
void NodeBuilder::Insert(Node& node)
|
||||
{
|
||||
Node& node = Top();
|
||||
switch(node.GetType()) {
|
||||
case CT_SEQUENCE:
|
||||
node.Append(pNode);
|
||||
Node& curTop = Top();
|
||||
switch(curTop.Type()) {
|
||||
case NodeType::Null:
|
||||
case NodeType::Scalar:
|
||||
assert(false);
|
||||
break;
|
||||
case CT_MAP:
|
||||
case NodeType::Sequence:
|
||||
curTop.Append(node);
|
||||
break;
|
||||
case NodeType::Map:
|
||||
assert(!m_didPushKey.empty());
|
||||
if(m_didPushKey.top()) {
|
||||
assert(!m_pendingKeys.empty());
|
||||
|
||||
std::auto_ptr<Node> pKey = m_pendingKeys.pop();
|
||||
node.Insert(pKey, pNode);
|
||||
Node& key = *m_pendingKeys.top();
|
||||
m_pendingKeys.pop();
|
||||
curTop.Insert(key, node);
|
||||
m_didPushKey.top() = false;
|
||||
} else {
|
||||
m_pendingKeys.push(pNode);
|
||||
m_pendingKeys.push(&node);
|
||||
m_didPushKey.top() = true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
void NodeBuilder::RegisterAnchor(anchor_t anchor, const Node& node)
|
||||
void NodeBuilder::RegisterAnchor(anchor_t anchor, Node& node)
|
||||
{
|
||||
if(anchor) {
|
||||
assert(anchor == m_anchors.size());
|
||||
|
@@ -6,10 +6,10 @@
|
||||
#endif
|
||||
|
||||
#include "yaml-cpp/eventhandler.h"
|
||||
#include "ptr_stack.h"
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <stack>
|
||||
#include <vector>
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
@@ -24,7 +24,7 @@ namespace YAML
|
||||
virtual void OnDocumentStart(const Mark& mark);
|
||||
virtual void OnDocumentEnd();
|
||||
|
||||
virtual void OnNull(const std::string& tag, anchor_t anchor);
|
||||
virtual void OnNull(const Mark& mark, anchor_t anchor);
|
||||
virtual void OnAlias(const Mark& mark, anchor_t anchor);
|
||||
virtual void OnScalar(const Mark& mark, const std::string& tag, anchor_t anchor, const std::string& value);
|
||||
|
||||
@@ -40,19 +40,19 @@ namespace YAML
|
||||
Node& Top();
|
||||
void Pop();
|
||||
|
||||
void Insert(std::auto_ptr<Node> pNode);
|
||||
void RegisterAnchor(anchor_t anchor, const Node& node);
|
||||
void Insert(Node& node);
|
||||
void RegisterAnchor(anchor_t anchor, Node& node);
|
||||
|
||||
private:
|
||||
Node& m_root;
|
||||
bool m_initializedRoot;
|
||||
bool m_finished;
|
||||
|
||||
ptr_stack<Node> m_stack;
|
||||
ptr_stack<Node> m_pendingKeys;
|
||||
std::stack<Node *> m_stack;
|
||||
std::stack<Node *> m_pendingKeys;
|
||||
std::stack<bool> m_didPushKey;
|
||||
|
||||
typedef std::vector<const Node *> Anchors;
|
||||
typedef std::vector<Node *> Anchors;
|
||||
Anchors m_anchors;
|
||||
};
|
||||
}
|
||||
|
31
src/nodeownership.cpp
Normal file
31
src/nodeownership.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "nodeownership.h"
|
||||
#include "yaml-cpp/node.h"
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
NodeOwnership::NodeOwnership(NodeOwnership *pOwner): m_pOwner(pOwner)
|
||||
{
|
||||
if(!m_pOwner)
|
||||
m_pOwner = this;
|
||||
}
|
||||
|
||||
NodeOwnership::~NodeOwnership()
|
||||
{
|
||||
}
|
||||
|
||||
Node& NodeOwnership::_Create()
|
||||
{
|
||||
m_nodes.push_back(std::auto_ptr<Node>(new Node));
|
||||
return m_nodes.back();
|
||||
}
|
||||
|
||||
void NodeOwnership::_MarkAsAliased(const Node& node)
|
||||
{
|
||||
m_aliasedNodes.insert(&node);
|
||||
}
|
||||
|
||||
bool NodeOwnership::_IsAliased(const Node& node) const
|
||||
{
|
||||
return m_aliasedNodes.count(&node) > 0;
|
||||
}
|
||||
}
|
39
src/nodeownership.h
Normal file
39
src/nodeownership.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef NODE_OWNERSHIP_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
#define NODE_OWNERSHIP_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include "yaml-cpp/noncopyable.h"
|
||||
#include "ptr_vector.h"
|
||||
#include <set>
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
class Node;
|
||||
|
||||
class NodeOwnership: private noncopyable
|
||||
{
|
||||
public:
|
||||
explicit NodeOwnership(NodeOwnership *pOwner = 0);
|
||||
~NodeOwnership();
|
||||
|
||||
Node& Create() { return m_pOwner->_Create(); }
|
||||
void MarkAsAliased(const Node& node) { m_pOwner->_MarkAsAliased(node); }
|
||||
bool IsAliased(const Node& node) const { return m_pOwner->_IsAliased(node); }
|
||||
|
||||
private:
|
||||
Node& _Create();
|
||||
void _MarkAsAliased(const Node& node);
|
||||
bool _IsAliased(const Node& node) const;
|
||||
|
||||
private:
|
||||
ptr_vector<Node> m_nodes;
|
||||
std::set<const Node *> m_aliasedNodes;
|
||||
NodeOwnership *m_pOwner;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NODE_OWNERSHIP_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
45
src/ptr_vector.h
Normal file
45
src/ptr_vector.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#ifndef PTR_VECTOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
#define PTR_VECTOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "yaml-cpp/noncopyable.h"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace YAML {
|
||||
|
||||
template <typename T>
|
||||
class ptr_vector: private YAML::noncopyable
|
||||
{
|
||||
public:
|
||||
ptr_vector() {}
|
||||
~ptr_vector() { clear(); }
|
||||
|
||||
void clear() {
|
||||
for(unsigned i=0;i<m_data.size();i++)
|
||||
delete m_data[i];
|
||||
m_data.clear();
|
||||
}
|
||||
|
||||
std::size_t size() const { return m_data.size(); }
|
||||
bool empty() const { return m_data.empty(); }
|
||||
|
||||
void push_back(std::auto_ptr<T> t) {
|
||||
m_data.push_back(NULL);
|
||||
m_data.back() = t.release();
|
||||
}
|
||||
T& operator[](std::size_t i) { return *m_data[i]; }
|
||||
const T& operator[](std::size_t i) const { return *m_data[i]; }
|
||||
|
||||
T& back() { return *m_data.back(); }
|
||||
const T& back() const { return *m_data.back(); }
|
||||
|
||||
private:
|
||||
std::vector<T*> m_data;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // PTR_VECTOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
@@ -1,34 +0,0 @@
|
||||
#include "scalar.h"
|
||||
#include "yaml-cpp/eventhandler.h"
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
Scalar::Scalar()
|
||||
{
|
||||
}
|
||||
|
||||
Scalar::~Scalar()
|
||||
{
|
||||
}
|
||||
|
||||
void Scalar::EmitEvents(AliasManager&, EventHandler& eventHandler, const Mark& mark, const std::string& tag, anchor_t anchor) const
|
||||
{
|
||||
eventHandler.OnScalar(mark, tag, anchor, m_data);
|
||||
}
|
||||
|
||||
int Scalar::Compare(Content *pContent)
|
||||
{
|
||||
return -pContent->Compare(this);
|
||||
}
|
||||
|
||||
int Scalar::Compare(Scalar *pScalar)
|
||||
{
|
||||
if(m_data < pScalar->m_data)
|
||||
return -1;
|
||||
else if(m_data > pScalar->m_data)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
43
src/scalar.h
43
src/scalar.h
@@ -1,43 +0,0 @@
|
||||
#ifndef SCALAR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
#define SCALAR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include "content.h"
|
||||
#include <string>
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
class Scalar: public Content
|
||||
{
|
||||
public:
|
||||
Scalar();
|
||||
virtual ~Scalar();
|
||||
|
||||
virtual void SetData(const std::string& data) { m_data = data; }
|
||||
|
||||
virtual bool IsScalar() const { return true; }
|
||||
virtual void EmitEvents(AliasManager& am, EventHandler& eventHandler, const Mark& mark, const std::string& tag, anchor_t anchor) const;
|
||||
|
||||
// extraction
|
||||
virtual bool GetScalar(std::string& scalar) const {
|
||||
scalar = m_data;
|
||||
return true;
|
||||
}
|
||||
|
||||
// ordering
|
||||
virtual int Compare(Content *pContent);
|
||||
virtual int Compare(Scalar *pScalar);
|
||||
virtual int Compare(Sequence *) { return -1; }
|
||||
virtual int Compare(Map *) { return -1; }
|
||||
|
||||
protected:
|
||||
std::string m_data;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // SCALAR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
@@ -1,83 +0,0 @@
|
||||
#include "sequence.h"
|
||||
#include "yaml-cpp/eventhandler.h"
|
||||
#include "yaml-cpp/node.h"
|
||||
#include <stdexcept>
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
Sequence::Sequence()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Sequence::~Sequence()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
void Sequence::Clear()
|
||||
{
|
||||
for(std::size_t i=0;i<m_data.size();i++)
|
||||
delete m_data[i];
|
||||
m_data.clear();
|
||||
}
|
||||
|
||||
bool Sequence::GetBegin(std::vector <Node *>::const_iterator& it) const
|
||||
{
|
||||
it = m_data.begin();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Sequence::GetEnd(std::vector <Node *>::const_iterator& it) const
|
||||
{
|
||||
it = m_data.end();
|
||||
return true;
|
||||
}
|
||||
|
||||
Node *Sequence::GetNode(std::size_t i) const
|
||||
{
|
||||
if(i < m_data.size())
|
||||
return m_data[i];
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::size_t Sequence::GetSize() const
|
||||
{
|
||||
return m_data.size();
|
||||
}
|
||||
|
||||
void Sequence::Append(std::auto_ptr<Node> pNode)
|
||||
{
|
||||
m_data.push_back(pNode.release());
|
||||
}
|
||||
|
||||
void Sequence::EmitEvents(AliasManager& am, EventHandler& eventHandler, const Mark& mark, const std::string& tag, anchor_t anchor) const
|
||||
{
|
||||
eventHandler.OnSequenceStart(mark, tag, anchor);
|
||||
for(std::size_t i=0;i<m_data.size();i++)
|
||||
m_data[i]->EmitEvents(am, eventHandler);
|
||||
eventHandler.OnSequenceEnd();
|
||||
}
|
||||
|
||||
int Sequence::Compare(Content *pContent)
|
||||
{
|
||||
return -pContent->Compare(this);
|
||||
}
|
||||
|
||||
int Sequence::Compare(Sequence *pSeq)
|
||||
{
|
||||
std::size_t n = m_data.size(), m = pSeq->m_data.size();
|
||||
if(n < m)
|
||||
return -1;
|
||||
else if(n > m)
|
||||
return 1;
|
||||
|
||||
for(std::size_t i=0;i<n;i++) {
|
||||
int cmp = m_data[i]->Compare(*pSeq->m_data[i]);
|
||||
if(cmp != 0)
|
||||
return cmp;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
@@ -1,45 +0,0 @@
|
||||
#ifndef SEQUENCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
#define SEQUENCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include "content.h"
|
||||
#include <vector>
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
class Node;
|
||||
|
||||
class Sequence: public Content
|
||||
{
|
||||
public:
|
||||
Sequence();
|
||||
virtual ~Sequence();
|
||||
|
||||
void Clear();
|
||||
|
||||
virtual bool GetBegin(std::vector <Node *>::const_iterator& it) const;
|
||||
virtual bool GetEnd(std::vector <Node *>::const_iterator& it) const;
|
||||
virtual Node *GetNode(std::size_t i) const;
|
||||
virtual std::size_t GetSize() const;
|
||||
|
||||
virtual void Append(std::auto_ptr<Node> pNode);
|
||||
virtual void EmitEvents(AliasManager& am, EventHandler& eventHandler, const Mark& mark, const std::string& tag, anchor_t anchor) const;
|
||||
|
||||
virtual bool IsSequence() const { return true; }
|
||||
|
||||
// ordering
|
||||
virtual int Compare(Content *pContent);
|
||||
virtual int Compare(Scalar *) { return 1; }
|
||||
virtual int Compare(Sequence *pSeq);
|
||||
virtual int Compare(Map *) { return -1; }
|
||||
|
||||
protected:
|
||||
std::vector <Node *> m_data;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // SEQUENCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
@@ -48,7 +48,7 @@ namespace YAML
|
||||
{
|
||||
// an empty node *is* a possibility
|
||||
if(m_scanner.empty()) {
|
||||
eventHandler.OnNull("", NullAnchor);
|
||||
eventHandler.OnNull(Mark::null(), NullAnchor);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -112,7 +112,10 @@ namespace YAML
|
||||
break;
|
||||
}
|
||||
|
||||
eventHandler.OnNull(tag, anchor);
|
||||
if(tag == "?")
|
||||
eventHandler.OnNull(mark, anchor);
|
||||
else
|
||||
eventHandler.OnScalar(mark, tag, anchor, "");
|
||||
}
|
||||
|
||||
void SingleDocParser::HandleSequence(EventHandler& eventHandler)
|
||||
@@ -147,7 +150,7 @@ namespace YAML
|
||||
if(!m_scanner.empty()) {
|
||||
const Token& token = m_scanner.peek();
|
||||
if(token.type == Token::BLOCK_ENTRY || token.type == Token::BLOCK_SEQ_END) {
|
||||
eventHandler.OnNull("", NullAnchor);
|
||||
eventHandler.OnNull(token.mark, NullAnchor);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -224,7 +227,7 @@ namespace YAML
|
||||
m_scanner.pop();
|
||||
HandleNode(eventHandler);
|
||||
} else {
|
||||
eventHandler.OnNull("", NullAnchor);
|
||||
eventHandler.OnNull(token.mark, NullAnchor);
|
||||
}
|
||||
|
||||
// now grab value (optional)
|
||||
@@ -232,7 +235,7 @@ namespace YAML
|
||||
m_scanner.pop();
|
||||
HandleNode(eventHandler);
|
||||
} else {
|
||||
eventHandler.OnNull("", NullAnchor);
|
||||
eventHandler.OnNull(token.mark, NullAnchor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,7 +264,7 @@ namespace YAML
|
||||
m_scanner.pop();
|
||||
HandleNode(eventHandler);
|
||||
} else {
|
||||
eventHandler.OnNull("", NullAnchor);
|
||||
eventHandler.OnNull(token.mark, NullAnchor);
|
||||
}
|
||||
|
||||
// now grab value (optional)
|
||||
@@ -269,7 +272,7 @@ namespace YAML
|
||||
m_scanner.pop();
|
||||
HandleNode(eventHandler);
|
||||
} else {
|
||||
eventHandler.OnNull("", NullAnchor);
|
||||
eventHandler.OnNull(token.mark, NullAnchor);
|
||||
}
|
||||
|
||||
// now eat the separator (or could be a map end, which we ignore - but if it's neither, then it's a bad node)
|
||||
@@ -289,6 +292,7 @@ namespace YAML
|
||||
m_pCollectionStack->PushCollectionType(CollectionType::CompactMap);
|
||||
|
||||
// grab key
|
||||
Mark mark = m_scanner.peek().mark;
|
||||
m_scanner.pop();
|
||||
HandleNode(eventHandler);
|
||||
|
||||
@@ -297,7 +301,7 @@ namespace YAML
|
||||
m_scanner.pop();
|
||||
HandleNode(eventHandler);
|
||||
} else {
|
||||
eventHandler.OnNull("", NullAnchor);
|
||||
eventHandler.OnNull(mark, NullAnchor);
|
||||
}
|
||||
|
||||
m_pCollectionStack->PopCollectionType(CollectionType::CompactMap);
|
||||
@@ -309,7 +313,7 @@ namespace YAML
|
||||
m_pCollectionStack->PushCollectionType(CollectionType::CompactMap);
|
||||
|
||||
// null key
|
||||
eventHandler.OnNull("", NullAnchor);
|
||||
eventHandler.OnNull(m_scanner.peek().mark, NullAnchor);
|
||||
|
||||
// grab value
|
||||
m_scanner.pop();
|
||||
|
Reference in New Issue
Block a user