mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 12:41:17 +00:00
Implemented conversion for std::string, including a bypass-accessor to the scalar value
This commit is contained in:
@@ -20,9 +20,10 @@ namespace YAML
|
||||
public:
|
||||
explicit node(shared_node_ref pRef): m_pRef(pRef) {}
|
||||
|
||||
ValueType::value type() const { return m_pRef->type(); }
|
||||
|
||||
bool is(const node& rhs) const { return m_pRef == rhs.m_pRef; }
|
||||
ValueType::value type() const { return m_pRef->type(); }
|
||||
|
||||
const std::string& scalar() const { return m_pRef->scalar(); }
|
||||
|
||||
void set_ref(const node& rhs) { m_pRef = rhs.m_pRef; }
|
||||
void set_data(const node& rhs) { m_pRef->set_data(*rhs.m_pRef); }
|
||||
|
@@ -27,7 +27,7 @@ namespace YAML
|
||||
void set_scalar(const std::string& scalar);
|
||||
|
||||
ValueType::value type() const { return m_isDefined ? m_type : ValueType::Undefined; }
|
||||
const std::string scalar() const { return m_scalar; }
|
||||
const std::string& scalar() const { return m_scalar; }
|
||||
|
||||
// indexing
|
||||
template<typename Key> shared_node get(const Key& key, shared_memory_holder pMemory) const;
|
||||
|
@@ -21,6 +21,7 @@ namespace YAML
|
||||
node_ref(): m_pData(new node_data) {}
|
||||
|
||||
ValueType::value type() const { return m_pData->type(); }
|
||||
const std::string& scalar() const { return m_pData->scalar(); }
|
||||
|
||||
void set_data(const node_ref& rhs) { m_pData = rhs.m_pData; }
|
||||
|
||||
|
@@ -56,6 +56,19 @@ namespace YAML
|
||||
throw std::runtime_error("Unable to convert to type");
|
||||
}
|
||||
|
||||
template<>
|
||||
inline const std::string Value::as() const
|
||||
{
|
||||
if(Type() != ValueType::Scalar)
|
||||
throw std::runtime_error("Unable to convert to string, not a scalar");
|
||||
return scalar();
|
||||
}
|
||||
|
||||
inline const std::string& Value::scalar() const
|
||||
{
|
||||
return m_pNode->scalar();
|
||||
}
|
||||
|
||||
// assignment
|
||||
inline bool Value::is(const Value& rhs) const
|
||||
{
|
||||
|
@@ -29,6 +29,7 @@ namespace YAML
|
||||
|
||||
// access
|
||||
template<typename T> const T as() const;
|
||||
const std::string& scalar() const;
|
||||
|
||||
// assignment
|
||||
bool is(const Value& rhs) const;
|
||||
|
Reference in New Issue
Block a user