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
4568dd0b
Commit
4568dd0b
authored
Sep 11, 2011
by
Jesse Beder
Browse files
Started specialization for operator[] for integers
parent
a308b73e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
27 deletions
+77
-27
include/yaml-cpp/node/detail/impl.h
include/yaml-cpp/node/detail/impl.h
+41
-12
include/yaml-cpp/node/detail/node_data.h
include/yaml-cpp/node/detail/node_data.h
+2
-0
src/node/detail/node_data.cpp
src/node/detail/node_data.cpp
+34
-15
No files found.
include/yaml-cpp/node/detail/impl.h
View file @
4568dd0b
...
...
@@ -13,12 +13,42 @@ namespace YAML
{
namespace
detail
{
template
<
typename
Key
,
typename
Enable
=
void
>
struct
get_idx_helper
{
static
node
*
get
(
const
Key
&
/* key */
,
shared_memory_holder
/* pMemory */
)
{
return
0
;
}
};
template
<
typename
Key
>
struct
get_idx_helper
<
Key
,
typename
boost
::
enable_if
<
boost
::
is_integral
<
Key
>
>::
type
>
{
static
node
*
get
(
const
Key
&
key
,
shared_memory_holder
pMemory
)
{
return
0
;
}
};
template
<
typename
Key
>
inline
node
*
get_idx
(
const
Key
&
key
,
shared_memory_holder
pMemory
)
{
return
get_idx_helper
<
Key
>::
get
(
key
,
pMemory
);
}
// indexing
template
<
typename
Key
>
inline
node
&
node_data
::
get
(
const
Key
&
key
,
shared_memory_holder
pMemory
)
const
{
if
(
m_type
!=
NodeType
::
Map
)
switch
(
m_type
)
{
case
NodeType
::
Map
:
break
;
case
NodeType
::
Undefined
:
case
NodeType
::
Null
:
return
pMemory
->
create_node
();
case
NodeType
::
Sequence
:
if
(
node
*
pNode
=
get_idx
(
key
,
pMemory
))
return
*
pNode
;
return
pMemory
->
create_node
();
case
NodeType
::
Scalar
:
throw
std
::
runtime_error
(
"Can't call operator[] on a scalar"
);
}
for
(
node_map
::
const_iterator
it
=
m_map
.
begin
();
it
!=
m_map
.
end
();
++
it
)
{
if
(
equals
(
*
it
->
first
,
key
,
pMemory
))
...
...
@@ -31,20 +61,19 @@ namespace YAML
template
<
typename
Key
>
inline
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
NodeType
::
Map
:
break
;
case
NodeType
::
Undefined
:
case
NodeType
::
Null
:
case
NodeType
::
Scalar
:
m_type
=
NodeType
::
Map
;
m_map
.
clear
();
break
;
case
NodeType
::
Sequence
:
convert_sequence_to_map
(
pMemory
);
break
;
case
NodeType
::
Map
:
if
(
node
*
pNode
=
get_idx
(
key
,
pMemory
))
return
*
pNode
;
convert_to_map
(
pMemory
);
break
;
case
NodeType
::
Scalar
:
throw
std
::
runtime_error
(
"Can't call operator[] on a scalar"
);
}
for
(
node_map
::
const_iterator
it
=
m_map
.
begin
();
it
!=
m_map
.
end
();
++
it
)
{
...
...
include/yaml-cpp/node/detail/node_data.h
View file @
4568dd0b
...
...
@@ -64,7 +64,9 @@ namespace YAML
void
reset_sequence
();
void
reset_map
();
void
insert_map_pair
(
node
&
key
,
node
&
value
);
void
convert_to_map
(
shared_memory_holder
pMemory
);
void
convert_sequence_to_map
(
shared_memory_holder
pMemory
);
template
<
typename
T
>
...
...
src/node/detail/node_data.cpp
View file @
4568dd0b
...
...
@@ -163,16 +163,18 @@ namespace YAML
void
node_data
::
insert
(
node
&
key
,
node
&
value
,
shared_memory_holder
pMemory
)
{
if
(
m_type
==
NodeType
::
Undefined
||
m_type
==
NodeType
::
Null
)
{
m_type
=
NodeType
::
Map
;
reset_map
();
}
else
if
(
m_type
==
NodeType
::
Sequence
)
{
convert_sequence_to_map
(
pMemory
);
switch
(
m_type
)
{
case
NodeType
::
Map
:
break
;
case
NodeType
::
Undefined
:
case
NodeType
::
Null
:
case
NodeType
::
Sequence
:
convert_to_map
(
pMemory
);
break
;
case
NodeType
::
Scalar
:
throw
std
::
runtime_error
(
"Can't call operator[] on a scalar"
);
}
if
(
m_type
!=
NodeType
::
Map
)
throw
std
::
runtime_error
(
"Can't insert into a non-map node"
);
insert_map_pair
(
key
,
value
);
}
...
...
@@ -193,17 +195,15 @@ namespace YAML
node
&
node_data
::
get
(
node
&
key
,
shared_memory_holder
pMemory
)
{
switch
(
m_type
)
{
case
NodeType
::
Map
:
break
;
case
NodeType
::
Undefined
:
case
NodeType
::
Null
:
case
NodeType
::
Scalar
:
m_type
=
NodeType
::
Map
;
reset_map
();
break
;
case
NodeType
::
Sequence
:
convert_sequence_to_map
(
pMemory
);
break
;
case
NodeType
::
Map
:
convert_to_map
(
pMemory
);
break
;
case
NodeType
::
Scalar
:
throw
std
::
runtime_error
(
"Can't call operator[] on a scalar"
);
}
for
(
node_map
::
const_iterator
it
=
m_map
.
begin
();
it
!=
m_map
.
end
();
++
it
)
{
...
...
@@ -250,6 +250,25 @@ namespace YAML
m_undefinedPairs
.
push_back
(
kv_pair
(
&
key
,
&
value
));
}
void
node_data
::
convert_to_map
(
shared_memory_holder
pMemory
)
{
switch
(
m_type
)
{
case
NodeType
::
Undefined
:
case
NodeType
::
Null
:
reset_map
();
m_type
=
NodeType
::
Map
;
break
;
case
NodeType
::
Sequence
:
convert_sequence_to_map
(
pMemory
);
break
;
case
NodeType
::
Map
:
break
;
case
NodeType
::
Scalar
:
assert
(
false
);
break
;
}
}
void
node_data
::
convert_sequence_to_map
(
shared_memory_holder
pMemory
)
{
assert
(
m_type
==
NodeType
::
Sequence
);
...
...
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