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
cf240daf
Commit
cf240daf
authored
Sep 11, 2011
by
beder
Browse files
Added reading/writing std::list
parent
2a71e886
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
2 deletions
+41
-2
include/yaml-cpp/node/convert.h
include/yaml-cpp/node/convert.h
+24
-2
test/new-api/nodetests.cpp
test/new-api/nodetests.cpp
+17
-0
No files found.
include/yaml-cpp/node/convert.h
View file @
cf240daf
...
@@ -8,8 +8,10 @@
...
@@ -8,8 +8,10 @@
#include "yaml-cpp/node/node.h"
#include "yaml-cpp/node/node.h"
#include "yaml-cpp/node/iterator.h"
#include "yaml-cpp/node/iterator.h"
#include <list>
#include <map>
#include <map>
#include <sstream>
#include <sstream>
#include <vector>
namespace
YAML
namespace
YAML
{
{
...
@@ -83,8 +85,8 @@ namespace YAML
...
@@ -83,8 +85,8 @@ namespace YAML
struct
convert
<
std
::
vector
<
T
>
>
{
struct
convert
<
std
::
vector
<
T
>
>
{
static
Node
encode
(
const
std
::
vector
<
T
>&
rhs
)
{
static
Node
encode
(
const
std
::
vector
<
T
>&
rhs
)
{
Node
node
(
NodeType
::
Sequence
);
Node
node
(
NodeType
::
Sequence
);
for
(
std
::
size_t
i
=
0
;
i
<
rhs
.
size
();
i
++
)
for
(
typename
std
::
vector
<
T
>::
const_iterator
it
=
rhs
.
begin
();
it
!=
rhs
.
end
();
++
it
)
node
.
append
(
rhs
[
i
]
);
node
.
append
(
*
it
);
return
node
;
return
node
;
}
}
...
@@ -98,6 +100,26 @@ namespace YAML
...
@@ -98,6 +100,26 @@ namespace YAML
return
true
;
return
true
;
}
}
};
};
template
<
typename
T
>
struct
convert
<
std
::
list
<
T
>
>
{
static
Node
encode
(
const
std
::
list
<
T
>&
rhs
)
{
Node
node
(
NodeType
::
Sequence
);
for
(
typename
std
::
list
<
T
>::
const_iterator
it
=
rhs
.
begin
();
it
!=
rhs
.
end
();
++
it
)
node
.
append
(
*
it
);
return
node
;
}
static
bool
decode
(
const
Node
&
node
,
std
::
list
<
T
>&
rhs
)
{
if
(
node
.
Type
()
!=
NodeType
::
Sequence
)
return
false
;
rhs
.
clear
();
for
(
const_iterator
it
=
node
.
begin
();
it
!=
node
.
end
();
++
it
)
rhs
.
push_back
(
it
->
as
<
T
>
());
return
true
;
}
};
}
}
#endif // NODE_CONVERT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#endif // NODE_CONVERT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
test/new-api/nodetests.cpp
View file @
cf240daf
...
@@ -132,6 +132,22 @@ namespace Test
...
@@ -132,6 +132,22 @@ namespace Test
YAML_ASSERT
(
node
[
"primes"
].
as
<
std
::
vector
<
int
>
>
()
==
primes
);
YAML_ASSERT
(
node
[
"primes"
].
as
<
std
::
vector
<
int
>
>
()
==
primes
);
return
true
;
return
true
;
}
}
TEST
StdList
()
{
std
::
list
<
int
>
primes
;
primes
.
push_back
(
2
);
primes
.
push_back
(
3
);
primes
.
push_back
(
5
);
primes
.
push_back
(
7
);
primes
.
push_back
(
11
);
primes
.
push_back
(
13
);
YAML
::
Node
node
;
node
[
"primes"
]
=
primes
;
YAML_ASSERT
(
node
[
"primes"
].
as
<
std
::
list
<
int
>
>
()
==
primes
);
return
true
;
}
}
}
void
RunNodeTest
(
TEST
(
*
test
)(),
const
std
::
string
&
name
,
int
&
passed
,
int
&
total
)
{
void
RunNodeTest
(
TEST
(
*
test
)(),
const
std
::
string
&
name
,
int
&
passed
,
int
&
total
)
{
...
@@ -165,6 +181,7 @@ namespace Test
...
@@ -165,6 +181,7 @@ namespace Test
RunNodeTest
(
&
Node
::
MapIteratorWithUndefinedValues
,
"map iterator with undefined values"
,
passed
,
total
);
RunNodeTest
(
&
Node
::
MapIteratorWithUndefinedValues
,
"map iterator with undefined values"
,
passed
,
total
);
RunNodeTest
(
&
Node
::
SimpleSubkeys
,
"simple subkey"
,
passed
,
total
);
RunNodeTest
(
&
Node
::
SimpleSubkeys
,
"simple subkey"
,
passed
,
total
);
RunNodeTest
(
&
Node
::
StdVector
,
"std::vector"
,
passed
,
total
);
RunNodeTest
(
&
Node
::
StdVector
,
"std::vector"
,
passed
,
total
);
RunNodeTest
(
&
Node
::
StdList
,
"std::list"
,
passed
,
total
);
std
::
cout
<<
"Node tests: "
<<
passed
<<
"/"
<<
total
<<
" passed
\n
"
;
std
::
cout
<<
"Node tests: "
<<
passed
<<
"/"
<<
total
<<
" passed
\n
"
;
return
passed
==
total
;
return
passed
==
total
;
...
...
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