Added tags to Node

This commit is contained in:
beder
2011-09-13 14:00:47 -05:00
parent 535f81a387
commit 8dcd96dbd2
7 changed files with 35 additions and 7 deletions

View File

@@ -26,7 +26,7 @@ namespace YAML
static bool decode(const Node& node, std::string& rhs) {
if(node.Type() != NodeType::Scalar)
return false;
rhs = node.scalar();
rhs = node.Scalar();
return true;
}
};
@@ -54,7 +54,7 @@ namespace YAML
static bool decode(const Node& node, type& rhs) {\
if(node.Type() != NodeType::Scalar)\
return false;\
std::stringstream stream(node.scalar());\
std::stringstream stream(node.Scalar());\
stream >> rhs;\
return !!stream;\
}\

View File

@@ -29,6 +29,7 @@ namespace YAML
NodeType::value type() const { return m_pRef->type(); }
const std::string& scalar() const { return m_pRef->scalar(); }
const std::string& tag() const { return m_pRef->tag(); }
void mark_defined() {
if(is_defined())
@@ -71,6 +72,10 @@ namespace YAML
mark_defined();
m_pRef->set_scalar(scalar);
}
void set_tag(const std::string& tag) {
mark_defined();
m_pRef->set_tag(tag);
}
// size/iterator
std::size_t size() const { return m_pRef->size(); }

View File

@@ -26,12 +26,14 @@ namespace YAML
void mark_defined();
void set_type(NodeType::value type);
void set_tag(const std::string& tag);
void set_null();
void set_scalar(const std::string& scalar);
bool is_defined() const { return m_isDefined; }
NodeType::value type() const { return m_isDefined ? m_type : NodeType::Undefined; }
const std::string& scalar() const { return m_scalar; }
const std::string& tag() const { return m_tag; }
// size/iterator
std::size_t size() const;
@@ -78,6 +80,7 @@ namespace YAML
private:
bool m_isDefined;
NodeType::value m_type;
std::string m_tag;
// scalar
std::string m_scalar;

View File

@@ -24,11 +24,13 @@ namespace YAML
bool is_defined() const { return m_pData->is_defined(); }
NodeType::value type() const { return m_pData->type(); }
const std::string& scalar() const { return m_pData->scalar(); }
const std::string& tag() const { return m_pData->tag(); }
void mark_defined() { m_pData->mark_defined(); }
void set_data(const node_ref& rhs) { m_pData = rhs.m_pData; }
void set_type(NodeType::value type) { m_pData->set_type(type); }
void set_tag(const std::string& tag) { m_pData->set_tag(tag); }
void set_null() { m_pData->set_null(); }
void set_scalar(const std::string& scalar) { m_pData->set_scalar(scalar); }

View File

@@ -73,14 +73,25 @@ namespace YAML
{
if(Type() != NodeType::Scalar)
throw std::runtime_error("Unable to convert to string, not a scalar");
return scalar();
return Scalar();
}
inline const std::string& Node::scalar() const
inline const std::string& Node::Scalar() const
{
return m_pNode ? m_pNode->scalar() : detail::node_data::empty_scalar;
}
inline const std::string& Node::Tag() const
{
return m_pNode ? m_pNode->tag() : detail::node_data::empty_scalar;
}
inline void Node::SetTag(const std::string& tag)
{
EnsureNodeExists();
m_pNode->set_tag(tag);
}
// assignment
inline bool Node::is(const Node& rhs) const
{

View File

@@ -32,7 +32,9 @@ namespace YAML
// access
template<typename T> const T as() const;
const std::string& scalar() const;
const std::string& Scalar() const;
const std::string& Tag() const;
void SetTag(const std::string& tag);
// assignment
bool is(const Node& rhs) const;

View File

@@ -54,6 +54,11 @@ namespace YAML
}
}
void node_data::set_tag(const std::string& tag)
{
m_tag = tag;
}
void node_data::set_null()
{
m_isDefined = true;