Add flow/block style setting on Nodes

This commit is contained in:
Jesse Beder
2015-01-24 13:11:43 -06:00
parent 9880b608b9
commit 0c280724e9
13 changed files with 252 additions and 84 deletions

View File

@@ -7,6 +7,7 @@
#pragma once
#endif
#include "yaml-cpp/emitterstyle.h"
#include "yaml-cpp/dll.h"
#include "yaml-cpp/node/type.h"
#include "yaml-cpp/node/ptr.h"
@@ -28,6 +29,7 @@ class node : private boost::noncopyable {
const std::string& scalar() const { return m_pRef->scalar(); }
const std::string& tag() const { return m_pRef->tag(); }
EmitterStyle::value style() const { return m_pRef->style(); }
void mark_defined() {
if (is_defined())
@@ -76,6 +78,12 @@ class node : private boost::noncopyable {
m_pRef->set_tag(tag);
}
// style
void set_style(EmitterStyle::value style) {
mark_defined();
m_pRef->set_style(style);
}
// size/iterator
std::size_t size() const { return m_pRef->size(); }

View File

@@ -38,6 +38,7 @@ class YAML_CPP_API node_data : private boost::noncopyable {
void set_tag(const std::string& tag);
void set_null();
void set_scalar(const std::string& scalar);
void set_style(EmitterStyle::value style);
bool is_defined() const { return m_isDefined; }
NodeType::value type() const {
@@ -45,6 +46,7 @@ class YAML_CPP_API node_data : private boost::noncopyable {
}
const std::string& scalar() const { return m_scalar; }
const std::string& tag() const { return m_tag; }
EmitterStyle::value style() const { return m_style; }
// size/iterator
std::size_t size() const;
@@ -101,6 +103,7 @@ class YAML_CPP_API node_data : private boost::noncopyable {
bool m_isDefined;
NodeType::value m_type;
std::string m_tag;
EmitterStyle::value m_style;
// scalar
std::string m_scalar;

View File

@@ -23,6 +23,7 @@ class node_ref : private boost::noncopyable {
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(); }
EmitterStyle::value style() const { return m_pData->style(); }
void mark_defined() { m_pData->mark_defined(); }
void set_data(const node_ref& rhs) { m_pData = rhs.m_pData; }
@@ -31,6 +32,7 @@ class node_ref : private boost::noncopyable {
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); }
void set_style(EmitterStyle::value style) { m_pData->set_style(style); }
// size/iterator
std::size_t size() const { return m_pData->size(); }

View File

@@ -164,6 +164,19 @@ inline void Node::SetTag(const std::string& tag) {
m_pNode->set_tag(tag);
}
inline EmitterStyle::value Node::Style() const {
if (!m_isValid)
throw InvalidNode();
return m_pNode ? m_pNode->style() : EmitterStyle::Default;
}
inline void Node::SetStyle(EmitterStyle::value style) {
if (!m_isValid)
throw InvalidNode();
EnsureNodeExists();
m_pNode->set_style(style);
}
// assignment
inline bool Node::is(const Node& rhs) const {
if (!m_isValid || !rhs.m_isValid)

View File

@@ -10,6 +10,7 @@
#include <stdexcept>
#include "yaml-cpp/dll.h"
#include "yaml-cpp/emitterstyle.h"
#include "yaml-cpp/node/detail/bool_type.h"
#include "yaml-cpp/node/detail/iterator_fwd.h"
#include "yaml-cpp/node/ptr.h"
@@ -63,9 +64,15 @@ class YAML_CPP_API Node {
template <typename T, typename S>
const T as(const S& fallback) const;
const std::string& Scalar() const;
const std::string& Tag() const;
void SetTag(const std::string& tag);
// style
// WARNING: This API might change in future releases.
EmitterStyle::value Style() const;
void SetStyle(EmitterStyle::value style);
// assignment
bool is(const Node& rhs) const;
template <typename T>