Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yaml-cpp
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
yaml-cpp
Commits
32491166
Commit
32491166
authored
Nov 10, 2009
by
Jesse Beder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replaced conversion macros with SFINAE
parent
6f94f954
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
21 deletions
+59
-21
CMakeLists.txt
+1
-1
include/conversion.h
+31
-19
test/parsertests.cpp
+27
-1
No files found.
CMakeLists.txt
View file @
32491166
...
@@ -10,7 +10,7 @@ if(IPHONE)
...
@@ -10,7 +10,7 @@ if(IPHONE)
endif
(
IPHONE
)
endif
(
IPHONE
)
if
(
CMAKE_COMPILER_IS_GNUCC
)
if
(
CMAKE_COMPILER_IS_GNUCC
)
set
(
CMAKE_CXX_FLAGS
"-O2 -Wall -
pedantic -Wextra
${
CMAKE_CXX_FLAGS
}
"
)
set
(
CMAKE_CXX_FLAGS
"-O2 -Wall -
Wextra -pedantic -Wno-long-long
${
CMAKE_CXX_FLAGS
}
"
)
endif
(
CMAKE_COMPILER_IS_GNUCC
)
endif
(
CMAKE_COMPILER_IS_GNUCC
)
set
(
YAML_CPP_VERSION_MAJOR
"0"
)
set
(
YAML_CPP_VERSION_MAJOR
"0"
)
...
...
include/conversion.h
View file @
32491166
...
@@ -18,26 +18,38 @@ namespace YAML
...
@@ -18,26 +18,38 @@ namespace YAML
bool
Convert
(
const
std
::
string
&
input
,
bool
&
output
);
bool
Convert
(
const
std
::
string
&
input
,
bool
&
output
);
bool
Convert
(
const
std
::
string
&
input
,
_Null
&
output
);
bool
Convert
(
const
std
::
string
&
input
,
_Null
&
output
);
#define YAML_MAKE_STREAM_CONVERT(type) \
template
<
typename
>
inline bool Convert(const std::string& input, type& output) { \
struct
is_numeric
{
enum
{
value
=
false
};
};
std::stringstream stream(input); \
stream.unsetf(std::ios::dec); \
template
<>
struct
is_numeric
<
char
>
{
enum
{
value
=
true
};
};
return stream >> output; \
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
#endif // CONVERSION_H_62B23520_7C8E_11DE_8A39_0800200C9A66
test/parsertests.cpp
View file @
32491166
...
@@ -620,7 +620,6 @@ namespace Test
...
@@ -620,7 +620,6 @@ namespace Test
std
::
stringstream
stream
(
input
);
std
::
stringstream
stream
(
input
);
YAML
::
Parser
parser
(
stream
);
YAML
::
Parser
parser
(
stream
);
YAML
::
Node
doc
;
YAML
::
Node
doc
;
std
::
string
output
;
parser
.
GetNextDocument
(
doc
);
parser
.
GetNextDocument
(
doc
);
if
(
doc
.
size
()
!=
2
)
if
(
doc
.
size
()
!=
2
)
...
@@ -632,6 +631,32 @@ namespace Test
...
@@ -632,6 +631,32 @@ namespace Test
return
true
;
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
{
namespace
{
...
@@ -892,6 +917,7 @@ namespace Test
...
@@ -892,6 +917,7 @@ namespace Test
RunParserTest
(
&
Parser
::
ExplicitEndDoc
,
"explicit end doc"
,
passed
,
total
);
RunParserTest
(
&
Parser
::
ExplicitEndDoc
,
"explicit end doc"
,
passed
,
total
);
RunParserTest
(
&
Parser
::
MultipleDocsWithSomeExplicitIndicators
,
"multiple docs with some explicit indicators"
,
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
::
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
,
false
,
"UTF-8, no BOM"
,
passed
,
total
);
RunEncodingTest
(
&
EncodeToUtf8
,
true
,
"UTF-8 with 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