Merged r444:449 from the node refactoring branch to the trunk

This commit is contained in:
Jesse Beder
2011-03-03 00:19:26 +00:00
parent ced50538fe
commit ca5992b971
35 changed files with 421 additions and 860 deletions

View File

@@ -18,18 +18,12 @@ namespace YAML
AliasManager();
void RegisterReference(const Node& node);
const Node *LookupReference(const Node& node) const;
anchor_t LookupAnchor(const Node& node) const;
private:
const Node *_LookupReference(const Node& oldIdentity) const;
anchor_t _CreateNewAnchor();
private:
typedef std::map<const Node*, const Node*> NodeByNode;
NodeByNode m_newIdentityByOldIdentity;
typedef std::map<const Node*, anchor_t> AnchorByIdentity;
AnchorByIdentity m_anchorByIdentity;

View File

@@ -20,7 +20,7 @@ namespace YAML
{
public:
// Create and return a new node with a null value.
virtual void *NewNull(const std::string& tag, void *pParentNode) = 0;
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, void *pParentNode, const std::string& value) = 0;
@@ -74,8 +74,8 @@ namespace YAML
GraphBuilderInterface& AsBuilderInterface() {return *this;}
virtual void *NewNull(const std::string& tag, void* pParentNode) {
return CheckType<Node>(m_impl.NewNull(tag, AsNode(pParentNode)));
virtual void *NewNull(const Mark& mark, void* pParentNode) {
return CheckType<Node>(m_impl.NewNull(mark, AsNode(pParentNode)));
}
virtual void *NewScalar(const Mark& mark, const std::string& tag, void *pParentNode, const std::string& value) {

View File

@@ -20,7 +20,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);

View File

@@ -20,7 +20,7 @@ namespace YAML
virtual void OnDocumentStart(const Mark& mark) = 0;
virtual void OnDocumentEnd() = 0;
virtual void OnNull(const std::string& tag, anchor_t anchor) = 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;

View File

@@ -5,6 +5,7 @@
#pragma once
#endif
#include <memory>
namespace YAML
{
@@ -15,7 +16,7 @@ namespace YAML
{
public:
Iterator();
Iterator(IterPriv *pData);
Iterator(std::auto_ptr<IterPriv> pData);
Iterator(const Iterator& rhs);
~Iterator();
@@ -31,7 +32,7 @@ namespace YAML
friend bool operator != (const Iterator& it, const Iterator& jt);
private:
IterPriv *m_pData;
std::auto_ptr<IterPriv> m_pData;
};
}

View File

@@ -9,28 +9,32 @@
#include "yaml-cpp/conversion.h"
#include "yaml-cpp/exceptions.h"
#include "yaml-cpp/iterator.h"
#include "yaml-cpp/ltnode.h"
#include "yaml-cpp/mark.h"
#include "yaml-cpp/noncopyable.h"
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <memory>
#include <string>
#include <vector>
namespace YAML
{
class AliasManager;
class Content;
class NodeOwnership;
class Scanner;
class Emitter;
class EventHandler;
struct NodeProperties;
enum CONTENT_TYPE { CT_NONE, CT_SCALAR, CT_SEQUENCE, CT_MAP };
struct NodeType { enum value { Null, Scalar, Sequence, Map }; };
class Node: private noncopyable
{
public:
friend class NodeOwnership;
friend class NodeBuilder;
Node();
~Node();
@@ -38,16 +42,9 @@ namespace YAML
std::auto_ptr<Node> Clone() const;
void EmitEvents(EventHandler& eventHandler) const;
void EmitEvents(AliasManager& am, EventHandler& eventHandler) const;
void Init(CONTENT_TYPE type, const Mark& mark, const std::string& tag);
void InitNull(const std::string& tag);
void InitAlias(const Mark& mark, const Node& identity);
void SetData(const std::string& data);
void Append(std::auto_ptr<Node> pNode);
void Insert(std::auto_ptr<Node> pKey, std::auto_ptr<Node> pValue);
CONTENT_TYPE GetType() const { return m_type; }
NodeType::value Type() const { return m_type; }
bool IsAliased() const;
// file location of start of this node
const Mark GetMark() const { return m_mark; }
@@ -84,13 +81,8 @@ namespace YAML
const Node *FindValue(const char *key) const;
const Node& operator [] (const char *key) const;
// for anchors/aliases
const Node *Identity() const { return m_pIdentity; }
bool IsAlias() const { return m_alias; }
bool IsReferenced() const { return m_referenced; }
// for tags
const std::string GetTag() const { return IsAlias() ? m_pIdentity->GetTag() : m_tag; }
const std::string& Tag() const { return m_tag; }
// emitting
friend Emitter& operator << (Emitter& out, const Node& node);
@@ -100,6 +92,16 @@ namespace YAML
friend bool operator < (const Node& n1, const Node& n2);
private:
explicit Node(NodeOwnership& owner);
Node& CreateNode();
void Init(NodeType::value type, const Mark& mark, const std::string& tag);
void MarkAsAliased();
void SetScalarData(const std::string& data);
void Append(Node& node);
void Insert(Node& key, Node& value);
// helper for sequences
template <typename, bool> friend struct _FindFromNodeAtIndex;
const Node *FindAtIndex(std::size_t i) const;
@@ -112,13 +114,18 @@ namespace YAML
const Node *FindValueForKey(const T& key) const;
private:
std::auto_ptr<NodeOwnership> m_pOwnership;
Mark m_mark;
std::string m_tag;
CONTENT_TYPE m_type;
Content *m_pContent;
bool m_alias;
const Node *m_pIdentity;
mutable bool m_referenced;
typedef std::vector<Node *> node_seq;
typedef std::map<Node *, Node *, ltnode> node_map;
NodeType::value m_type;
std::string m_scalarData;
node_seq m_seqData;
node_map m_mapData;
};
// comparisons with auto-conversion

View File

@@ -7,6 +7,7 @@
#include "yaml-cpp/nodeutil.h"
#include <cassert>
namespace YAML
{
@@ -31,14 +32,17 @@ namespace YAML
template <typename T>
inline const Node *Node::FindValue(const T& key) const {
switch(GetType()) {
case CT_MAP:
return FindValueForKey(key);
case CT_SEQUENCE:
switch(m_type) {
case NodeType::Null:
case NodeType::Scalar:
throw BadDereference();
case NodeType::Sequence:
return FindFromNodeAtIndex(*this, key);
default:
return 0;
case NodeType::Map:
return FindValueForKey(key);
}
assert(false);
throw BadDereference();
}
template <typename T>
@@ -56,14 +60,9 @@ namespace YAML
template <typename T>
inline const Node& Node::GetValue(const T& key) const {
if(!m_pContent)
throw BadDereference();
const Node *pValue = FindValue(key);
if(!pValue)
throw MakeTypedKeyNotFound(m_mark, key);
return *pValue;
if(const Node *pValue = FindValue(key))
return *pValue;
throw MakeTypedKeyNotFound(m_mark, key);
}
template <typename T>

View File

@@ -1,16 +0,0 @@
#ifndef NODEPROPERTIES_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define NODEPROPERTIES_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
{
struct NodeProperties {
std::string tag;
std::string anchor;
};
}
#endif // NODEPROPERTIES_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -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);
}
}

View File

@@ -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

View File

@@ -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;

View File

@@ -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
}
}

