Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
yaml-cpp
Commits
248b18a2
Commit
248b18a2
authored
Sep 06, 2011
by
Jesse Beder
Browse files
Sketched more of the implementation
parent
7e79edc0
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
339 additions
and
6 deletions
+339
-6
CMakeLists.txt
CMakeLists.txt
+5
-1
include/yaml-cpp/value/detail/memory.h
include/yaml-cpp/value/detail/memory.h
+71
-0
include/yaml-cpp/value/detail/node.h
include/yaml-cpp/value/detail/node.h
+44
-0
include/yaml-cpp/value/detail/nodedata.h
include/yaml-cpp/value/detail/nodedata.h
+0
-0
include/yaml-cpp/value/impl.h
include/yaml-cpp/value/impl.h
+168
-0
include/yaml-cpp/value/ptr.h
include/yaml-cpp/value/ptr.h
+27
-0
include/yaml-cpp/value/value.h
include/yaml-cpp/value/value.h
+24
-5
No files found.
CMakeLists.txt
View file @
248b18a2
...
...
@@ -56,7 +56,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 public_headers
"include/yaml-cpp/[a-zA-Z]*.h"
)
file
(
GLOB public_headers
"include/yaml-cpp/[a-zA-Z]*.h"
"include/yaml-cpp/value/[a-zA-Z]*.h"
"include/yaml-cpp/value/detail/[a-zA-Z]*.h"
)
file
(
GLOB private_headers
"src/[a-zA-Z]*.h"
)
if
(
YAML_CPP_BUILD_CONTRIB
)
...
...
include/yaml-cpp/value/detail/memory.h
0 → 100644
View file @
248b18a2
#ifndef VALUE_DETAIL_MEMORY_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define VALUE_DETAIL_MEMORY_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
#include "yaml-cpp/value/ptr.h"
#include <set>
#include <boost/shared_ptr.hpp>
namespace
YAML
{
namespace
detail
{
class
memory
;
class
memory_holder
{
public:
memory_holder
();
shared_node
create_node
();
void
merge
(
memory_holder
&
rhs
);
private:
boost
::
shared_ptr
<
memory
>
m_pMemory
;
};
class
memory
{
public:
shared_node
create_node
();
void
merge
(
const
memory
&
rhs
);
private:
typedef
std
::
set
<
shared_node
>
Nodes
;
Nodes
m_nodes
;
};
inline
memory_holder
::
memory_holder
()
:
m_pMemory
(
new
memory
)
{
}
inline
shared_node
memory_holder
::
create_node
()
{
return
m_pMemory
->
create_node
();
}
inline
void
memory_holder
::
merge
(
memory_holder
&
rhs
)
{
if
(
m_pMemory
==
rhs
.
m_pMemory
)
return
;
m_pMemory
->
merge
(
*
rhs
.
m_pMemory
);
rhs
.
m_pMemory
=
m_pMemory
;
}
shared_node
memory
::
create_node
()
{
shared_node
pNode
(
new
node
);
m_nodes
.
insert
(
pNode
);
return
pNode
;
}
inline
void
memory
::
merge
(
const
memory
&
rhs
)
{
m_nodes
.
insert
(
rhs
.
m_nodes
.
begin
(),
rhs
.
m_nodes
.
end
());
}
}
}
#endif // VALUE_DETAIL_MEMORY_H_62B23520_7C8E_11DE_8A39_0800200C9A66
include/yaml-cpp/value/detail/node.h
0 → 100644
View file @
248b18a2
#ifndef VALUE_DETAIL_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define VALUE_DETAIL_NODE_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
#include "yaml-cpp/dll.h"
#include "yaml-cpp/value/ptr.h"
namespace
YAML
{
namespace
detail
{
class
node
{
public:
node
();
void
assign_data
(
const
node
&
rhs
);
void
set_scalar
(
const
std
::
string
&
data
);
private:
shared_node_data
m_pData
;
};
inline
node
::
node
()
{
}
inline
void
node
::
assign_data
(
const
node
&
rhs
)
{
m_pData
=
rhs
.
m_pData
;
}
inline
void
node
::
set_scalar
(
const
std
::
string
&
data
)
{
m_pData
.
reset
(
new
node_data
(
data
));
}
}
}
#endif // VALUE_DETAIL_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
include/yaml-cpp/value/detail/nodedata.h
0 → 100644
View file @
248b18a2
include/yaml-cpp/value/impl.h
0 → 100644
View file @
248b18a2
#ifndef VALUE_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define VALUE_IMPL_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
#include "yaml-cpp/value/value.h"
namespace
YAML
{
inline
Value
::
Value
()
:
m_pMemory
(
new
detail
::
memory_holder
)
{
}
template
<
typename
T
>
inline
Value
::
Value
(
const
T
&
rhs
)
:
m_pMemory
(
new
detail
::
memory_holder
)
{
operator
=
(
rhs
);
}
inline
Value
::
Value
(
const
Value
&
rhs
)
:
m_pNode
(
rhs
.
m_pNode
),
m_pMemory
(
rhs
.
m_pMemory
)
{
}
// access
template
<
typename
T
>
inline
const
T
Value
::
as
()
const
{
T
t
;
if
(
convert
<
T
>
(
*
this
,
t
))
return
t
;
throw
std
::
runtime_error
(
"Unable to convert to type"
);
}
// assignment
template
<
typename
T
>
inline
Value
&
Value
::
operator
=
(
const
T
&
rhs
)
{
AssignData
(
convert
<
T
>
(
rhs
));
return
*
this
;
}
template
<
>
inline
Value
&
Value
::
operator
=
(
const
std
::
string
&
rhs
)
{
EnsureNodeExists
();
m_pNode
->
set_scalar
(
rhs
);
}
inline
Value
&
Value
::
operator
=
(
const
Value
&
rhs
)
{
if
(
is
(
*
this
,
rhs
))
return
*
this
;
AssignNode
(
rhs
);
}
void
Value
::
EnsureNodeExists
()
{
if
(
!
m_pNode
)
m_pNode
=
m_pMemory
->
create_node
();
}
void
Value
::
AssignData
(
const
Value
&
rhs
)
{
EnsureNodeExists
();
if
(
!
rhs
.
m_pNode
)
throw
std
::
runtime_error
(
"Tried to assign an undefined value"
);
m_pNode
->
assign_data
(
*
rhs
.
m_pNode
);
m_pMemory
->
merge
(
*
rhs
.
m_pMemory
);
}
void
Value
::
AssignNode
(
const
Value
&
rhs
)
{
m_pNode
=
rhs
.
m_pNode
;
m_pMemory
->
merge
(
*
rhs
.
m_pMemory
);
}
// size/iterator
inline
std
::
size_t
Value
::
size
()
const
{
}
inline
const_iterator
Value
::
begin
()
const
{
}
inline
iterator
Value
::
begin
()
{
}
inline
const_iterator
Value
::
end
()
const
{
}
inline
iterator
Value
::
end
()
{
}
// indexing
template
<
typename
Key
>
inline
const
Value
Value
::
operator
[](
const
Key
&
key
)
const
{
}
template
<
typename
Key
>
inline
Value
Value
::
operator
[](
const
Key
&
key
)
{
}
template
<
typename
Key
>
inline
bool
Value
::
remove
(
const
Key
&
key
)
{
}
inline
const
Value
Value
::
operator
[](
const
Value
&
key
)
const
{
}
inline
Value
Value
::
operator
[](
const
Value
&
key
)
{
}
inline
bool
Value
::
remove
(
const
Value
&
key
)
{
}
inline
const
Value
Value
::
operator
[](
const
char
*
key
)
const
{
}
inline
Value
Value
::
operator
[](
const
char
*
key
)
{
}
inline
bool
Value
::
remove
(
const
char
*
key
)
{
}
inline
const
Value
Value
::
operator
[](
char
*
key
)
const
{
}
inline
Value
Value
::
operator
[](
char
*
key
)
{
}
inline
bool
Value
::
remove
(
char
*
key
)
{
}
// free functions
inline
int
compare
(
const
Value
&
lhs
,
const
Value
&
rhs
)
{
}
inline
bool
operator
<
(
const
Value
&
lhs
,
const
Value
&
rhs
)
{
}
inline
bool
is
(
const
Value
&
lhs
,
const
Value
&
rhs
)
{
}
}
#endif // VALUE_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
include/yaml-cpp/value/ptr.h
0 → 100644
View file @
248b18a2
#ifndef VALUE_PTR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define VALUE_PTR_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
#include "yaml-cpp/dll.h"
#include <boost/shared_ptr.hpp>
namespace
YAML
{
namespace
detail
{
class
node
;
class
node_data
;
class
memory
;
class
memory_holder
;
typedef
boost
::
shared_ptr
<
node
>
shared_node
;
typedef
boost
::
shared_ptr
<
node_data
>
shared_node_data
;
typedef
boost
::
shared_ptr
<
memory_holder
>
shared_memory_holder
;
typedef
boost
::
shared_ptr
<
memory
>
shared_memory
;
}
}
#endif // VALUE_PTR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
include/yaml-cpp/value/value.h
View file @
248b18a2
#ifndef VALUE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define VALUE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#ifndef
VALUE_
VALUE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define
VALUE_
VALUE_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
...
...
@@ -7,7 +7,7 @@
#include "yaml-cpp/dll.h"
#include "yaml-cpp/
node_
ptr.h"
#include "yaml-cpp/
value/
ptr.h"
namespace
YAML
{
...
...
@@ -18,6 +18,8 @@ namespace YAML
public:
Value
();
explicit
Value
(
ValueType
::
value
type
);
explicit
template
<
typename
T
>
Value
(
const
T
&
rhs
);
explicit
Value
(
const
Value
&
rhs
);
~
Value
();
ValueType
::
value
Type
()
const
;
...
...
@@ -26,7 +28,7 @@ namespace YAML
template
<
typename
T
>
const
T
as
()
const
;
// assignment
template
<
typename
T
>
Value
&
operator
=
(
const
T
&
rhs
)
const
;
template
<
typename
T
>
Value
&
operator
=
(
const
T
&
rhs
);
Value
&
operator
=
(
const
Value
&
rhs
);
// size/iterator
...
...
@@ -54,12 +56,29 @@ namespace YAML
const
Value
operator
[](
char
*
key
)
const
;
Value
operator
[](
char
*
key
);
bool
remove
(
char
*
key
);
private:
void
EnsureNodeExists
();
void
AssignData
(
const
Value
&
rhs
);
void
AssignNode
(
const
Value
&
rhs
);
private:
shared_node
m_pNode
;
shared_memory_holder
m_pMemory
;
};
int
compare
(
const
Value
&
lhs
,
const
Value
&
rhs
);
bool
operator
<
(
const
Value
&
lhs
,
const
Value
&
rhs
);
bool
is
(
const
Value
&
lhs
,
const
Value
&
rhs
);
template
<
typename
T
>
Value
convert
(
const
T
&
rhs
);
template
<
typename
T
>
bool
convert
(
const
Value
&
value
,
T
&
rhs
);
}
#endif // VALUE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#include "yaml-cpp/value/impl.h"
#endif // VALUE_VALUE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment