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
90f48fd0
Commit
90f48fd0
authored
Jan 20, 2012
by
beder
Browse files
Began new-api branch, and removed all traces of the old api from this branch
parent
9403ac04
Changes
28
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
7 additions
and
1405 deletions
+7
-1405
CMakeLists.txt
CMakeLists.txt
+7
-27
include/yaml-cpp/old-api/aliasmanager.h
include/yaml-cpp/old-api/aliasmanager.h
+0
-34
include/yaml-cpp/old-api/conversion.h
include/yaml-cpp/old-api/conversion.h
+0
-75
include/yaml-cpp/old-api/iterator.h
include/yaml-cpp/old-api/iterator.h
+0
-40
include/yaml-cpp/old-api/ltnode.h
include/yaml-cpp/old-api/ltnode.h
+0
-18
include/yaml-cpp/old-api/node.h
include/yaml-cpp/old-api/node.h
+0
-135
include/yaml-cpp/old-api/nodeimpl.h
include/yaml-cpp/old-api/nodeimpl.h
+0
-85
include/yaml-cpp/old-api/nodereadimpl.h
include/yaml-cpp/old-api/nodereadimpl.h
+0
-86
include/yaml-cpp/old-api/nodeutil.h
include/yaml-cpp/old-api/nodeutil.h
+0
-62
include/yaml-cpp/old-api/stlnode.h
include/yaml-cpp/old-api/stlnode.h
+0
-38
include/yaml-cpp/yaml.h.cmake
include/yaml-cpp/yaml.h.cmake
+0
-34
src/null.cpp
src/null.cpp
+0
-11
src/old-api/aliasmanager.cpp
src/old-api/aliasmanager.cpp
+0
-29
src/old-api/conversion.cpp
src/old-api/conversion.cpp
+0
-89
src/old-api/iterator.cpp
src/old-api/iterator.cpp
+0
-103
src/old-api/iterpriv.h
src/old-api/iterpriv.h
+0
-33
src/old-api/node.cpp
src/old-api/node.cpp
+0
-269
src/old-api/nodebuilder.cpp
src/old-api/nodebuilder.cpp
+0
-145
src/old-api/nodebuilder.h
src/old-api/nodebuilder.h
+0
-61
src/old-api/nodeownership.cpp
src/old-api/nodeownership.cpp
+0
-31
No files found.
CMakeLists.txt
View file @
90f48fd0
...
@@ -22,8 +22,8 @@ include(CheckCXXCompilerFlag)
...
@@ -22,8 +22,8 @@ include(CheckCXXCompilerFlag)
project
(
YAML_CPP
)
project
(
YAML_CPP
)
set
(
YAML_CPP_VERSION_MAJOR
"0"
)
set
(
YAML_CPP_VERSION_MAJOR
"0"
)
set
(
YAML_CPP_VERSION_MINOR
"
2
"
)
set
(
YAML_CPP_VERSION_MINOR
"
5
"
)
set
(
YAML_CPP_VERSION_PATCH
"
7
"
)
set
(
YAML_CPP_VERSION_PATCH
"
0
"
)
set
(
YAML_CPP_VERSION
"
${
YAML_CPP_VERSION_MAJOR
}
.
${
YAML_CPP_VERSION_MINOR
}
.
${
YAML_CPP_VERSION_PATCH
}
"
)
set
(
YAML_CPP_VERSION
"
${
YAML_CPP_VERSION_MAJOR
}
.
${
YAML_CPP_VERSION_MINOR
}
.
${
YAML_CPP_VERSION_PATCH
}
"
)
enable_testing
()
enable_testing
()
...
@@ -35,7 +35,6 @@ enable_testing()
...
@@ -35,7 +35,6 @@ enable_testing()
## Project stuff
## Project stuff
option
(
YAML_CPP_BUILD_TOOLS
"Enable testing and parse tools"
ON
)
option
(
YAML_CPP_BUILD_TOOLS
"Enable testing and parse tools"
ON
)
option
(
YAML_CPP_BUILD_CONTRIB
"Enable contrib stuff in library"
ON
)
option
(
YAML_CPP_BUILD_CONTRIB
"Enable contrib stuff in library"
ON
)
option
(
YAML_CPP_BUILD_OLD_API
"Enable building the old API"
ON
)
## Build options
## Build options
# --> General
# --> General
...
@@ -52,15 +51,6 @@ option(APPLE_UNIVERSAL_BIN "Apple: Build universal binary" OFF)
...
@@ -52,15 +51,6 @@ option(APPLE_UNIVERSAL_BIN "Apple: Build universal binary" OFF)
option
(
MSVC_SHARED_RT
"MSVC: Build with shared runtime libs (/MD)"
ON
)
option
(
MSVC_SHARED_RT
"MSVC: Build with shared runtime libs (/MD)"
ON
)
option
(
MSVC_STHREADED_RT
"MSVC: Build with single-threaded static runtime libs (/ML until VS .NET 2003)"
OFF
)
option
(
MSVC_STHREADED_RT
"MSVC: Build with single-threaded static runtime libs (/ML until VS .NET 2003)"
OFF
)
###
### Configure the main header
###
if
(
YAML_CPP_BUILD_OLD_API
)
set
(
API_DEFINE
"#define YAML_CPP_OLD_API"
)
endif
()
configure_file
(
${
YAML_CPP_SOURCE_DIR
}
/include/yaml-cpp/yaml.h.cmake
${
YAML_CPP_SOURCE_DIR
}
/include/yaml-cpp/yaml.h @ONLY
)
###
###
### Sources, headers, directories and libs
### Sources, headers, directories and libs
###
###
...
@@ -71,31 +61,21 @@ file(GLOB new_api_sources
...
@@ -71,31 +61,21 @@ file(GLOB new_api_sources
"src/node/[a-zA-Z]*.cpp"
"src/node/[a-zA-Z]*.cpp"
"src/node/detail/[a-zA-Z]*.cpp"
"src/node/detail/[a-zA-Z]*.cpp"
)
)
file
(
GLOB old_api_sources
"src/old-api/[a-zA-Z]*.cpp"
)
file
(
GLOB common_public_headers
"include/yaml-cpp/[a-zA-Z]*.h"
)
file
(
GLOB common_public_headers
"include/yaml-cpp/[a-zA-Z]*.h"
)
file
(
GLOB new_api_public_headers
file
(
GLOB new_api_public_headers
"include/yaml-cpp/node/[a-zA-Z]*.h"
"include/yaml-cpp/node/[a-zA-Z]*.h"
"include/yaml-cpp/node/detail/[a-zA-Z]*.h"
"include/yaml-cpp/node/detail/[a-zA-Z]*.h"
)
)
file
(
GLOB old_api_public_headers
"include/yaml-cpp/old-api/[a-zA-Z]*.h"
)
file
(
GLOB common_private_headers
"src/[a-zA-Z]*.h"
)
file
(
GLOB common_private_headers
"src/[a-zA-Z]*.h"
)
file
(
GLOB new_api_private_headers
"src/node/[a-zA-Z]*.h"
)
file
(
GLOB new_api_private_headers
"src/node/[a-zA-Z]*.h"
)
file
(
GLOB old_api_private_headers
"src/old-api/[a-zA-Z]*.h"
)
if
(
YAML_CPP_BUILD_OLD_API
)
find_package
(
Boost REQUIRED
)
list
(
APPEND sources
${
common_sources
}
${
old_api_sources
}
)
include_directories
(
${
Boost_INCLUDE_DIRS
}
)
list
(
APPEND public_headers
${
common_public_headers
}
${
old_api_public_headers
}
)
list
(
APPEND sources
${
common_sources
}
${
new_api_sources
}
)
list
(
APPEND private_headers
${
common_private_headers
}
${
old_api_private_headers
}
)
list
(
APPEND public_headers
${
common_public_headers
}
${
new_api_public_headers
}
)
add_definitions
(
-DYAML_CPP_OLD_API
)
list
(
APPEND private_headers
${
common_private_headers
}
${
new_api_private_headers
}
)
else
()
find_package
(
Boost REQUIRED
)
include_directories
(
${
Boost_INCLUDE_DIRS
}
)
list
(
APPEND sources
${
common_sources
}
${
new_api_sources
}
)
list
(
APPEND public_headers
${
common_public_headers
}
${
new_api_public_headers
}
)
list
(
APPEND private_headers
${
common_private_headers
}
${
new_api_private_headers
}
)
endif
()
if
(
YAML_CPP_BUILD_CONTRIB
)
if
(
YAML_CPP_BUILD_CONTRIB
)
file
(
GLOB contrib_sources
"src/contrib/[a-zA-Z]*.cpp"
)
file
(
GLOB contrib_sources
"src/contrib/[a-zA-Z]*.cpp"
)
...
...
include/yaml-cpp/old-api/aliasmanager.h
deleted
100644 → 0
View file @
9403ac04
#ifndef ALIASMANAGER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define ALIASMANAGER_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/anchor.h"
#include <map>
namespace
YAML
{
class
Node
;
class
AliasManager
{
public:
AliasManager
();
void
RegisterReference
(
const
Node
&
node
);
anchor_t
LookupAnchor
(
const
Node
&
node
)
const
;
private:
anchor_t
_CreateNewAnchor
();
private:
typedef
std
::
map
<
const
Node
*
,
anchor_t
>
AnchorByIdentity
;
AnchorByIdentity
m_anchorByIdentity
;
anchor_t
m_curAnchor
;
};
}
#endif // ALIASMANAGER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
include/yaml-cpp/old-api/conversion.h
deleted
100644 → 0
View file @
9403ac04
#ifndef CONVERSION_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define CONVERSION_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/null.h"
#include "yaml-cpp/traits.h"
#include <limits>
#include <string>
#include <sstream>
namespace
YAML
{
// traits for conversion
template
<
typename
T
>
struct
is_scalar_convertible
{
enum
{
value
=
is_numeric
<
T
>::
value
};
};
template
<
>
struct
is_scalar_convertible
<
std
::
string
>
{
enum
{
value
=
true
};
};
template
<
>
struct
is_scalar_convertible
<
bool
>
{
enum
{
value
=
true
};
};
template
<
>
struct
is_scalar_convertible
<
_Null
>
{
enum
{
value
=
true
};
};
// actual conversion
inline
bool
Convert
(
const
std
::
string
&
input
,
std
::
string
&
output
)
{
output
=
input
;
return
true
;
}
YAML_CPP_API
bool
Convert
(
const
std
::
string
&
input
,
bool
&
output
);
YAML_CPP_API
bool
Convert
(
const
std
::
string
&
input
,
_Null
&
output
);
inline
bool
IsInfinity
(
const
std
::
string
&
input
)
{
return
input
==
".inf"
||
input
==
".Inf"
||
input
==
".INF"
||
input
==
"+.inf"
||
input
==
"+.Inf"
||
input
==
"+.INF"
;
}
inline
bool
IsNegativeInfinity
(
const
std
::
string
&
input
)
{
return
input
==
"-.inf"
||
input
==
"-.Inf"
||
input
==
"-.INF"
;
}
inline
bool
IsNaN
(
const
std
::
string
&
input
)
{
return
input
==
".nan"
||
input
==
".NaN"
||
input
==
".NAN"
;
}
template
<
typename
T
>
inline
bool
Convert
(
const
std
::
string
&
input
,
T
&
output
,
typename
enable_if
<
is_numeric
<
T
>
>::
type
*
=
0
)
{
std
::
stringstream
stream
(
input
);
stream
.
unsetf
(
std
::
ios
::
dec
);
if
((
stream
>>
output
)
&&
(
stream
>>
std
::
ws
).
eof
())
return
true
;
if
(
std
::
numeric_limits
<
T
>::
has_infinity
)
{
if
(
IsInfinity
(
input
))
{
output
=
std
::
numeric_limits
<
T
>::
infinity
();
return
true
;
}
else
if
(
IsNegativeInfinity
(
input
))
{
output
=
-
std
::
numeric_limits
<
T
>::
infinity
();
return
true
;
}
}
if
(
std
::
numeric_limits
<
T
>::
has_quiet_NaN
&&
IsNaN
(
input
))
{
output
=
std
::
numeric_limits
<
T
>::
quiet_NaN
();
return
true
;
}
return
false
;
}
}
#endif // CONVERSION_H_62B23520_7C8E_11DE_8A39_0800200C9A66
include/yaml-cpp/old-api/iterator.h
deleted
100644 → 0
View file @
9403ac04
#ifndef ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define ITERATOR_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 <memory>
namespace
YAML
{
class
Node
;
struct
IterPriv
;
class
YAML_CPP_API
Iterator
{
public:
Iterator
();
Iterator
(
std
::
auto_ptr
<
IterPriv
>
pData
);
Iterator
(
const
Iterator
&
rhs
);
~
Iterator
();
Iterator
&
operator
=
(
const
Iterator
&
rhs
);
Iterator
&
operator
++
();
Iterator
operator
++
(
int
);
const
Node
&
operator
*
()
const
;
const
Node
*
operator
->
()
const
;
const
Node
&
first
()
const
;
const
Node
&
second
()
const
;
friend
YAML_CPP_API
bool
operator
==
(
const
Iterator
&
it
,
const
Iterator
&
jt
);
friend
YAML_CPP_API
bool
operator
!=
(
const
Iterator
&
it
,
const
Iterator
&
jt
);
private:
std
::
auto_ptr
<
IterPriv
>
m_pData
;
};
}
#endif // ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
include/yaml-cpp/old-api/ltnode.h
deleted
100644 → 0
View file @
9403ac04
#ifndef LTNODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define LTNODE_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
{
class
Node
;
struct
ltnode
{
bool
operator
()(
const
Node
*
pNode1
,
const
Node
*
pNode2
)
const
;
};
}
#endif // LTNODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
include/yaml-cpp/old-api/node.h
deleted
100644 → 0
View file @
9403ac04
#ifndef NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define 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/exceptions.h"
#include "yaml-cpp/mark.h"
#include "yaml-cpp/noncopyable.h"
#include "yaml-cpp/old-api/conversion.h"
#include "yaml-cpp/old-api/iterator.h"
#include "yaml-cpp/old-api/ltnode.h"
#include <iostream>
#include <map>
#include <memory>
#include <string>
#include <vector>
namespace
YAML
{
class
AliasManager
;
class
Content
;
class
NodeOwnership
;
class
Scanner
;
class
Emitter
;
class
EventHandler
;
struct
NodeType
{
enum
value
{
Null
,
Scalar
,
Sequence
,
Map
};
};
class
YAML_CPP_API
Node
:
private
noncopyable
{
public:
friend
class
NodeOwnership
;
friend
class
NodeBuilder
;
Node
();
~
Node
();
void
Clear
();
std
::
auto_ptr
<
Node
>
Clone
()
const
;
void
EmitEvents
(
EventHandler
&
eventHandler
)
const
;
void
EmitEvents
(
AliasManager
&
am
,
EventHandler
&
eventHandler
)
const
;
NodeType
::
value
Type
()
const
{
return
m_type
;
}
bool
IsAliased
()
const
;
// file location of start of this node
const
Mark
GetMark
()
const
{
return
m_mark
;
}
// accessors
Iterator
begin
()
const
;
Iterator
end
()
const
;
std
::
size_t
size
()
const
;
// extraction of scalars
bool
GetScalar
(
std
::
string
&
s
)
const
;
// we can specialize this for other values
template
<
typename
T
>
bool
Read
(
T
&
value
)
const
;
template
<
typename
T
>
const
T
to
()
const
;
template
<
typename
T
>
friend
YAML_CPP_API
typename
enable_if
<
is_scalar_convertible
<
T
>
>::
type
operator
>>
(
const
Node
&
node
,
T
&
value
);
// retrieval for maps and sequences
template
<
typename
T
>
const
Node
*
FindValue
(
const
T
&
key
)
const
;
template
<
typename
T
>
const
Node
&
operator
[]
(
const
T
&
key
)
const
;
// specific to maps
const
Node
*
FindValue
(
const
char
*
key
)
const
;
const
Node
*
FindValue
(
char
*
key
)
const
;
const
Node
&
operator
[]
(
const
char
*
key
)
const
;
const
Node
&
operator
[]
(
char
*
key
)
const
;
// for tags
const
std
::
string
&
Tag
()
const
{
return
m_tag
;
}
// emitting
friend
YAML_CPP_API
Emitter
&
operator
<<
(
Emitter
&
out
,
const
Node
&
node
);
// ordering
int
Compare
(
const
Node
&
rhs
)
const
;
friend
bool
operator
<
(
const
Node
&
n1
,
const
Node
&
n2
);
private:
explicit
Node
(
NodeOwnership
&
owner
);
Node
&
CreateNode
();
void
Init
(
NodeType
::
value
type
,
const
Mark
&
mark
,
const
std
::
string
&
tag
);
void
MarkAsAliased
();
void
SetScalarData
(
const
std
::
string
&
data
);
void
Append
(
Node
&
node
);
void
Insert
(
Node
&
key
,
Node
&
value
);
// helper for sequences
template
<
typename
,
bool
>
friend
struct
_FindFromNodeAtIndex
;
const
Node
*
FindAtIndex
(
std
::
size_t
i
)
const
;
// helper for maps
template
<
typename
T
>
const
Node
&
GetValue
(
const
T
&
key
)
const
;
template
<
typename
T
>
const
Node
*
FindValueForKey
(
const
T
&
key
)
const
;
private:
std
::
auto_ptr
<
NodeOwnership
>
m_pOwnership
;
Mark
m_mark
;
std
::
string
m_tag
;
typedef
std
::
vector
<
Node
*>
node_seq
;
typedef
std
::
map
<
Node
*
,
Node
*
,
ltnode
>
node_map
;
NodeType
::
value
m_type
;
std
::
string
m_scalarData
;
node_seq
m_seqData
;
node_map
m_mapData
;
};
}
#include "yaml-cpp/old-api/nodeimpl.h"
#include "yaml-cpp/old-api/nodereadimpl.h"
#endif // NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
include/yaml-cpp/old-api/nodeimpl.h
deleted
100644 → 0
View file @
9403ac04
#ifndef NODEIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define NODEIMPL_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/old-api/nodeutil.h"
#include <cassert>
namespace
YAML
{
// implementation of templated things
template
<
typename
T
>
inline
const
T
Node
::
to
()
const
{
T
value
;
*
this
>>
value
;
return
value
;
}
template
<
typename
T
>
inline
typename
enable_if
<
is_scalar_convertible
<
T
>
>::
type
operator
>>
(
const
Node
&
node
,
T
&
value
)
{
if
(
!
ConvertScalar
(
node
,
value
))
throw
InvalidScalar
(
node
.
m_mark
);
}
template
<
typename
T
>
inline
const
Node
*
Node
::
FindValue
(
const
T
&
key
)
const
{
switch
(
m_type
)
{
case
NodeType
::
Null
:
case
NodeType
::
Scalar
:
throw
BadDereference
();
case
NodeType
::
Sequence
:
return
FindFromNodeAtIndex
(
*
this
,
key
);
case
NodeType
::
Map
:
return
FindValueForKey
(
key
);
}
assert
(
false
);
throw
BadDereference
();
}
template
<
typename
T
>
inline
const
Node
*
Node
::
FindValueForKey
(
const
T
&
key
)
const
{
for
(
Iterator
it
=
begin
();
it
!=
end
();
++
it
)
{
T
t
;
if
(
it
.
first
().
Read
(
t
))
{
if
(
key
==
t
)
return
&
it
.
second
();
}
}
return
0
;
}
template
<
typename
T
>
inline
const
Node
&
Node
::
GetValue
(
const
T
&
key
)
const
{
if
(
const
Node
*
pValue
=
FindValue
(
key
))
return
*
pValue
;
throw
MakeTypedKeyNotFound
(
m_mark
,
key
);
}
template
<
typename
T
>
inline
const
Node
&
Node
::
operator
[]
(
const
T
&
key
)
const
{
return
GetValue
(
key
);
}
inline
const
Node
*
Node
::
FindValue
(
const
char
*
key
)
const
{
return
FindValue
(
std
::
string
(
key
));
}
inline
const
Node
*
Node
::
FindValue
(
char
*
key
)
const
{
return
FindValue
(
std
::
string
(
key
));
}
inline
const
Node
&
Node
::
operator
[]
(
const
char
*
key
)
const
{
return
GetValue
(
std
::
string
(
key
));
}
inline
const
Node
&
Node
::
operator
[]
(
char
*
key
)
const
{
return
GetValue
(
std
::
string
(
key
));
}
}
#endif // NODEIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
include/yaml-cpp/old-api/nodereadimpl.h
deleted
100644 → 0
View file @
9403ac04
#ifndef NODEREADIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define NODEREADIMPL_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
{
// implementation for Node::Read
// (the goal is to call ConvertScalar if we can, and fall back to operator >> if not)
// thanks to litb from stackoverflow.com
// http://stackoverflow.com/questions/1386183/how-to-call-a-templated-function-if-it-exists-and-something-else-otherwise/1386390#1386390
// Note: this doesn't work on gcc 3.2, but does on gcc 3.4 and above. I'm not sure about 3.3.
#if __GNUC__ && (__GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ <= 3))
// trick doesn't work? Just fall back to ConvertScalar.
// This means that we can't use any user-defined types as keys in a map
template
<
typename
T
>
inline
bool
Node
::
Read
(
T
&
value
)
const
{
return
ConvertScalar
(
*
this
,
value
);
}
#else
// usual case: the trick!
template
<
bool
>
struct
read_impl
;
// ConvertScalar available
template
<
>
struct
read_impl
<
true
>
{
template
<
typename
T
>
static
bool
read
(
const
Node
&
node
,
T
&
value
)
{
return
ConvertScalar
(
node
,
value
);
}
};
// ConvertScalar not available
template
<
>
struct
read_impl
<
false
>
{
template
<
typename
T
>
static
bool
read
(
const
Node
&
node
,
T
&
value
)
{
try
{
node
>>
value
;
}
catch
(
const
Exception
&
)
{
return
false
;
}
return
true
;
}
};
namespace
fallback
{
// sizeof > 1
struct
flag
{
char
c
[
2
];
};
flag
Convert
(...);
int
operator
,(
flag
,
flag
);
template
<
typename
T
>
char
operator
,(
flag
,
T
const
&
);
char
operator
,(
int
,
flag
);
int
operator
,(
char
,
flag
);
}
template
<
typename
T
>
inline
bool
Node
::
Read
(
T
&
value
)
const
{
using
namespace
fallback
;
return
read_impl
<
sizeof
(
fallback
::
flag
(),
Convert
(
std
::
string
(),
value
),
fallback
::
flag
())
!=
1
>::
read
(
*
this
,
value
);
}
#endif // done with trick
// the main conversion function
template
<
typename
T
>
inline
bool
ConvertScalar
(
const
Node
&
node
,
T
&
value
)
{
std
::
string
scalar
;
if
(
!
node
.
GetScalar
(
scalar
))
return
false
;
return
Convert
(
scalar
,
value
);
}
}
#endif // NODEREADIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
include/yaml-cpp/old-api/nodeutil.h
deleted
100644 → 0
View file @
9403ac04
#ifndef NODEUTIL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define NODEUTIL_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
{
template
<
typename
T
,
typename
U
>
struct
is_same_type
{
enum
{
value
=
false
};
};
template
<
typename
T
>
struct
is_same_type
<
T
,
T
>
{
enum
{
value
=
true
};
};
template
<
typename
T
,
bool
check
>
struct
is_index_type_with_check
{
enum
{
value
=
false
};
};
template
<
>
struct
is_index_type_with_check
<
std
::
size_t
,
false
>
{
enum
{
value
=
true
};
};
#define MAKE_INDEX_TYPE(Type) \
template <> struct is_index_type_with_check<Type, is_same_type<Type, std::size_t>::value> { enum { value = true }; }
MAKE_INDEX_TYPE
(
int
);
MAKE_INDEX_TYPE
(
unsigned
);
MAKE_INDEX_TYPE
(
short
);
MAKE_INDEX_TYPE
(
unsigned
short
);
MAKE_INDEX_TYPE
(
long
);
MAKE_INDEX_TYPE
(
unsigned
long
);
#undef MAKE_INDEX_TYPE
template
<
typename
T
>
struct
is_index_type
:
public
is_index_type_with_check
<
T
,
false
>
{};
// messing around with template stuff to get the right overload for operator [] for a sequence
template
<
typename
T
,
bool
b
>
struct
_FindFromNodeAtIndex
{
const
Node
*
pRet
;
_FindFromNodeAtIndex
(
const
Node
&
,
const
T
&
)
:
pRet
(
0
)
{}
};
template
<
typename
T
>
struct
_FindFromNodeAtIndex
<
T
,
true
>
{
const
Node
*
pRet
;
_FindFromNodeAtIndex
(
const
Node
&
node
,
const
T
&
key
)
:
pRet
(
node
.
FindAtIndex
(
static_cast
<
std
::
size_t
>
(
key
)))
{}
};
template
<
typename
T
>
inline
const
Node
*
FindFromNodeAtIndex
(
const
Node
&
node
,
const
T
&
key
)
{
return
_FindFromNodeAtIndex
<
T
,
is_index_type
<
T
>::
value
>
(
node
,
key
).
pRet
;
}
}
#endif // NODEUTIL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
include/yaml-cpp/old-api/stlnode.h
deleted
100644 → 0
View file @
9403ac04
#ifndef STLNODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define STLNODE_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 <vector>
#include <map>
namespace
YAML
{
template
<
typename
T
>
void
operator
>>
(
const
Node
&
node
,
std
::
vector
<
T
>&
v
)
{
v
.
clear
();
v
.
resize
(
node
.
size
());
for
(
unsigned
i
=
0
;
i
<
node
.
size
();
++
i
)
node
[
i
]
>>
v
[
i
];
}
template
<
typename
K
,
typename
V
>
void
operator
>>
(
const
Node
&
node
,
std
::
map
<
K
,
V
>&
m
)
{
m
.
clear
();
for
(
Iterator
it
=
node
.
begin
();
it
!=
node
.
end
();
++
it
)
{
K
k
;
V
v
;
it
.
first
()
>>
k
;
it
.
second
()
>>
v
;
m
[
k
]
=
v
;
}
}
}
#endif // STLNODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
include/yaml-cpp/yaml.h.cmake
deleted
100644 → 0
View file @
9403ac04
#ifndef YAML_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define YAML_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
#undef YAML_CPP_OLD_API
@API_DEFINE@
#include "yaml-cpp/parser.h"
#include "yaml-cpp/emitter.h"
#include "yaml-cpp/stlemitter.h"
#include "yaml-cpp/exceptions.h"
#ifdef YAML_CPP_OLD_API
#include "yaml-cpp/old-api/node.h"
#include "yaml-cpp/old-api/stlnode.h"
#include "yaml-cpp/old-api/iterator.h"
#else
#include "yaml-cpp/node/node.h"
#include "yaml-cpp/node/impl.h"
#include "yaml-cpp/node/convert.h"
#include "yaml-cpp/node/iterator.h"
#include "yaml-cpp/node/detail/impl.h"
#include "yaml-cpp/node/parse.h"
#include "yaml-cpp/node/emit.h"
#endif // YAML_CPP_OLD_API
#endif // YAML_H_62B23520_7C8E_11DE_8A39_0800200C9A66
src/null.cpp
View file @
90f48fd0
#include "yaml-cpp/null.h"
#include "yaml-cpp/null.h"
#ifdef YAML_CPP_OLD_API
#include "yaml-cpp/old-api/node.h"
#endif
namespace
YAML
namespace
YAML
{
{
_Null
Null
;
_Null
Null
;
#ifdef YAML_CPP_OLD_API
bool
IsNull
(
const
Node
&
node
)
{
return
node
.
Read
(
Null
);
}
#endif
}
}
src/old-api/aliasmanager.cpp
deleted
100644 → 0
View file @
9403ac04
#include "yaml-cpp/old-api/aliasmanager.h"
#include "yaml-cpp/old-api/node.h"
#include <cassert>
#include <sstream>
namespace
YAML
{
AliasManager
::
AliasManager
()
:
m_curAnchor
(
0
)
{
}
void
AliasManager
::
RegisterReference
(
const
Node
&
node
)
{
m_anchorByIdentity
.
insert
(
std
::
make_pair
(
&
node
,
_CreateNewAnchor
()));
}
anchor_t
AliasManager
::
LookupAnchor
(
const
Node
&
node
)
const
{
AnchorByIdentity
::
const_iterator
it
=
m_anchorByIdentity
.
find
(
&
node
);
if
(
it
==
m_anchorByIdentity
.
end
())
return
0
;
return
it
->
second
;
}
anchor_t
AliasManager
::
_CreateNewAnchor
()
{
return
++
m_curAnchor
;
}
}
src/old-api/conversion.cpp
deleted
100644 → 0
View file @
9403ac04
#include "yaml-cpp/old-api/conversion.h"
#include <algorithm>
////////////////////////////////////////////////////////////////
// Specializations for converting a string to specific types
namespace
{
// we're not gonna mess with the mess that is all the isupper/etc. functions
bool
IsLower
(
char
ch
)
{
return
'a'
<=
ch
&&
ch
<=
'z'
;
}
bool
IsUpper
(
char
ch
)
{
return
'A'
<=
ch
&&
ch
<=
'Z'
;
}
char
ToLower
(
char
ch
)
{
return
IsUpper
(
ch
)
?
ch
+
'a'
-
'A'
:
ch
;
}
std
::
string
tolower
(
const
std
::
string
&
str
)
{
std
::
string
s
(
str
);
std
::
transform
(
s
.
begin
(),
s
.
end
(),
s
.
begin
(),
ToLower
);
return
s
;
}
template
<
typename
T
>
bool
IsEntirely
(
const
std
::
string
&
str
,
T
func
)
{
for
(
std
::
size_t
i
=
0
;
i
<
str
.
size
();
i
++
)
if
(
!
func
(
str
[
i
]))
return
false
;
return
true
;
}
// IsFlexibleCase
// . Returns true if 'str' is:
// . UPPERCASE
// . lowercase
// . Capitalized
bool
IsFlexibleCase
(
const
std
::
string
&
str
)
{
if
(
str
.
empty
())
return
true
;
if
(
IsEntirely
(
str
,
IsLower
))
return
true
;
bool
firstcaps
=
IsUpper
(
str
[
0
]);
std
::
string
rest
=
str
.
substr
(
1
);
return
firstcaps
&&
(
IsEntirely
(
rest
,
IsLower
)
||
IsEntirely
(
rest
,
IsUpper
));
}
}
namespace
YAML
{
bool
Convert
(
const
std
::
string
&
input
,
bool
&
b
)
{
// we can't use iostream bool extraction operators as they don't
// recognize all possible values in the table below (taken from
// http://yaml.org/type/bool.html)
static
const
struct
{
std
::
string
truename
,
falsename
;
}
names
[]
=
{
{
"y"
,
"n"
},
{
"yes"
,
"no"
},
{
"true"
,
"false"
},
{
"on"
,
"off"
},
};
if
(
!
IsFlexibleCase
(
input
))
return
false
;
for
(
unsigned
i
=
0
;
i
<
sizeof
(
names
)
/
sizeof
(
names
[
0
]);
i
++
)
{
if
(
names
[
i
].
truename
==
tolower
(
input
))
{
b
=
true
;
return
true
;
}
if
(
names
[
i
].
falsename
==
tolower
(
input
))
{
b
=
false
;
return
true
;
}
}
return
false
;
}
bool
Convert
(
const
std
::
string
&
input
,
_Null
&
/*output*/
)
{
return
input
.
empty
()
||
input
==
"~"
||
input
==
"null"
||
input
==
"Null"
||
input
==
"NULL"
;
}
}
src/old-api/iterator.cpp
deleted
100644 → 0
View file @
9403ac04
#include "yaml-cpp/old-api/node.h"
#include "yaml-cpp/exceptions.h"
#include "iterpriv.h"
namespace
YAML
{
Iterator
::
Iterator
()
:
m_pData
(
new
IterPriv
)
{
}
Iterator
::
Iterator
(
std
::
auto_ptr
<
IterPriv
>
pData
)
:
m_pData
(
pData
)
{
}
Iterator
::
Iterator
(
const
Iterator
&
rhs
)
:
m_pData
(
new
IterPriv
(
*
rhs
.
m_pData
))
{
}
Iterator
&
Iterator
::
operator
=
(
const
Iterator
&
rhs
)
{
if
(
this
==
&
rhs
)
return
*
this
;
m_pData
.
reset
(
new
IterPriv
(
*
rhs
.
m_pData
));
return
*
this
;
}
Iterator
::~
Iterator
()
{
}
Iterator
&
Iterator
::
operator
++
()
{
if
(
m_pData
->
type
==
IterPriv
::
IT_SEQ
)
++
m_pData
->
seqIter
;
else
if
(
m_pData
->
type
==
IterPriv
::
IT_MAP
)
++
m_pData
->
mapIter
;
return
*
this
;
}
Iterator
Iterator
::
operator
++
(
int
)
{
Iterator
temp
=
*
this
;
if
(
m_pData
->
type
==
IterPriv
::
IT_SEQ
)
++
m_pData
->
seqIter
;
else
if
(
m_pData
->
type
==
IterPriv
::
IT_MAP
)
++
m_pData
->
mapIter
;
return
temp
;
}
const
Node
&
Iterator
::
operator
*
()
const
{
if
(
m_pData
->
type
==
IterPriv
::
IT_SEQ
)
return
**
m_pData
->
seqIter
;
throw
BadDereference
();
}
const
Node
*
Iterator
::
operator
->
()
const
{
if
(
m_pData
->
type
==
IterPriv
::
IT_SEQ
)
return
*
m_pData
->
seqIter
;
throw
BadDereference
();
}
const
Node
&
Iterator
::
first
()
const
{
if
(
m_pData
->
type
==
IterPriv
::
IT_MAP
)
return
*
m_pData
->
mapIter
->
first
;
throw
BadDereference
();
}
const
Node
&
Iterator
::
second
()
const
{
if
(
m_pData
->
type
==
IterPriv
::
IT_MAP
)
return
*
m_pData
->
mapIter
->
second
;
throw
BadDereference
();
}
bool
operator
==
(
const
Iterator
&
it
,
const
Iterator
&
jt
)
{
if
(
it
.
m_pData
->
type
!=
jt
.
m_pData
->
type
)
return
false
;
if
(
it
.
m_pData
->
type
==
IterPriv
::
IT_SEQ
)
return
it
.
m_pData
->
seqIter
==
jt
.
m_pData
->
seqIter
;
else
if
(
it
.
m_pData
->
type
==
IterPriv
::
IT_MAP
)
return
it
.
m_pData
->
mapIter
==
jt
.
m_pData
->
mapIter
;
return
true
;
}
bool
operator
!=
(
const
Iterator
&
it
,
const
Iterator
&
jt
)
{
return
!
(
it
==
jt
);
}
}
src/old-api/iterpriv.h
deleted
100644 → 0
View file @
9403ac04
#ifndef ITERPRIV_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define ITERPRIV_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/old-api/ltnode.h"
#include <vector>
#include <map>
namespace
YAML
{
class
Node
;
// IterPriv
// . The implementation for iterators - essentially a union of sequence and map iterators.
struct
IterPriv
{
IterPriv
()
:
type
(
IT_NONE
)
{}
IterPriv
(
std
::
vector
<
Node
*>::
const_iterator
it
)
:
type
(
IT_SEQ
),
seqIter
(
it
)
{}
IterPriv
(
std
::
map
<
Node
*
,
Node
*
,
ltnode
>::
const_iterator
it
)
:
type
(
IT_MAP
),
mapIter
(
it
)
{}
enum
ITER_TYPE
{
IT_NONE
,
IT_SEQ
,
IT_MAP
};
ITER_TYPE
type
;
std
::
vector
<
Node
*>::
const_iterator
seqIter
;
std
::
map
<
Node
*
,
Node
*
,
ltnode
>::
const_iterator
mapIter
;
};
}
#endif // ITERPRIV_H_62B23520_7C8E_11DE_8A39_0800200C9A66
src/old-api/node.cpp
deleted
100644 → 0
View file @
9403ac04
#include "yaml-cpp/old-api/node.h"
#include "yaml-cpp/old-api/aliasmanager.h"
#include "yaml-cpp/emitfromevents.h"
#include "yaml-cpp/emitter.h"
#include "yaml-cpp/eventhandler.h"
#include "old-api/iterpriv.h"
#include "old-api/nodebuilder.h"
#include "old-api/nodeownership.h"
#include "scanner.h"
#include "tag.h"
#include "token.h"
#include <cassert>
#include <stdexcept>
namespace
YAML
{
bool
ltnode
::
operator
()(
const
Node
*
pNode1
,
const
Node
*
pNode2
)
const
{
return
*
pNode1
<
*
pNode2
;
}
Node
::
Node
()
:
m_pOwnership
(
new
NodeOwnership
),
m_type
(
NodeType
::
Null
)
{
}
Node
::
Node
(
NodeOwnership
&
owner
)
:
m_pOwnership
(
new
NodeOwnership
(
&
owner
)),
m_type
(
NodeType
::
Null
)
{
}
Node
::~
Node
()
{
Clear
();
}
void
Node
::
Clear
()
{
m_pOwnership
.
reset
(
new
NodeOwnership
);
m_type
=
NodeType
::
Null
;
m_tag
.
clear
();
m_scalarData
.
clear
();
m_seqData
.
clear
();
m_mapData
.
clear
();
}
bool
Node
::
IsAliased
()
const
{
return
m_pOwnership
->
IsAliased
(
*
this
);
}
Node
&
Node
::
CreateNode
()
{
return
m_pOwnership
->
Create
();
}
std
::
auto_ptr
<
Node
>
Node
::
Clone
()
const
{
std
::
auto_ptr
<
Node
>
pNode
(
new
Node
);
NodeBuilder
nodeBuilder
(
*
pNode
);
EmitEvents
(
nodeBuilder
);
return
pNode
;
}
void
Node
::
EmitEvents
(
EventHandler
&
eventHandler
)
const
{
eventHandler
.
OnDocumentStart
(
m_mark
);
AliasManager
am
;
EmitEvents
(
am
,
eventHandler
);
eventHandler
.
OnDocumentEnd
();
}
void
Node
::
EmitEvents
(
AliasManager
&
am
,
EventHandler
&
eventHandler
)
const
{
anchor_t
anchor
=
NullAnchor
;
if
(
IsAliased
())
{
anchor
=
am
.
LookupAnchor
(
*
this
);
if
(
anchor
)
{
eventHandler
.
OnAlias
(
m_mark
,
anchor
);
return
;
}
am
.
RegisterReference
(
*
this
);
anchor
=
am
.
LookupAnchor
(
*
this
);
}
switch
(
m_type
)
{
case
NodeType
::
Null
:
eventHandler
.
OnNull
(
m_mark
,
anchor
);
break
;
case
NodeType
::
Scalar
:
eventHandler
.
OnScalar
(
m_mark
,
m_tag
,
anchor
,
m_scalarData
);
break
;
case
NodeType
::
Sequence
:
eventHandler
.
OnSequenceStart
(
m_mark
,
m_tag
,
anchor
);
for
(
std
::
size_t
i
=
0
;
i
<
m_seqData
.
size
();
i
++
)
m_seqData
[
i
]
->
EmitEvents
(
am
,
eventHandler
);
eventHandler
.
OnSequenceEnd
();
break
;
case
NodeType
::
Map
:
eventHandler
.
OnMapStart
(
m_mark
,
m_tag
,
anchor
);
for
(
node_map
::
const_iterator
it
=
m_mapData
.
begin
();
it
!=
m_mapData
.
end
();
++
it
)
{
it
->
first
->
EmitEvents
(
am
,
eventHandler
);
it
->
second
->
EmitEvents
(
am
,
eventHandler
);
}
eventHandler
.
OnMapEnd
();
break
;
}
}
void
Node
::
Init
(
NodeType
::
value
type
,
const
Mark
&
mark
,
const
std
::
string
&
tag
)
{
Clear
();
m_mark
=
mark
;
m_type
=
type
;
m_tag
=
tag
;
}
void
Node
::
MarkAsAliased
()
{
m_pOwnership
->
MarkAsAliased
(
*
this
);
}
void
Node
::
SetScalarData
(
const
std
::
string
&
data
)
{
assert
(
m_type
==
NodeType
::
Scalar
);
// TODO: throw?
m_scalarData
=
data
;
}
void
Node
::
Append
(
Node
&
node
)
{
assert
(
m_type
==
NodeType
::
Sequence
);
// TODO: throw?
m_seqData
.
push_back
(
&
node
);
}
void
Node
::
Insert
(
Node
&
key
,
Node
&
value
)
{
assert
(
m_type
==
NodeType
::
Map
);
// TODO: throw?
m_mapData
[
&
key
]
=
&
value
;
}
// begin
// Returns an iterator to the beginning of this (sequence or map).
Iterator
Node
::
begin
()
const
{
switch
(
m_type
)
{
case
NodeType
::
Null
:
case
NodeType
::
Scalar
:
return
Iterator
();
case
NodeType
::
Sequence
:
return
Iterator
(
std
::
auto_ptr
<
IterPriv
>
(
new
IterPriv
(
m_seqData
.
begin
())));
case
NodeType
::
Map
:
return
Iterator
(
std
::
auto_ptr
<
IterPriv
>
(
new
IterPriv
(
m_mapData
.
begin
())));
}
assert
(
false
);
return
Iterator
();
}
// end
// . Returns an iterator to the end of this (sequence or map).
Iterator
Node
::
end
()
const
{
switch
(
m_type
)
{
case
NodeType
::
Null
:
case
NodeType
::
Scalar
:
return
Iterator
();
case
NodeType
::
Sequence
:
return
Iterator
(
std
::
auto_ptr
<
IterPriv
>
(
new
IterPriv
(
m_seqData
.
end
())));
case
NodeType
::
Map
:
return
Iterator
(
std
::
auto_ptr
<
IterPriv
>
(
new
IterPriv
(
m_mapData
.
end
())));
}
assert
(
false
);
return
Iterator
();
}
// size
// . Returns the size of a sequence or map node
// . Otherwise, returns zero.
std
::
size_t
Node
::
size
()
const
{
switch
(
m_type
)
{
case
NodeType
::
Null
:
case
NodeType
::
Scalar
:
return
0
;
case
NodeType
::
Sequence
:
return
m_seqData
.
size
();
case
NodeType
::
Map
:
return
m_mapData
.
size
();
}
assert
(
false
);
return
0
;
}
const
Node
*
Node
::
FindAtIndex
(
std
::
size_t
i
)
const
{
if
(
m_type
==
NodeType
::
Sequence
)
return
m_seqData
[
i
];
return
0
;
}
bool
Node
::
GetScalar
(
std
::
string
&
s
)
const
{
switch
(
m_type
)
{
case
NodeType
::
Null
:
s
=
"~"
;
return
true
;
case
NodeType
::
Scalar
:
s
=
m_scalarData
;
return
true
;
case
NodeType
::
Sequence
:
case
NodeType
::
Map
:
return
false
;
}
assert
(
false
);
return
false
;
}
Emitter
&
operator
<<
(
Emitter
&
out
,
const
Node
&
node
)
{
EmitFromEvents
emitFromEvents
(
out
);
node
.
EmitEvents
(
emitFromEvents
);
return
out
;
}
int
Node
::
Compare
(
const
Node
&
rhs
)
const
{
if
(
m_type
!=
rhs
.
m_type
)
return
rhs
.
m_type
-
m_type
;
switch
(
m_type
)
{
case
NodeType
::
Null
:
return
0
;
case
NodeType
::
Scalar
:
return
m_scalarData
.
compare
(
rhs
.
m_scalarData
);
case
NodeType
::
Sequence
:
if
(
m_seqData
.
size
()
<
rhs
.
m_seqData
.
size
())
return
1
;
else
if
(
m_seqData
.
size
()
>
rhs
.
m_seqData
.
size
())
return
-
1
;
for
(
std
::
size_t
i
=
0
;
i
<
m_seqData
.
size
();
i
++
)
if
(
int
cmp
=
m_seqData
[
i
]
->
Compare
(
*
rhs
.
m_seqData
[
i
]))
return
cmp
;
return
0
;
case
NodeType
::
Map
:
if
(
m_mapData
.
size
()
<
rhs
.
m_mapData
.
size
())
return
1
;
else
if
(
m_mapData
.
size
()
>
rhs
.
m_mapData
.
size
())
return
-
1
;
node_map
::
const_iterator
it
=
m_mapData
.
begin
();
node_map
::
const_iterator
jt
=
rhs
.
m_mapData
.
begin
();
for
(;
it
!=
m_mapData
.
end
()
&&
jt
!=
rhs
.
m_mapData
.
end
();
it
++
,
jt
++
)
{
if
(
int
cmp
=
it
->
first
->
Compare
(
*
jt
->
first
))
return
cmp
;
if
(
int
cmp
=
it
->
second
->
Compare
(
*
jt
->
second
))
return
cmp
;
}
return
0
;
}
assert
(
false
);
return
0
;
}
bool
operator
<
(
const
Node
&
n1
,
const
Node
&
n2
)
{
return
n1
.
Compare
(
n2
)
<
0
;
}
}
src/old-api/nodebuilder.cpp
deleted
100644 → 0
View file @
9403ac04
#include "old-api/nodebuilder.h"
#include "yaml-cpp/mark.h"
#include "yaml-cpp/old-api/node.h"
#include <cassert>
namespace
YAML
{
NodeBuilder
::
NodeBuilder
(
Node
&
root
)
:
m_root
(
root
),
m_initializedRoot
(
false
),
m_finished
(
false
)
{
m_root
.
Clear
();
m_anchors
.
push_back
(
0
);
// since the anchors start at 1
}
NodeBuilder
::~
NodeBuilder
()
{
}
void
NodeBuilder
::
OnDocumentStart
(
const
Mark
&
)
{
}
void
NodeBuilder
::
OnDocumentEnd
()
{
assert
(
m_finished
);
}
void
NodeBuilder
::
OnNull
(
const
Mark
&
mark
,
anchor_t
anchor
)
{
Node
&
node
=
Push
(
anchor
);
node
.
Init
(
NodeType
::
Null
,
mark
,
""
);
Pop
();
}
void
NodeBuilder
::
OnAlias
(
const
Mark
&
/*mark*/
,
anchor_t
anchor
)
{
Node
&
node
=
*
m_anchors
[
anchor
];
Insert
(
node
);
node
.
MarkAsAliased
();
}
void
NodeBuilder
::
OnScalar
(
const
Mark
&
mark
,
const
std
::
string
&
tag
,
anchor_t
anchor
,
const
std
::
string
&
value
)
{
Node
&
node
=
Push
(
anchor
);
node
.
Init
(
NodeType
::
Scalar
,
mark
,
tag
);
node
.
SetScalarData
(
value
);
Pop
();
}
void
NodeBuilder
::
OnSequenceStart
(
const
Mark
&
mark
,
const
std
::
string
&
tag
,
anchor_t
anchor
)
{
Node
&
node
=
Push
(
anchor
);
node
.
Init
(
NodeType
::
Sequence
,
mark
,
tag
);
}
void
NodeBuilder
::
OnSequenceEnd
()
{
Pop
();
}
void
NodeBuilder
::
OnMapStart
(
const
Mark
&
mark
,
const
std
::
string
&
tag
,
anchor_t
anchor
)
{
Node
&
node
=
Push
(
anchor
);
node
.
Init
(
NodeType
::
Map
,
mark
,
tag
);
m_didPushKey
.
push
(
false
);
}
void
NodeBuilder
::
OnMapEnd
()
{
m_didPushKey
.
pop
();
Pop
();
}
Node
&
NodeBuilder
::
Push
(
anchor_t
anchor
)
{
Node
&
node
=
Push
();
RegisterAnchor
(
anchor
,
node
);
return
node
;
}
Node
&
NodeBuilder
::
Push
()
{
if
(
!
m_initializedRoot
)
{
m_initializedRoot
=
true
;
return
m_root
;
}
Node
&
node
=
m_root
.
CreateNode
();
m_stack
.
push
(
&
node
);
return
node
;
}
Node
&
NodeBuilder
::
Top
()
{
return
m_stack
.
empty
()
?
m_root
:
*
m_stack
.
top
();
}
void
NodeBuilder
::
Pop
()
{
assert
(
!
m_finished
);
if
(
m_stack
.
empty
())
{
m_finished
=
true
;
return
;
}
Node
&
node
=
*
m_stack
.
top
();
m_stack
.
pop
();
Insert
(
node
);
}
void
NodeBuilder
::
Insert
(
Node
&
node
)
{
Node
&
curTop
=
Top
();
switch
(
curTop
.
Type
())
{
case
NodeType
::
Null
:
case
NodeType
::
Scalar
:
assert
(
false
);
break
;
case
NodeType
::
Sequence
:
curTop
.
Append
(
node
);
break
;
case
NodeType
::
Map
:
assert
(
!
m_didPushKey
.
empty
());
if
(
m_didPushKey
.
top
())
{
assert
(
!
m_pendingKeys
.
empty
());
Node
&
key
=
*
m_pendingKeys
.
top
();
m_pendingKeys
.
pop
();
curTop
.
Insert
(
key
,
node
);
m_didPushKey
.
top
()
=
false
;
}
else
{
m_pendingKeys
.
push
(
&
node
);
m_didPushKey
.
top
()
=
true
;
}
break
;
}
}
void
NodeBuilder
::
RegisterAnchor
(
anchor_t
anchor
,
Node
&
node
)
{
if
(
anchor
)
{
assert
(
anchor
==
m_anchors
.
size
());
m_anchors
.
push_back
(
&
node
);
}
}
}
src/old-api/nodebuilder.h
deleted
100644 → 0
View file @
9403ac04
#ifndef NODEBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define NODEBUILDER_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/eventhandler.h"
#include <map>
#include <memory>
#include <stack>
#include <vector>
namespace
YAML
{
class
Node
;
class
NodeBuilder
:
public
EventHandler
{
public:
explicit
NodeBuilder
(
Node
&
root
);
virtual
~
NodeBuilder
();
virtual
void
OnDocumentStart
(
const
Mark
&
mark
);
virtual
void
OnDocumentEnd
();
virtual
void
OnNull
(
const
Mark
&
mark
,
anchor_t
anchor
);
virtual
void
OnAlias
(
const
Mark
&
mark
,
anchor_t
anchor
);
virtual
void
OnScalar
(
const
Mark
&
mark
,
const
std
::
string
&
tag
,
anchor_t
anchor
,
const
std
::
string
&
value
);
virtual
void
OnSequenceStart
(
const
Mark
&
mark
,
const
std
::
string
&
tag
,
anchor_t
anchor
);
virtual
void
OnSequenceEnd
();
virtual
void
OnMapStart
(
const
Mark
&
mark
,
const
std
::
string
&
tag
,
anchor_t
anchor
);
virtual
void
OnMapEnd
();
private:
Node
&
Push
(
anchor_t
anchor
);
Node
&
Push
();
Node
&
Top
();
void
Pop
();
void
Insert
(
Node
&
node
);
void
RegisterAnchor
(
anchor_t
anchor
,
Node
&
node
);
private:
Node
&
m_root
;
bool
m_initializedRoot
;
bool
m_finished
;
std
::
stack
<
Node
*>
m_stack
;
std
::
stack
<
Node
*>
m_pendingKeys
;
std
::
stack
<
bool
>
m_didPushKey
;
typedef
std
::
vector
<
Node
*>
Anchors
;
Anchors
m_anchors
;
};
}
#endif // NODEBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
src/old-api/nodeownership.cpp
deleted
100644 → 0
View file @
9403ac04
#include "old-api/nodeownership.h"
#include "yaml-cpp/old-api/node.h"
namespace
YAML
{
NodeOwnership
::
NodeOwnership
(
NodeOwnership
*
pOwner
)
:
m_pOwner
(
pOwner
)
{
if
(
!
m_pOwner
)
m_pOwner
=
this
;
}
NodeOwnership
::~
NodeOwnership
()
{
}
Node
&
NodeOwnership
::
_Create
()
{
m_nodes
.
push_back
(
std
::
auto_ptr
<
Node
>
(
new
Node
));
return
m_nodes
.
back
();
}
void
NodeOwnership
::
_MarkAsAliased
(
const
Node
&
node
)
{
m_aliasedNodes
.
insert
(
&
node
);
}
bool
NodeOwnership
::
_IsAliased
(
const
Node
&
node
)
const
{
return
m_aliasedNodes
.
count
(
&
node
)
>
0
;
}
}
Prev
1
2
Next
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