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
6ffc9ac7
Commit
6ffc9ac7
authored
Sep 08, 2011
by
Jesse Beder
Browse files
Added half of the std::map conversion (we don't have reading from Values yet)
parent
0e197b87
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
9 deletions
+24
-9
include/yaml-cpp/value/convert.h
include/yaml-cpp/value/convert.h
+16
-0
src/value/convert.cpp
src/value/convert.cpp
+0
-9
util/value.cpp
util/value.cpp
+8
-0
No files found.
include/yaml-cpp/value/convert.h
View file @
6ffc9ac7
...
...
@@ -7,6 +7,7 @@
#include "yaml-cpp/value/value.h"
#include <map>
#include <sstream>
namespace
YAML
...
...
@@ -61,6 +62,21 @@ namespace YAML
YAML_DEFINE_CONVERT_STREAMABLE
(
long
double
);
#undef YAML_DEFINE_CONVERT_STREAMABLE
template
<
typename
K
,
typename
V
>
struct
convert
<
std
::
map
<
K
,
V
>
>
{
static
Value
encode
(
const
std
::
map
<
K
,
V
>&
rhs
)
{
Value
value
(
ValueType
::
Map
);
for
(
typename
std
::
map
<
K
,
V
>::
const_iterator
it
=
rhs
.
begin
();
it
!=
rhs
.
end
();
++
it
)
value
[
it
->
first
]
=
it
->
second
;
return
value
;
}
static
bool
decode
(
const
Value
&
value
,
std
::
map
<
K
,
V
>&
rhs
)
{
rhs
.
clear
();
return
false
;
}
};
}
#endif // VALUE_CONVERT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
src/value/convert.cpp
View file @
6ffc9ac7
...
...
@@ -2,13 +2,4 @@
namespace
YAML
{
//
// template<typename K, typename V>
// Value convert<std::map<K, V> >(const std::map<K, V>& rhs) {
// Value value(ValueType::Map);
// for(std::map<K, V>::const_iterator it=rhs.begin();it!=rhs.end();++it)
// value[it->first] = it->second;
// return value;
// }
}
util/value.cpp
View file @
6ffc9ac7
#include "yaml-cpp/value.h"
#include <map>
int
main
()
{
...
...
@@ -12,5 +13,12 @@ int main()
value
[
"monkey"
]
=
5
;
std
::
cout
<<
value
[
"monkey"
].
as
<
int
>
()
<<
"
\n
"
;
std
::
map
<
int
,
std
::
string
>
names
;
names
[
1
]
=
"one"
;
names
[
2
]
=
"two"
;
names
[
3
]
=
"three"
;
names
[
4
]
=
"four"
;
value
[
"names"
]
=
names
;
return
0
;
}
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