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
d1eca902
Commit
d1eca902
authored
Sep 07, 2011
by
Jesse Beder
Browse files
Implemented map get(), and it would work (I think) if we implemented convert() for strings
parent
020cd979
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
12 deletions
+61
-12
include/yaml-cpp/value/detail/impl.h
include/yaml-cpp/value/detail/impl.h
+53
-0
include/yaml-cpp/value/detail/node_data.h
include/yaml-cpp/value/detail/node_data.h
+6
-0
include/yaml-cpp/value/impl.h
include/yaml-cpp/value/impl.h
+0
-9
include/yaml-cpp/value/value.h
include/yaml-cpp/value/value.h
+2
-3
No files found.
include/yaml-cpp/value/detail/impl.h
View file @
d1eca902
...
...
@@ -31,11 +31,64 @@ namespace YAML
template
<
typename
Key
>
inline
shared_node
node_data
::
get
(
const
Key
&
key
,
shared_memory_holder
pMemory
)
{
// TODO: check if 'key' is index-like, and we're a sequence
switch
(
m_type
)
{
case
ValueType
::
Undefined
:
case
ValueType
::
Null
:
case
ValueType
::
Scalar
:
m_type
=
ValueType
::
Map
;
m_map
.
clear
();
break
;
case
ValueType
::
Sequence
:
convert_sequence_to_map
();
break
;
case
ValueType
::
Map
:
break
;
}
for
(
node_map
::
const_iterator
it
=
m_map
.
begin
();
it
!=
m_map
.
end
();
++
it
)
{
if
(
equals
(
it
->
first
,
key
,
pMemory
))
return
it
->
second
;
}
shared_node
pKey
=
convert_to_node
(
key
,
pMemory
);
shared_node
pValue
(
new
node
);
m_map
.
push_back
(
kv_pair
(
pKey
,
pValue
));
return
pValue
;
}
template
<
typename
Key
>
inline
bool
node_data
::
remove
(
const
Key
&
key
,
shared_memory_holder
pMemory
)
{
if
(
m_type
!=
ValueType
::
Map
)
return
false
;
for
(
node_map
::
iterator
it
=
m_map
.
begin
();
it
!=
m_map
.
end
();
++
it
)
{
if
(
equals
(
it
->
first
,
key
,
pMemory
))
{
m_map
.
erase
(
it
);
return
true
;
}
}
return
false
;
}
template
<
typename
T
>
inline
bool
node_data
::
equals
(
detail
::
shared_node
pNode
,
const
T
&
rhs
,
detail
::
shared_memory_holder
pMemory
)
{
T
lhs
;
if
(
convert
(
Value
(
pNode
,
pMemory
),
lhs
))
return
lhs
==
rhs
;
return
false
;
}
template
<
typename
T
>
inline
shared_node
node_data
::
convert_to_node
(
const
T
&
rhs
,
detail
::
shared_memory_holder
pMemory
)
{
Value
value
=
convert
(
rhs
);
pMemory
->
merge
(
*
value
.
m_pMemory
);
return
value
.
m_pNode
;
}
}
}
...
...
include/yaml-cpp/value/detail/node_data.h
View file @
d1eca902
...
...
@@ -40,6 +40,12 @@ namespace YAML
private:
void
convert_sequence_to_map
();
template
<
typename
T
>
static
bool
equals
(
detail
::
shared_node
pNode
,
const
T
&
rhs
,
detail
::
shared_memory_holder
pMemory
);
template
<
typename
T
>
static
shared_node
convert_to_node
(
const
T
&
rhs
,
detail
::
shared_memory_holder
pMemory
);
private:
bool
m_isDefined
;
...
...
include/yaml-cpp/value/impl.h
View file @
d1eca902
...
...
@@ -215,15 +215,6 @@ namespace YAML
{
return
false
;
}
template
<
typename
T
>
inline
bool
equals
(
detail
::
shared_node
pNode
,
const
T
&
rhs
,
detail
::
shared_memory_holder
pMemory
)
{
T
lhs
;
if
(
convert
(
Value
(
pNode
,
pMemory
),
lhs
))
return
lhs
==
rhs
;
return
false
;
}
}
#endif // VALUE_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
include/yaml-cpp/value/value.h
View file @
d1eca902
...
...
@@ -17,6 +17,8 @@ namespace YAML
class
Value
{
public:
friend
class
detail
::
node_data
;
Value
();
explicit
Value
(
ValueType
::
value
type
);
template
<
typename
T
>
explicit
Value
(
const
T
&
rhs
);
...
...
@@ -61,9 +63,6 @@ namespace YAML
private:
explicit
Value
(
detail
::
shared_node
pNode
,
detail
::
shared_memory_holder
pMemory
);
template
<
typename
T
>
friend
bool
equals
(
detail
::
shared_node
pNode
,
const
T
&
rhs
,
detail
::
shared_memory_holder
pMemory
);
template
<
typename
T
>
void
Assign
(
const
T
&
rhs
);
void
Assign
(
const
char
*
rhs
);
void
Assign
(
char
*
rhs
);
...
...
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