Started implementing node_data

This commit is contained in:
beder
2011-09-07 00:45:28 -05:00
parent 555cfae28d
commit a07642f156
8 changed files with 68 additions and 6 deletions

View File

@@ -55,7 +55,11 @@ option(MSVC_STHREADED_RT "MSVC: Build with single-threaded static runtime 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
"include/yaml-cpp/[a-zA-Z]*.h"
"include/yaml-cpp/value/[a-zA-Z]*.h"

View File

@@ -7,6 +7,7 @@
#include "yaml-cpp/dll.h"
#include "yaml-cpp/value/type.h"
#include "yaml-cpp/value/ptr.h"
#include "yaml-cpp/value/detail/node_data.h"
@@ -19,6 +20,7 @@ namespace YAML
public:
node();
ValueType::value type() const;
void assign_data(const node& rhs);
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)
{
m_pData = rhs.m_pData;

View File

@@ -7,7 +7,10 @@
#include "yaml-cpp/dll.h"
#include "yaml-cpp/value/type.h"
#include "yaml-cpp/value/ptr.h"
#include <pair>
#include <vector>
namespace YAML
{
@@ -16,7 +19,25 @@ namespace YAML
class node_data
{
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;
};
}
}

View File

@@ -14,6 +14,7 @@ namespace YAML
{
inline Value::Value(): m_pMemory(new detail::memory_holder)
{
EnsureNodeExists();
}
template<typename T>
@@ -30,6 +31,11 @@ namespace YAML
{
}
inline ValueType::value Value::Type() const
{
return m_pNode ? m_pNode->type() : ValueType::Undefined;
}
// access
template<typename T>
inline const T Value::as() const

View 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

View File

@@ -7,14 +7,13 @@
#include "yaml-cpp/dll.h"
#include "yaml-cpp/value/ptr.h"
#include "yaml-cpp/value/iterator.h"
#include "yaml-cpp/value/ptr.h"
#include "yaml-cpp/value/type.h"
#include <stdexcept>
namespace YAML
{
struct ValueType { enum value { Undefined, Null, Scalar, Sequence, Map }; };
class Value
{
public:

View 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)
{
}
}
}

View File

@@ -3,7 +3,7 @@
int main()
{
YAML::Value value;
value = "Hello";
value["key"] = "value";
return 0;
}