mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 20:51:16 +00:00
Started implementing node_data
This commit is contained in:
@@ -55,7 +55,11 @@ option(MSVC_STHREADED_RT "MSVC: Build with single-threaded static runtime libs (
|
|||||||
###
|
###
|
||||||
### Sources, headers, directories and libs
|
### Sources, headers, directories and libs
|
||||||
###
|
###
|
||||||
file(GLOB sources "src/[a-zA-Z]*.cpp")
|
file(GLOB sources
|
||||||
|
"src/[a-zA-Z]*.cpp"
|
||||||
|
"src/value/[a-zA-Z]*.cpp"
|
||||||
|
"src/value/detail/[a-zA-Z]*.cpp"
|
||||||
|
)
|
||||||
file(GLOB public_headers
|
file(GLOB public_headers
|
||||||
"include/yaml-cpp/[a-zA-Z]*.h"
|
"include/yaml-cpp/[a-zA-Z]*.h"
|
||||||
"include/yaml-cpp/value/[a-zA-Z]*.h"
|
"include/yaml-cpp/value/[a-zA-Z]*.h"
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "yaml-cpp/dll.h"
|
#include "yaml-cpp/dll.h"
|
||||||
|
#include "yaml-cpp/value/type.h"
|
||||||
#include "yaml-cpp/value/ptr.h"
|
#include "yaml-cpp/value/ptr.h"
|
||||||
#include "yaml-cpp/value/detail/node_data.h"
|
#include "yaml-cpp/value/detail/node_data.h"
|
||||||
|
|
||||||
@@ -19,6 +20,7 @@ namespace YAML
|
|||||||
public:
|
public:
|
||||||
node();
|
node();
|
||||||
|
|
||||||
|
ValueType::value type() const;
|
||||||
void assign_data(const node& rhs);
|
void assign_data(const node& rhs);
|
||||||
void set_scalar(const std::string& data);
|
void set_scalar(const std::string& data);
|
||||||
|
|
||||||
@@ -30,6 +32,11 @@ namespace YAML
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline ValueType::value node::type() const
|
||||||
|
{
|
||||||
|
return m_pData ? m_pData->type() : ValueType::Null;
|
||||||
|
}
|
||||||
|
|
||||||
inline void node::assign_data(const node& rhs)
|
inline void node::assign_data(const node& rhs)
|
||||||
{
|
{
|
||||||
m_pData = rhs.m_pData;
|
m_pData = rhs.m_pData;
|
||||||
|
@@ -7,7 +7,10 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "yaml-cpp/dll.h"
|
#include "yaml-cpp/dll.h"
|
||||||
|
#include "yaml-cpp/value/type.h"
|
||||||
#include "yaml-cpp/value/ptr.h"
|
#include "yaml-cpp/value/ptr.h"
|
||||||
|
#include <pair>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML
|
||||||
{
|
{
|
||||||
@@ -16,7 +19,25 @@ namespace YAML
|
|||||||
class node_data
|
class node_data
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit node_data(const std::string& data) {}
|
explicit node_data(const std::string& scalar);
|
||||||
|
|
||||||
|
ValueType::value type() const { return m_type; }
|
||||||
|
const std::string scalar() const { return m_data; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
ValueType::value m_type;
|
||||||
|
|
||||||
|
// scalar
|
||||||
|
std::string m_scalar;
|
||||||
|
|
||||||
|
// sequence
|
||||||
|
typedef std::vector<shared_node> node_seq;
|
||||||
|
node_seq m_sequence;
|
||||||
|
|
||||||
|
// map
|
||||||
|
typedef std::pair<shared_node, shared_node> kv_pair;
|
||||||
|
typedef std::vector<kv_pair> node_map;
|
||||||
|
node_map m_map;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -14,6 +14,7 @@ namespace YAML
|
|||||||
{
|
{
|
||||||
inline Value::Value(): m_pMemory(new detail::memory_holder)
|
inline Value::Value(): m_pMemory(new detail::memory_holder)
|
||||||
{
|
{
|
||||||
|
EnsureNodeExists();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -30,6 +31,11 @@ namespace YAML
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline ValueType::value Value::Type() const
|
||||||
|
{
|
||||||
|
return m_pNode ? m_pNode->type() : ValueType::Undefined;
|
||||||
|
}
|
||||||
|
|
||||||
// access
|
// access
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline const T Value::as() const
|
inline const T Value::as() const
|
||||||
|
14
include/yaml-cpp/value/type.h
Normal file
14
include/yaml-cpp/value/type.h
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#ifndef VALUE_TYPE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
#define VALUE_TYPE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
||||||
|
#pragma once
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
namespace YAML
|
||||||
|
{
|
||||||
|
struct ValueType { enum value { Undefined, Null, Scalar, Sequence, Map }; };
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // VALUE_TYPE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
@@ -7,14 +7,13 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "yaml-cpp/dll.h"
|
#include "yaml-cpp/dll.h"
|
||||||
#include "yaml-cpp/value/ptr.h"
|
|
||||||
#include "yaml-cpp/value/iterator.h"
|
#include "yaml-cpp/value/iterator.h"
|
||||||
|
#include "yaml-cpp/value/ptr.h"
|
||||||
|
#include "yaml-cpp/value/type.h"
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML
|
||||||
{
|
{
|
||||||
struct ValueType { enum value { Undefined, Null, Scalar, Sequence, Map }; };
|
|
||||||
|
|
||||||
class Value
|
class Value
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
11
src/value/detail/node_data.cpp
Normal file
11
src/value/detail/node_data.cpp
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#include "yaml-cpp/value/detail/node_data.h"
|
||||||
|
|
||||||
|
namespace YAML
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
node_data::node_data(const std::string& scalar): m_type(ValueType::Scalar), m_scalar(scalar)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -3,7 +3,7 @@
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
YAML::Value value;
|
YAML::Value value;
|
||||||
value = "Hello";
|
value["key"] = "value";
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user