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:
@@ -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;
|
||||
|
||||
|
@@ -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) {
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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;
|
||||
|
||||
|
@@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
|
18
include/yaml-cpp/ltnode.h
Normal file
18
include/yaml-cpp/ltnode.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#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
|
@@ -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
|
||||
|
@@ -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>
|
||||
|
@@ -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
|
Reference in New Issue
Block a user