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
c4b3b5e5
"...csrc/git@developer.sourcefind.cn:change/sglang.git" did not exist on "43baba649e43d198eea73f58cd50882530763ebc"
Commit
c4b3b5e5
authored
Nov 13, 2011
by
beder
Browse files
Added (unspecified-type) bool conversions for Node (new API)
parent
50b6a029
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
48 additions
and
0 deletions
+48
-0
include/yaml-cpp/node/detail/bool_type.h
include/yaml-cpp/node/detail/bool_type.h
+26
-0
include/yaml-cpp/node/impl.h
include/yaml-cpp/node/impl.h
+5
-0
include/yaml-cpp/node/node.h
include/yaml-cpp/node/node.h
+6
-0
test/new-api/nodetests.cpp
test/new-api/nodetests.cpp
+11
-0
No files found.
include/yaml-cpp/node/detail/bool_type.h
0 → 100644
View file @
c4b3b5e5
#ifndef NODE_DETAIL_BOOL_TYPE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define NODE_DETAIL_BOOL_TYPE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
namespace
YAML
{
namespace
detail
{
struct
unspecified_bool
{
struct
NOT_ALLOWED
;
static
void
true_value
(
NOT_ALLOWED
*
)
{}
};
typedef
void
(
*
unspecified_bool_type
)(
unspecified_bool
::
NOT_ALLOWED
*
);
}
}
#define YAML_CPP_OPERATOR_BOOL()\
operator YAML::detail::unspecified_bool_type() const\
{\
return this->operator!() ? 0 : &YAML::detail::unspecified_bool::true_value;\
}
#endif // NODE_DETAIL_BOOL_TYPE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
include/yaml-cpp/node/impl.h
View file @
c4b3b5e5
...
@@ -50,6 +50,11 @@ namespace YAML
...
@@ -50,6 +50,11 @@ namespace YAML
}
}
}
}
inline
bool
Node
::
IsDefined
()
const
{
return
m_pNode
?
m_pNode
->
is_defined
()
:
true
;
}
inline
NodeType
::
value
Node
::
Type
()
const
inline
NodeType
::
value
Node
::
Type
()
const
{
{
return
m_pNode
?
m_pNode
->
type
()
:
NodeType
::
Null
;
return
m_pNode
?
m_pNode
->
type
()
:
NodeType
::
Null
;
...
...
include/yaml-cpp/node/node.h
View file @
c4b3b5e5
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
#include "yaml-cpp/node/ptr.h"
#include "yaml-cpp/node/ptr.h"
#include "yaml-cpp/node/type.h"
#include "yaml-cpp/node/type.h"
#include "yaml-cpp/node/detail/iterator_fwd.h"
#include "yaml-cpp/node/detail/iterator_fwd.h"
#include "yaml-cpp/node/detail/bool_type.h"
#include <stdexcept>
#include <stdexcept>
namespace
YAML
namespace
YAML
...
@@ -29,11 +30,16 @@ namespace YAML
...
@@ -29,11 +30,16 @@ namespace YAML
~
Node
();
~
Node
();
NodeType
::
value
Type
()
const
;
NodeType
::
value
Type
()
const
;
bool
IsDefined
()
const
;
bool
IsNull
()
const
{
return
Type
()
==
NodeType
::
Null
;
}
bool
IsNull
()
const
{
return
Type
()
==
NodeType
::
Null
;
}
bool
IsScalar
()
const
{
return
Type
()
==
NodeType
::
Scalar
;
}
bool
IsScalar
()
const
{
return
Type
()
==
NodeType
::
Scalar
;
}
bool
IsSequence
()
const
{
return
Type
()
==
NodeType
::
Sequence
;
}
bool
IsSequence
()
const
{
return
Type
()
==
NodeType
::
Sequence
;
}
bool
IsMap
()
const
{
return
Type
()
==
NodeType
::
Map
;
}
bool
IsMap
()
const
{
return
Type
()
==
NodeType
::
Map
;
}
// bool conversions
YAML_CPP_OPERATOR_BOOL
();
bool
operator
!
()
const
{
return
!
IsDefined
();
}
// access
// access
template
<
typename
T
>
const
T
as
()
const
;
template
<
typename
T
>
const
T
as
()
const
;
const
std
::
string
&
Scalar
()
const
;
const
std
::
string
&
Scalar
()
const
;
...
...
test/new-api/nodetests.cpp
View file @
c4b3b5e5
...
@@ -268,6 +268,16 @@ namespace Test
...
@@ -268,6 +268,16 @@ namespace Test
YAML_ASSERT
(
node
[
true
].
as
<
bool
>
()
==
false
);
YAML_ASSERT
(
node
[
true
].
as
<
bool
>
()
==
false
);
return
true
;
return
true
;
}
}
TEST
AutoBoolConversion
()
{
YAML
::
Node
node
;
node
[
"foo"
]
=
"bar"
;
YAML_ASSERT
(
static_cast
<
bool
>
(
node
[
"foo"
]));
YAML_ASSERT
(
!
node
[
"monkey"
]);
YAML_ASSERT
(
!!
node
[
"foo"
]);
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
)
{
...
@@ -312,6 +322,7 @@ namespace Test
...
@@ -312,6 +322,7 @@ namespace Test
RunNodeTest
(
&
Node
::
TempMapVariable
,
"temp map variable"
,
passed
,
total
);
RunNodeTest
(
&
Node
::
TempMapVariable
,
"temp map variable"
,
passed
,
total
);
RunNodeTest
(
&
Node
::
TempMapVariableAlias
,
"temp map variable alias"
,
passed
,
total
);
RunNodeTest
(
&
Node
::
TempMapVariableAlias
,
"temp map variable alias"
,
passed
,
total
);
RunNodeTest
(
&
Node
::
Bool
,
"bool"
,
passed
,
total
);
RunNodeTest
(
&
Node
::
Bool
,
"bool"
,
passed
,
total
);
RunNodeTest
(
&
Node
::
AutoBoolConversion
,
"auto bool conversion"
,
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