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
0e197b87
Commit
0e197b87
authored
Sep 08, 2011
by
Jesse Beder
Browse files
Added back the streamable conversions
parent
3d84f570
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
35 deletions
+40
-35
include/yaml-cpp/value/convert.h
include/yaml-cpp/value/convert.h
+36
-0
src/value/convert.cpp
src/value/convert.cpp
+0
-31
util/value.cpp
util/value.cpp
+4
-4
No files found.
include/yaml-cpp/value/convert.h
View file @
0e197b87
...
...
@@ -25,6 +25,42 @@ namespace YAML
return
true
;
}
};
#define YAML_DEFINE_CONVERT_STREAMABLE(type)\
template<>\
struct convert<type> {\
static Value encode(const type& rhs) {\
std::stringstream stream;\
stream << rhs;\
return Value(stream.str());\
}\
\
static bool decode(const Value& value, type& rhs) {\
if(value.Type() != ValueType::Scalar)\
return false;\
std::stringstream stream(value.scalar());\
stream >> rhs;\
return !!stream;\
}\
}
YAML_DEFINE_CONVERT_STREAMABLE
(
int
);
YAML_DEFINE_CONVERT_STREAMABLE
(
unsigned
);
YAML_DEFINE_CONVERT_STREAMABLE
(
short
);
YAML_DEFINE_CONVERT_STREAMABLE
(
unsigned
short
);
YAML_DEFINE_CONVERT_STREAMABLE
(
long
);
YAML_DEFINE_CONVERT_STREAMABLE
(
unsigned
long
);
YAML_DEFINE_CONVERT_STREAMABLE
(
long
long
);
YAML_DEFINE_CONVERT_STREAMABLE
(
unsigned
long
long
);
YAML_DEFINE_CONVERT_STREAMABLE
(
char
);
YAML_DEFINE_CONVERT_STREAMABLE
(
unsigned
char
);
YAML_DEFINE_CONVERT_STREAMABLE
(
float
);
YAML_DEFINE_CONVERT_STREAMABLE
(
double
);
YAML_DEFINE_CONVERT_STREAMABLE
(
long
double
);
#undef YAML_DEFINE_CONVERT_STREAMABLE
}
#endif // VALUE_CONVERT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
src/value/convert.cpp
View file @
0e197b87
...
...
@@ -3,37 +3,6 @@
namespace
YAML
{
//#define YAML_DEFINE_CONVERT_STREAMABLE(type)\
// template<> Value convert(const type& rhs) {\
// std::stringstream stream;\
// stream << rhs;\
// return Value(stream.str());\
// }\
// template<> bool convert(const Value& value, type& rhs) {\
// if(value.Type() != ValueType::Scalar)\
// return false;\
// std::stringstream stream(value.scalar());\
// stream >> rhs;\
// return !!stream;\
// }
//
// YAML_DEFINE_CONVERT_STREAMABLE(int)
// YAML_DEFINE_CONVERT_STREAMABLE(unsigned)
// YAML_DEFINE_CONVERT_STREAMABLE(short)
// YAML_DEFINE_CONVERT_STREAMABLE(unsigned short)
// YAML_DEFINE_CONVERT_STREAMABLE(long)
// YAML_DEFINE_CONVERT_STREAMABLE(unsigned long)
// YAML_DEFINE_CONVERT_STREAMABLE(long long)
// YAML_DEFINE_CONVERT_STREAMABLE(unsigned long long)
//
// YAML_DEFINE_CONVERT_STREAMABLE(char)
// YAML_DEFINE_CONVERT_STREAMABLE(unsigned char)
//
// YAML_DEFINE_CONVERT_STREAMABLE(float)
// YAML_DEFINE_CONVERT_STREAMABLE(double)
// YAML_DEFINE_CONVERT_STREAMABLE(long double)
//
//#undef YAML_DEFINE_CONVERT_STREAMABLE
//
// template<typename K, typename V>
// Value convert<std::map<K, V> >(const std::map<K, V>& rhs) {
...
...
util/value.cpp
View file @
0e197b87
...
...
@@ -7,10 +7,10 @@ int main()
std
::
cout
<<
value
[
"key"
].
as
<
std
::
string
>
()
<<
"
\n
"
;
value
[
"key"
][
"key"
]
=
"value"
;
std
::
cout
<<
value
[
"key"
][
"key"
].
as
<
std
::
string
>
()
<<
"
\n
"
;
//
value[5] = "monkey";
//
std::cout << value[5].as<std::string>() << "\n";
//
value["monkey"] = 5;
//
std::cout << value["monkey"].as<int>() << "\n";
value
[
5
]
=
"monkey"
;
std
::
cout
<<
value
[
5
].
as
<
std
::
string
>
()
<<
"
\n
"
;
value
[
"monkey"
]
=
5
;
std
::
cout
<<
value
[
"monkey"
].
as
<
int
>
()
<<
"
\n
"
;
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