View File

@@ -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

View File

@@ -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);

View File

@@ -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);

View File

@@ -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)

View File

@@ -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 ++ ()

View File

@@ -6,7 +6,7 @@
#endif
#include "ltnode.h"
#include "yaml-cpp/ltnode.h"
#include <vector>
#include <map>

View File

@@ -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;
}
}

View File

@@ -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

View File

@@ -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)

View File

@@ -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());

View File

@@ -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
View 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
View 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
View 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

View File

@@ -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;
}
}

View File

@@ -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

View File

@@ -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;
}
}

View File

@@ -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

View File

@@ -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();

View File

@@ -698,7 +698,7 @@ namespace Test
YAML::Node doc;
parser.GetNextDocument(doc);
if(doc["a"] != 1)
if(doc["a"] != 4)
return false;
if(doc["b"] != 2)
return false;
@@ -729,10 +729,10 @@ namespace Test
bool ExpectedTagValue(YAML::Node& node, const char* tag)
{
if(node.GetTag() == tag)
if(node.Tag() == tag)
return true;
throw TagMismatch(node.GetTag(), tag);
throw TagMismatch(node.Tag(), tag);
}
bool DefaultPlainScalarTag()

View File

@@ -481,16 +481,16 @@ namespace Test {
PARSE(doc, input);
YAML_ASSERT(doc.size() == 3);
YAML_ASSERT(doc["not-date"].GetTag() == "tag:yaml.org,2002:str");
YAML_ASSERT(doc["not-date"].Tag() == "tag:yaml.org,2002:str");
YAML_ASSERT(doc["not-date"] == "2002-04-28");
YAML_ASSERT(doc["picture"].GetTag() == "tag:yaml.org,2002:binary");
YAML_ASSERT(doc["picture"].Tag() == "tag:yaml.org,2002:binary");
YAML_ASSERT(doc["picture"] ==
"R0lGODlhDAAMAIQAAP//9/X\n"
"17unp5WZmZgAAAOfn515eXv\n"
"Pz7Y6OjuDg4J+fn5OTk6enp\n"
"56enmleECcgggoBADs=\n"
);
YAML_ASSERT(doc["application specific tag"].GetTag() == "!something");
YAML_ASSERT(doc["application specific tag"].Tag() == "!something");
YAML_ASSERT(doc["application specific tag"] ==
"The semantics of the tag\n"
"above may be different for\n"
@@ -519,15 +519,15 @@ namespace Test {
" text: Pretty vector drawing.";
PARSE(doc, input);
YAML_ASSERT(doc.GetTag() == "tag:clarkevans.com,2002:shape");
YAML_ASSERT(doc.Tag() == "tag:clarkevans.com,2002:shape");
YAML_ASSERT(doc.size() == 3);
YAML_ASSERT(doc[0].GetTag() == "tag:clarkevans.com,2002:circle");
YAML_ASSERT(doc[0].Tag() == "tag:clarkevans.com,2002:circle");
YAML_ASSERT(doc[0].size() == 2);
YAML_ASSERT(doc[0]["center"].size() == 2);
YAML_ASSERT(doc[0]["center"]["x"] == 73);
YAML_ASSERT(doc[0]["center"]["y"] == 129);
YAML_ASSERT(doc[0]["radius"] == 7);
YAML_ASSERT(doc[1].GetTag() == "tag:clarkevans.com,2002:line");
YAML_ASSERT(doc[1].Tag() == "tag:clarkevans.com,2002:line");
YAML_ASSERT(doc[1].size() == 2);
YAML_ASSERT(doc[1]["start"].size() == 2);
YAML_ASSERT(doc[1]["start"]["x"] == 73);
@@ -535,7 +535,7 @@ namespace Test {
YAML_ASSERT(doc[1]["finish"].size() == 2);
YAML_ASSERT(doc[1]["finish"]["x"] == 89);
YAML_ASSERT(doc[1]["finish"]["y"] == 102);
YAML_ASSERT(doc[2].GetTag() == "tag:clarkevans.com,2002:label");
YAML_ASSERT(doc[2].Tag() == "tag:clarkevans.com,2002:label");
YAML_ASSERT(doc[2].size() == 3);
YAML_ASSERT(doc[2]["start"].size() == 2);
YAML_ASSERT(doc[2]["start"]["x"] == 73);
@@ -558,7 +558,7 @@ namespace Test {
"? Ken Griffey";
PARSE(doc, input);
YAML_ASSERT(doc.GetTag() == "tag:yaml.org,2002:set");
YAML_ASSERT(doc.Tag() == "tag:yaml.org,2002:set");
YAML_ASSERT(doc.size() == 3);
YAML_ASSERT(IsNull(doc["Mark McGwire"]));
YAML_ASSERT(IsNull(doc["Sammy Sosa"]));
@@ -579,7 +579,7 @@ namespace Test {
"- Ken Griffey: 58";
PARSE(doc, input);
YAML_ASSERT(doc.GetTag() == "tag:yaml.org,2002:omap");
YAML_ASSERT(doc.Tag() == "tag:yaml.org,2002:omap");
YAML_ASSERT(doc.size() == 3);
YAML_ASSERT(doc[0].size() == 1);
YAML_ASSERT(doc[0]["Mark McGwire"] == 65);
@@ -625,7 +625,7 @@ namespace Test {
" Billsmer @ 338-4338.";
PARSE(doc, input);
YAML_ASSERT(doc.GetTag() == "tag:clarkevans.com,2002:invoice");
YAML_ASSERT(doc.Tag() == "tag:clarkevans.com,2002:invoice");
YAML_ASSERT(doc.size() == 8);
YAML_ASSERT(doc["invoice"] == 34843);
YAML_ASSERT(doc["date"] == "2001-01-23");
@@ -1185,7 +1185,7 @@ namespace Test {
"!yaml!str \"foo\"";
PARSE(doc, input);
YAML_ASSERT(doc.GetTag() == "tag:yaml.org,2002:str");
YAML_ASSERT(doc.Tag() == "tag:yaml.org,2002:str");
YAML_ASSERT(doc == "foo");
return true;
}
@@ -1223,11 +1223,11 @@ namespace Test {
"!foo \"bar\"";
PARSE(doc, input);
YAML_ASSERT(doc.GetTag() == "!foo");
YAML_ASSERT(doc.Tag() == "!foo");
YAML_ASSERT(doc == "bar");
PARSE_NEXT(doc);
YAML_ASSERT(doc.GetTag() == "tag:example.com,2000:app/foo");
YAML_ASSERT(doc.Tag() == "tag:example.com,2000:app/foo");
YAML_ASSERT(doc == "bar");
return true;
}
@@ -1241,7 +1241,7 @@ namespace Test {
"!!int 1 - 3 # Interval, not integer";
PARSE(doc, input);
YAML_ASSERT(doc.GetTag() == "tag:example.com,2000:app/int");
YAML_ASSERT(doc.Tag() == "tag:example.com,2000:app/int");
YAML_ASSERT(doc == "1 - 3");
return true;
}
@@ -1255,7 +1255,7 @@ namespace Test {
"!e!foo \"bar\"";
PARSE(doc, input);
YAML_ASSERT(doc.GetTag() == "tag:example.com,2000:app/foo");
YAML_ASSERT(doc.Tag() == "tag:example.com,2000:app/foo");
YAML_ASSERT(doc == "bar");
return true;
}
@@ -1273,11 +1273,11 @@ namespace Test {
"!m!light green";
PARSE(doc, input);
YAML_ASSERT(doc.GetTag() == "!my-light");
YAML_ASSERT(doc.Tag() == "!my-light");
YAML_ASSERT(doc == "fluorescent");
PARSE_NEXT(doc);
YAML_ASSERT(doc.GetTag() == "!my-light");
YAML_ASSERT(doc.Tag() == "!my-light");
YAML_ASSERT(doc == "green");
return true;
}
@@ -1292,7 +1292,7 @@ namespace Test {
PARSE(doc, input);
YAML_ASSERT(doc.size() == 1);
YAML_ASSERT(doc[0].GetTag() == "tag:example.com,2000:app/foo");
YAML_ASSERT(doc[0].Tag() == "tag:example.com,2000:app/foo");
YAML_ASSERT(doc[0] == "bar");
return true;
}
@@ -1309,8 +1309,8 @@ namespace Test {
YAML_ASSERT(doc.size() == 2);
for(YAML::Iterator it=doc.begin();it!=doc.end();++it) {
if(it.first() == "foo") {
YAML_ASSERT(it.first().GetTag() == "tag:yaml.org,2002:str");
YAML_ASSERT(it.second().GetTag() == "tag:yaml.org,2002:str");
YAML_ASSERT(it.first().Tag() == "tag:yaml.org,2002:str");
YAML_ASSERT(it.second().Tag() == "tag:yaml.org,2002:str");
YAML_ASSERT(it.second() == "bar");
} else if(it.first() == "baz") {
YAML_ASSERT(it.second() == "foo");
@@ -1331,9 +1331,9 @@ namespace Test {
PARSE(doc, input);
YAML_ASSERT(doc.size() == 1);
for(YAML::Iterator it=doc.begin();it!=doc.end();++it) {
YAML_ASSERT(it.first().GetTag() == "tag:yaml.org,2002:str");
YAML_ASSERT(it.first().Tag() == "tag:yaml.org,2002:str");
YAML_ASSERT(it.first() == "foo");
YAML_ASSERT(it.second().GetTag() == "!bar");
YAML_ASSERT(it.second().Tag() == "!bar");
YAML_ASSERT(it.second() == "baz");
}
return true;
@@ -1362,11 +1362,11 @@ namespace Test {
PARSE(doc, input);
YAML_ASSERT(doc.size() == 3);
YAML_ASSERT(doc[0].GetTag() == "!local");
YAML_ASSERT(doc[0].Tag() == "!local");
YAML_ASSERT(doc[0] == "foo");
YAML_ASSERT(doc[1].GetTag() == "tag:yaml.org,2002:str");
YAML_ASSERT(doc[1].Tag() == "tag:yaml.org,2002:str");
YAML_ASSERT(doc[1] == "bar");
YAML_ASSERT(doc[2].GetTag() == "tag:example.com,2000:app/tag%21");
YAML_ASSERT(doc[2].Tag() == "tag:example.com,2000:app/tag%21");
YAML_ASSERT(doc[2] == "baz");
return true;
}
@@ -1462,10 +1462,10 @@ namespace Test {
YAML_ASSERT(doc.size() == 2);
for(YAML::Iterator it=doc.begin();it!=doc.end();++it) {
if(it.first() == "foo") {
YAML_ASSERT(it.second().GetTag() == "tag:yaml.org,2002:str");
YAML_ASSERT(it.second().Tag() == "tag:yaml.org,2002:str");
YAML_ASSERT(it.second() == "");
} else if(it.first() == "") {
YAML_ASSERT(it.first().GetTag() == "tag:yaml.org,2002:str");
YAML_ASSERT(it.first().Tag() == "tag:yaml.org,2002:str");
YAML_ASSERT(it.second() == "bar");
} else
return " unexpected key";
@@ -1862,12 +1862,12 @@ namespace Test {
PARSE(doc, input);
YAML_ASSERT(doc.size() == 5);
YAML_ASSERT(doc[0].GetTag() == "tag:yaml.org,2002:str");
YAML_ASSERT(doc[0].Tag() == "tag:yaml.org,2002:str");
YAML_ASSERT(doc[0] == "a");
YAML_ASSERT(doc[1] == 'b');
YAML_ASSERT(doc[2] == "c");
YAML_ASSERT(doc[3] == "c");
YAML_ASSERT(doc[4].GetTag() == "tag:yaml.org,2002:str");
YAML_ASSERT(doc[4].Tag() == "tag:yaml.org,2002:str");
YAML_ASSERT(doc[4] == "");
return true;
}

View File

@@ -23,7 +23,7 @@ public:
virtual void OnDocumentStart(const YAML::Mark&) {}
virtual void OnDocumentEnd() {}
virtual void OnNull(const std::string&, YAML::anchor_t) {}
virtual void OnNull(const YAML::Mark&, YAML::anchor_t) {}
virtual void OnAlias(const YAML::Mark&, YAML::anchor_t) {}
virtual void OnScalar(const YAML::Mark&, const std::string&, YAML::anchor_t, const std::string&) {}