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
63cc5ade
".github/vscode:/vscode.git/clone" did not exist on "3c85a57297b22df8921bae39c0a2e3982ee69de7"
Commit
63cc5ade
authored
Nov 10, 2009
by
jbeder
Browse files
Replaced conversion macros with SFINAE
parent
71489e5a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
22 deletions
+60
-22
CMakeLists.txt
CMakeLists.txt
+1
-1
include/conversion.h
include/conversion.h
+31
-19
test/parsertests.cpp
test/parsertests.cpp
+28
-2
No files found.
CMakeLists.txt
View file @
63cc5ade
...
...
@@ -10,7 +10,7 @@ if(IPHONE)
endif
(
IPHONE
)
if
(
CMAKE_COMPILER_IS_GNUCC
)
set
(
CMAKE_CXX_FLAGS
"-O2 -Wall -pedantic -W
extra
${
CMAKE_CXX_FLAGS
}
"
)
set
(
CMAKE_CXX_FLAGS
"-O2 -Wall
-Wextra
-pedantic -W
no-long-long
${
CMAKE_CXX_FLAGS
}
"
)
endif
(
CMAKE_COMPILER_IS_GNUCC
)
set
(
YAML_CPP_VERSION_MAJOR
"0"
)
...
...
include/conversion.h
View file @
63cc5ade
...
...
@@ -18,26 +18,38 @@ namespace YAML
bool
Convert
(
const
std
::
string
&
input
,
bool
&
output
);
bool
Convert
(
const
std
::
string
&
input
,
_Null
&
output
);
#define YAML_MAKE_STREAM_CONVERT(type) \
inline bool Convert(const std::string& input, type& output) { \
std::stringstream stream(input); \
stream.unsetf(std::ios::dec); \
return stream >> output; \
template
<
typename
>
struct
is_numeric
{
enum
{
value
=
false
};
};
template
<
>
struct
is_numeric
<
char
>
{
enum
{
value
=
true
};
};
template
<
>
struct
is_numeric
<
unsigned
char
>
{
enum
{
value
=
true
};
};
template
<
>
struct
is_numeric
<
int
>
{
enum
{
value
=
true
};
};
template
<
>
struct
is_numeric
<
unsigned
int
>
{
enum
{
value
=
true
};
};
template
<
>
struct
is_numeric
<
long
int
>
{
enum
{
value
=
true
};
};
template
<
>
struct
is_numeric
<
unsigned
long
int
>
{
enum
{
value
=
true
};
};
template
<
>
struct
is_numeric
<
short
int
>
{
enum
{
value
=
true
};
};
template
<
>
struct
is_numeric
<
unsigned
short
int
>
{
enum
{
value
=
true
};
};
template
<
>
struct
is_numeric
<
long
long
>
{
enum
{
value
=
true
};
};
template
<
>
struct
is_numeric
<
unsigned
long
long
>
{
enum
{
value
=
true
};
};
template
<
>
struct
is_numeric
<
float
>
{
enum
{
value
=
true
};
};
template
<
>
struct
is_numeric
<
double
>
{
enum
{
value
=
true
};
};
template
<
>
struct
is_numeric
<
long
double
>
{
enum
{
value
=
true
};
};
template
<
typename
T
,
typename
,
bool
=
T
::
value
>
struct
enable_if
;
template
<
typename
T
,
typename
R
>
struct
enable_if
<
T
,
R
,
true
>
{
typedef
R
type
;
};
template
<
typename
T
>
inline
bool
Convert
(
const
std
::
string
&
input
,
T
&
output
,
typename
enable_if
<
is_numeric
<
T
>
,
T
>::
type
*
=
0
)
{
std
::
stringstream
stream
(
input
);
stream
.
unsetf
(
std
::
ios
::
dec
);
return
stream
>>
output
;
}
YAML_MAKE_STREAM_CONVERT
(
char
)
YAML_MAKE_STREAM_CONVERT
(
unsigned
char
)
YAML_MAKE_STREAM_CONVERT
(
int
)
YAML_MAKE_STREAM_CONVERT
(
unsigned
int
)
YAML_MAKE_STREAM_CONVERT
(
short
)
YAML_MAKE_STREAM_CONVERT
(
unsigned
short
)
YAML_MAKE_STREAM_CONVERT
(
long
)
YAML_MAKE_STREAM_CONVERT
(
unsigned
long
)
YAML_MAKE_STREAM_CONVERT
(
float
)
YAML_MAKE_STREAM_CONVERT
(
double
)
YAML_MAKE_STREAM_CONVERT
(
long
double
)
#undef YAML_MAKE_STREAM_CONVERT
}
#endif // CONVERSION_H_62B23520_7C8E_11DE_8A39_0800200C9A66
test/parsertests.cpp
View file @
63cc5ade
...
...
@@ -118,7 +118,7 @@ namespace Test
inputScalar
=
"http://example.com/foo#bar"
;
desiredOutput
=
"http://example.com/foo#bar"
;
}
bool
SimpleSeq
()
{
std
::
string
input
=
...
...
@@ -620,7 +620,6 @@ namespace Test
std
::
stringstream
stream
(
input
);
YAML
::
Parser
parser
(
stream
);
YAML
::
Node
doc
;
std
::
string
output
;
parser
.
GetNextDocument
(
doc
);
if
(
doc
.
size
()
!=
2
)
...
...
@@ -632,6 +631,32 @@ namespace Test
return
true
;
}
bool
Bases
()
{
std
::
string
input
=
"- 15
\n
"
"- 0x10
\n
"
"- 030
\n
"
"- 0xffffffff
\n
"
;
std
::
stringstream
stream
(
input
);
YAML
::
Parser
parser
(
stream
);
YAML
::
Node
doc
;
parser
.
GetNextDocument
(
doc
);
if
(
doc
.
size
()
!=
4
)
return
false
;
if
(
doc
[
0
]
!=
15
)
return
false
;
if
(
doc
[
1
]
!=
0x10
)
return
false
;
if
(
doc
[
2
]
!=
030
)
return
false
;
if
(
doc
[
3
]
!=
0xffffffff
)
return
false
;
return
true
;
}
}
namespace
{
...
...
@@ -892,6 +917,7 @@ namespace Test
RunParserTest
(
&
Parser
::
ExplicitEndDoc
,
"explicit end doc"
,
passed
,
total
);
RunParserTest
(
&
Parser
::
MultipleDocsWithSomeExplicitIndicators
,
"multiple docs with some explicit indicators"
,
passed
,
total
);
RunParserTest
(
&
Parser
::
BlockKeyWithNullValue
,
"block key with null value"
,
passed
,
total
);
RunParserTest
(
&
Parser
::
Bases
,
"bases"
,
passed
,
total
);
RunEncodingTest
(
&
EncodeToUtf8
,
false
,
"UTF-8, no BOM"
,
passed
,
total
);
RunEncodingTest
(
&
EncodeToUtf8
,
true
,
"UTF-8 with BOM"
,
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