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
a645866f
Commit
a645866f
authored
Oct 31, 2012
by
Jesse Beder
Browse files
Simplified Node::operator[] interface by removing the C-string overloads, using a helper to_value
parent
d770a7dc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
42 deletions
+49
-42
include/yaml-cpp/node/impl.h
include/yaml-cpp/node/impl.h
+49
-34
include/yaml-cpp/node/node.h
include/yaml-cpp/node/node.h
+0
-8
No files found.
include/yaml-cpp/node/impl.h
View file @
a645866f
...
@@ -123,7 +123,7 @@ namespace YAML
...
@@ -123,7 +123,7 @@ namespace YAML
return
node
.
Scalar
();
return
node
.
Scalar
();
}
}
};
};
// access functions
// access functions
template
<
typename
T
>
template
<
typename
T
>
inline
const
T
Node
::
as
()
const
inline
const
T
Node
::
as
()
const
...
@@ -267,12 +267,57 @@ namespace YAML
...
@@ -267,12 +267,57 @@ namespace YAML
m_pMemory
->
merge
(
*
rhs
.
m_pMemory
);
m_pMemory
->
merge
(
*
rhs
.
m_pMemory
);
}
}
// helpers for indexing
namespace
detail
{
template
<
typename
T
>
struct
to_value_t
{
explicit
to_value_t
(
const
T
&
t_
)
:
t
(
t_
)
{}
const
T
&
t
;
typedef
const
T
&
return_type
;
const
T
&
operator
()()
const
{
return
t
;
}
};
template
<
>
struct
to_value_t
<
const
char
*>
{
explicit
to_value_t
(
const
char
*
t_
)
:
t
(
t_
)
{}
const
char
*
t
;
typedef
std
::
string
return_type
;
const
std
::
string
operator
()()
const
{
return
t
;
}
};
template
<
>
struct
to_value_t
<
char
*>
{
explicit
to_value_t
(
char
*
t_
)
:
t
(
t_
)
{}
const
char
*
t
;
typedef
std
::
string
return_type
;
const
std
::
string
operator
()()
const
{
return
t
;
}
};
template
<
std
::
size_t
N
>
struct
to_value_t
<
char
[
N
]
>
{
explicit
to_value_t
(
const
char
*
t_
)
:
t
(
t_
)
{}
const
char
*
t
;
typedef
std
::
string
return_type
;
const
std
::
string
operator
()()
const
{
return
t
;
}
};
// converts C-strings to std::strings so they can be copied
template
<
typename
T
>
inline
typename
to_value_t
<
T
>::
return_type
to_value
(
const
T
&
t
)
{
return
to_value_t
<
T
>
(
t
)();
}
}
// indexing
// indexing
template
<
typename
Key
>
template
<
typename
Key
>
inline
const
Node
Node
::
operator
[](
const
Key
&
key
)
const
inline
const
Node
Node
::
operator
[](
const
Key
&
key
)
const
{
{
EnsureNodeExists
();
EnsureNodeExists
();
detail
::
node
&
value
=
static_cast
<
const
detail
::
node
&>
(
*
m_pNode
).
get
(
key
,
m_pMemory
);
detail
::
node
&
value
=
static_cast
<
const
detail
::
node
&>
(
*
m_pNode
).
get
(
detail
::
to_value
(
key
)
,
m_pMemory
);
return
Node
(
value
,
m_pMemory
);
return
Node
(
value
,
m_pMemory
);
}
}
...
@@ -280,7 +325,7 @@ namespace YAML
...
@@ -280,7 +325,7 @@ namespace YAML
inline
Node
Node
::
operator
[](
const
Key
&
key
)
inline
Node
Node
::
operator
[](
const
Key
&
key
)
{
{
EnsureNodeExists
();
EnsureNodeExists
();
detail
::
node
&
value
=
m_pNode
->
get
(
key
,
m_pMemory
);
detail
::
node
&
value
=
m_pNode
->
get
(
detail
::
to_value
(
key
)
,
m_pMemory
);
return
Node
(
value
,
m_pMemory
);
return
Node
(
value
,
m_pMemory
);
}
}
...
@@ -288,7 +333,7 @@ namespace YAML
...
@@ -288,7 +333,7 @@ namespace YAML
inline
bool
Node
::
remove
(
const
Key
&
key
)
inline
bool
Node
::
remove
(
const
Key
&
key
)
{
{
EnsureNodeExists
();
EnsureNodeExists
();
return
m_pNode
->
remove
(
key
,
m_pMemory
);
return
m_pNode
->
remove
(
detail
::
to_value
(
key
)
,
m_pMemory
);
}
}
inline
const
Node
Node
::
operator
[](
const
Node
&
key
)
const
inline
const
Node
Node
::
operator
[](
const
Node
&
key
)
const
...
@@ -313,36 +358,6 @@ namespace YAML
...
@@ -313,36 +358,6 @@ namespace YAML
key
.
EnsureNodeExists
();
key
.
EnsureNodeExists
();
return
m_pNode
->
remove
(
*
key
.
m_pNode
,
m_pMemory
);
return
m_pNode
->
remove
(
*
key
.
m_pNode
,
m_pMemory
);
}
}
inline
const
Node
Node
::
operator
[](
const
char
*
key
)
const
{
return
operator
[](
std
::
string
(
key
));
}
inline
Node
Node
::
operator
[](
const
char
*
key
)
{
return
operator
[](
std
::
string
(
key
));
}
inline
bool
Node
::
remove
(
const
char
*
key
)
{
return
remove
(
std
::
string
(
key
));
}
inline
const
Node
Node
::
operator
[](
char
*
key
)
const
{
return
operator
[](
static_cast
<
const
char
*>
(
key
));
}
inline
Node
Node
::
operator
[](
char
*
key
)
{
return
operator
[](
static_cast
<
const
char
*>
(
key
));
}
inline
bool
Node
::
remove
(
char
*
key
)
{
return
remove
(
static_cast
<
const
char
*>
(
key
));
}
// free functions
// free functions
...
...
include/yaml-cpp/node/node.h
View file @
a645866f
...
@@ -78,15 +78,7 @@ namespace YAML
...
@@ -78,15 +78,7 @@ namespace YAML
const
Node
operator
[](
const
Node
&
key
)
const
;
const
Node
operator
[](
const
Node
&
key
)
const
;
Node
operator
[](
const
Node
&
key
);
Node
operator
[](
const
Node
&
key
);
bool
remove
(
const
Node
&
key
);
bool
remove
(
const
Node
&
key
);
const
Node
operator
[](
const
char
*
key
)
const
;
Node
operator
[](
const
char
*
key
);
bool
remove
(
const
char
*
key
);
const
Node
operator
[](
char
*
key
)
const
;
Node
operator
[](
char
*
key
);
bool
remove
(
char
*
key
);
private:
private:
explicit
Node
(
detail
::
node
&
node
,
detail
::
shared_memory_holder
pMemory
);
explicit
Node
(
detail
::
node
&
node
,
detail
::
shared_memory_holder
pMemory
);
...
...
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