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
a95baeaf
Commit
a95baeaf
authored
Sep 07, 2011
by
Jesse Beder
Browse files
Implemented conversion for std::string, including a bypass-accessor to the scalar value
parent
1ab16bac
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
41 additions
and
3 deletions
+41
-3
include/yaml-cpp/value/detail/node.h
include/yaml-cpp/value/detail/node.h
+3
-2
include/yaml-cpp/value/detail/node_data.h
include/yaml-cpp/value/detail/node_data.h
+1
-1
include/yaml-cpp/value/detail/node_ref.h
include/yaml-cpp/value/detail/node_ref.h
+1
-0
include/yaml-cpp/value/impl.h
include/yaml-cpp/value/impl.h
+13
-0
include/yaml-cpp/value/value.h
include/yaml-cpp/value/value.h
+1
-0
src/value/convert.cpp
src/value/convert.cpp
+17
-0
util/value.cpp
util/value.cpp
+5
-0
No files found.
include/yaml-cpp/value/detail/node.h
View file @
a95baeaf
...
@@ -20,9 +20,10 @@ namespace YAML
...
@@ -20,9 +20,10 @@ namespace YAML
public:
public:
explicit
node
(
shared_node_ref
pRef
)
:
m_pRef
(
pRef
)
{}
explicit
node
(
shared_node_ref
pRef
)
:
m_pRef
(
pRef
)
{}
ValueType
::
value
type
()
const
{
return
m_pRef
->
type
();
}
bool
is
(
const
node
&
rhs
)
const
{
return
m_pRef
==
rhs
.
m_pRef
;
}
bool
is
(
const
node
&
rhs
)
const
{
return
m_pRef
==
rhs
.
m_pRef
;
}
ValueType
::
value
type
()
const
{
return
m_pRef
->
type
();
}
const
std
::
string
&
scalar
()
const
{
return
m_pRef
->
scalar
();
}
void
set_ref
(
const
node
&
rhs
)
{
m_pRef
=
rhs
.
m_pRef
;
}
void
set_ref
(
const
node
&
rhs
)
{
m_pRef
=
rhs
.
m_pRef
;
}
void
set_data
(
const
node
&
rhs
)
{
m_pRef
->
set_data
(
*
rhs
.
m_pRef
);
}
void
set_data
(
const
node
&
rhs
)
{
m_pRef
->
set_data
(
*
rhs
.
m_pRef
);
}
...
...
include/yaml-cpp/value/detail/node_data.h
View file @
a95baeaf
...
@@ -27,7 +27,7 @@ namespace YAML
...
@@ -27,7 +27,7 @@ namespace YAML
void
set_scalar
(
const
std
::
string
&
scalar
);
void
set_scalar
(
const
std
::
string
&
scalar
);
ValueType
::
value
type
()
const
{
return
m_isDefined
?
m_type
:
ValueType
::
Undefined
;
}
ValueType
::
value
type
()
const
{
return
m_isDefined
?
m_type
:
ValueType
::
Undefined
;
}
const
std
::
string
scalar
()
const
{
return
m_scalar
;
}
const
std
::
string
&
scalar
()
const
{
return
m_scalar
;
}
// indexing
// indexing
template
<
typename
Key
>
shared_node
get
(
const
Key
&
key
,
shared_memory_holder
pMemory
)
const
;
template
<
typename
Key
>
shared_node
get
(
const
Key
&
key
,
shared_memory_holder
pMemory
)
const
;
...
...
include/yaml-cpp/value/detail/node_ref.h
View file @
a95baeaf
...
@@ -21,6 +21,7 @@ namespace YAML
...
@@ -21,6 +21,7 @@ namespace YAML
node_ref
()
:
m_pData
(
new
node_data
)
{}
node_ref
()
:
m_pData
(
new
node_data
)
{}
ValueType
::
value
type
()
const
{
return
m_pData
->
type
();
}
ValueType
::
value
type
()
const
{
return
m_pData
->
type
();
}
const
std
::
string
&
scalar
()
const
{
return
m_pData
->
scalar
();
}
void
set_data
(
const
node_ref
&
rhs
)
{
m_pData
=
rhs
.
m_pData
;
}
void
set_data
(
const
node_ref
&
rhs
)
{
m_pData
=
rhs
.
m_pData
;
}
...
...
include/yaml-cpp/value/impl.h
View file @
a95baeaf
...
@@ -56,6 +56,19 @@ namespace YAML
...
@@ -56,6 +56,19 @@ namespace YAML
throw
std
::
runtime_error
(
"Unable to convert to type"
);
throw
std
::
runtime_error
(
"Unable to convert to type"
);
}
}
template
<
>
inline
const
std
::
string
Value
::
as
()
const
{
if
(
Type
()
!=
ValueType
::
Scalar
)
throw
std
::
runtime_error
(
"Unable to convert to string, not a scalar"
);
return
scalar
();
}
inline
const
std
::
string
&
Value
::
scalar
()
const
{
return
m_pNode
->
scalar
();
}
// assignment
// assignment
inline
bool
Value
::
is
(
const
Value
&
rhs
)
const
inline
bool
Value
::
is
(
const
Value
&
rhs
)
const
{
{
...
...
include/yaml-cpp/value/value.h
View file @
a95baeaf
...
@@ -29,6 +29,7 @@ namespace YAML
...
@@ -29,6 +29,7 @@ namespace YAML
// access
// access
template
<
typename
T
>
const
T
as
()
const
;
template
<
typename
T
>
const
T
as
()
const
;
const
std
::
string
&
scalar
()
const
;
// assignment
// assignment
bool
is
(
const
Value
&
rhs
)
const
;
bool
is
(
const
Value
&
rhs
)
const
;
...
...
src/value/convert.cpp
0 → 100644
View file @
a95baeaf
#include "yaml-cpp/value.h"
namespace
YAML
{
template
<
>
Value
convert
(
const
std
::
string
&
rhs
)
{
return
Value
(
rhs
);
}
template
<
>
bool
convert
(
const
Value
&
value
,
std
::
string
&
rhs
)
{
if
(
value
.
Type
()
!=
ValueType
::
Scalar
)
return
false
;
rhs
=
value
.
scalar
();
return
true
;
}
}
util/value.cpp
View file @
a95baeaf
...
@@ -4,6 +4,11 @@ int main()
...
@@ -4,6 +4,11 @@ int main()
{
{
YAML
::
Value
value
;
YAML
::
Value
value
;
value
[
"key"
]
=
"value"
;
value
[
"key"
]
=
"value"
;
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";
return
0
;
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