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
020cd979
Commit
020cd979
authored
Sep 07, 2011
by
Jesse Beder
Browse files
Set up map searching by templated key
parent
f0174ca0
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
37 additions
and
31 deletions
+37
-31
include/yaml-cpp/value/detail/impl.h
include/yaml-cpp/value/detail/impl.h
+4
-4
include/yaml-cpp/value/detail/node.h
include/yaml-cpp/value/detail/node.h
+7
-13
include/yaml-cpp/value/detail/node_data.h
include/yaml-cpp/value/detail/node_data.h
+5
-5
include/yaml-cpp/value/impl.h
include/yaml-cpp/value/impl.h
+16
-7
include/yaml-cpp/value/value.h
include/yaml-cpp/value/value.h
+3
-0
src/value/detail/node_data.cpp
src/value/detail/node_data.cpp
+2
-2
No files found.
include/yaml-cpp/value/detail/impl.h
View file @
020cd979
...
@@ -15,13 +15,13 @@ namespace YAML
...
@@ -15,13 +15,13 @@ namespace YAML
{
{
// indexing
// indexing
template
<
typename
Key
>
template
<
typename
Key
>
inline
shared_node
node_data
::
operator
[]
(
const
Key
&
key
)
const
inline
shared_node
node_data
::
get
(
const
Key
&
key
,
shared_memory_holder
pMemory
)
const
{
{
if
(
m_type
!=
ValueType
::
Map
)
if
(
m_type
!=
ValueType
::
Map
)
return
shared_node
(
new
node
);
return
shared_node
(
new
node
);
for
(
node_map
::
const_iterator
it
=
m_map
.
begin
();
it
!=
m_map
.
end
();
++
it
)
{
for
(
node_map
::
const_iterator
it
=
m_map
.
begin
();
it
!=
m_map
.
end
();
++
it
)
{
if
(
it
->
first
->
equals
(
ke
y
))
if
(
equals
(
it
->
first
,
key
,
pMemor
y
))
return
it
->
second
;
return
it
->
second
;
}
}
...
@@ -29,12 +29,12 @@ namespace YAML
...
@@ -29,12 +29,12 @@ namespace YAML
}
}
template
<
typename
Key
>
template
<
typename
Key
>
inline
shared_node
node_data
::
operator
[]
(
const
Key
&
key
)
inline
shared_node
node_data
::
get
(
const
Key
&
key
,
shared_memory_holder
pMemory
)
{
{
}
}
template
<
typename
Key
>
template
<
typename
Key
>
inline
bool
node_data
::
remove
(
const
Key
&
key
)
inline
bool
node_data
::
remove
(
const
Key
&
key
,
shared_memory_holder
pMemory
)
{
{
}
}
}
}
...
...
include/yaml-cpp/value/detail/node.h
View file @
020cd979
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
#include "yaml-cpp/dll.h"
#include "yaml-cpp/dll.h"
#include "yaml-cpp/value/type.h"
#include "yaml-cpp/value/type.h"
#include "yaml-cpp/value/ptr.h"
#include "yaml-cpp/value/ptr.h"
#include "yaml-cpp/value/value.h"
#include "yaml-cpp/value/detail/node_data.h"
#include "yaml-cpp/value/detail/node_data.h"
namespace
YAML
namespace
YAML
...
@@ -28,25 +29,18 @@ namespace YAML
...
@@ -28,25 +29,18 @@ namespace YAML
void
set_null
()
{
m_pData
->
set_null
();
}
void
set_null
()
{
m_pData
->
set_null
();
}
void
set_scalar
(
const
std
::
string
&
scalar
)
{
m_pData
->
set_scalar
(
scalar
);
}
void
set_scalar
(
const
std
::
string
&
scalar
)
{
m_pData
->
set_scalar
(
scalar
);
}
template
<
typename
T
>
bool
equals
(
const
T
&
rhs
)
const
;
// indexing
// indexing
template
<
typename
Key
>
shared_node
operator
[]
(
const
Key
&
key
)
const
{
return
(
static_cast
<
const
node_data
&>
(
*
m_pData
)
)[
key
]
;
}
template
<
typename
Key
>
shared_node
get
(
const
Key
&
key
,
shared_memory_holder
pMemory
)
const
{
return
static_cast
<
const
node_data
&>
(
*
m_pData
)
.
get
(
key
,
pMemory
)
;
}
template
<
typename
Key
>
shared_node
operator
[]
(
const
Key
&
key
)
{
return
(
*
m_pData
)[
key
]
;
}
template
<
typename
Key
>
shared_node
get
(
const
Key
&
key
,
shared_memory_holder
pMemory
)
{
return
m_pData
->
get
(
key
,
pMemory
)
;
}
template
<
typename
Key
>
bool
remove
(
const
Key
&
key
)
{
return
m_pData
->
remove
(
key
);
}
template
<
typename
Key
>
bool
remove
(
const
Key
&
key
,
shared_memory_holder
pMemory
)
{
return
m_pData
->
remove
(
key
,
pMemory
);
}
shared_node
operator
[]
(
shared_node
pKey
)
const
{
return
(
static_cast
<
const
node_data
&>
(
*
m_pData
)
)[
pKey
]
;
}
shared_node
get
(
shared_node
pKey
)
const
{
return
static_cast
<
const
node_data
&>
(
*
m_pData
)
.
get
(
pKey
)
;
}
shared_node
operator
[]
(
shared_node
pKey
)
{
return
(
*
m_pData
)[
pKey
]
;
}
shared_node
get
(
shared_node
pKey
)
{
return
m_pData
->
get
(
pKey
)
;
}
bool
remove
(
shared_node
pKey
)
{
return
m_pData
->
remove
(
pKey
);
}
bool
remove
(
shared_node
pKey
)
{
return
m_pData
->
remove
(
pKey
);
}
private:
private:
shared_node_data
m_pData
;
shared_node_data
m_pData
;
};
};
template
<
typename
T
>
inline
bool
node
::
equals
(
const
T
&
rhs
)
const
{
}
}
}
}
}
...
...
include/yaml-cpp/value/detail/node_data.h
View file @
020cd979
...
@@ -30,12 +30,12 @@ namespace YAML
...
@@ -30,12 +30,12 @@ namespace YAML
const
std
::
string
scalar
()
const
{
return
m_scalar
;
}
const
std
::
string
scalar
()
const
{
return
m_scalar
;
}
// indexing
// indexing
template
<
typename
Key
>
shared_node
operator
[]
(
const
Key
&
key
)
const
;
template
<
typename
Key
>
shared_node
get
(
const
Key
&
key
,
shared_memory_holder
pMemory
)
const
;
template
<
typename
Key
>
shared_node
operator
[]
(
const
Key
&
key
);
template
<
typename
Key
>
shared_node
get
(
const
Key
&
key
,
shared_memory_holder
pMemory
);
template
<
typename
Key
>
bool
remove
(
const
Key
&
key
);
template
<
typename
Key
>
bool
remove
(
const
Key
&
key
,
shared_memory_holder
pMemory
);
shared_node
operator
[]
(
shared_node
pKey
)
const
;
shared_node
get
(
shared_node
pKey
)
const
;
shared_node
operator
[]
(
shared_node
pKey
);
shared_node
get
(
shared_node
pKey
);
bool
remove
(
shared_node
pKey
);
bool
remove
(
shared_node
pKey
);
private:
private:
...
...
include/yaml-cpp/value/impl.h
View file @
020cd979
...
@@ -136,38 +136,38 @@ namespace YAML
...
@@ -136,38 +136,38 @@ namespace YAML
template
<
typename
Key
>
template
<
typename
Key
>
inline
const
Value
Value
::
operator
[](
const
Key
&
key
)
const
inline
const
Value
Value
::
operator
[](
const
Key
&
key
)
const
{
{
detail
::
shared_node
pValue
=
(
static_cast
<
const
detail
::
node
&>
(
*
m_pNode
)
)[
key
]
;
detail
::
shared_node
pValue
=
static_cast
<
const
detail
::
node
&>
(
*
m_pNode
)
.
get
(
key
,
m_pMemory
)
;
return
Value
(
pValue
,
m_pMemory
);
return
Value
(
pValue
,
m_pMemory
);
}
}
template
<
typename
Key
>
template
<
typename
Key
>
inline
Value
Value
::
operator
[](
const
Key
&
key
)
inline
Value
Value
::
operator
[](
const
Key
&
key
)
{
{
detail
::
shared_node
pValue
=
(
*
m_pNode
)[
key
]
;
detail
::
shared_node
pValue
=
m_pNode
->
get
(
key
,
m_pMemory
)
;
return
Value
(
pValue
,
m_pMemory
);
return
Value
(
pValue
,
m_pMemory
);
}
}
template
<
typename
Key
>
template
<
typename
Key
>
inline
bool
Value
::
remove
(
const
Key
&
key
)
inline
bool
Value
::
remove
(
const
Key
&
key
)
{
{
return
m_pNode
->
remove
(
key
);
return
m_pNode
->
remove
(
key
,
m_pMemory
);
}
}
inline
const
Value
Value
::
operator
[](
const
Value
&
key
)
const
inline
const
Value
Value
::
operator
[](
const
Value
&
key
)
const
{
{
detail
::
shared_node
pValue
=
(
static_cast
<
const
detail
::
node
&>
(
*
m_pNode
)
)[
*
key
.
m_pNode
]
;
detail
::
shared_node
pValue
=
static_cast
<
const
detail
::
node
&>
(
*
m_pNode
)
.
get
(
key
.
m_pNode
)
;
return
Value
(
pValue
,
m_pMemory
);
return
Value
(
pValue
,
m_pMemory
);
}
}
inline
Value
Value
::
operator
[](
const
Value
&
key
)
inline
Value
Value
::
operator
[](
const
Value
&
key
)
{
{
detail
::
shared_node
pValue
=
(
*
m_pNode
)[
*
key
.
m_pNode
]
;
detail
::
shared_node
pValue
=
m_pNode
->
get
(
key
.
m_pNode
)
;
return
Value
(
pValue
,
m_pMemory
);
return
Value
(
pValue
,
m_pMemory
);
}
}
inline
bool
Value
::
remove
(
const
Value
&
key
)
inline
bool
Value
::
remove
(
const
Value
&
key
)
{
{
return
m_pNode
->
remove
(
*
key
.
m_pNode
);
return
m_pNode
->
remove
(
key
.
m_pNode
);
}
}
inline
const
Value
Value
::
operator
[](
const
char
*
key
)
const
inline
const
Value
Value
::
operator
[](
const
char
*
key
)
const
...
@@ -182,7 +182,7 @@ namespace YAML
...
@@ -182,7 +182,7 @@ namespace YAML
inline
bool
Value
::
remove
(
const
char
*
key
)
inline
bool
Value
::
remove
(
const
char
*
key
)
{
{
return
m_pNode
->
remove
(
std
::
string
(
key
));
return
remove
(
std
::
string
(
key
));
}
}
inline
const
Value
Value
::
operator
[](
char
*
key
)
const
inline
const
Value
Value
::
operator
[](
char
*
key
)
const
...
@@ -215,6 +215,15 @@ namespace YAML
...
@@ -215,6 +215,15 @@ namespace YAML
{
{
return
false
;
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
#endif // VALUE_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
include/yaml-cpp/value/value.h
View file @
020cd979
...
@@ -61,6 +61,9 @@ namespace YAML
...
@@ -61,6 +61,9 @@ namespace YAML
private:
private:
explicit
Value
(
detail
::
shared_node
pNode
,
detail
::
shared_memory_holder
pMemory
);
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
);
template
<
typename
T
>
void
Assign
(
const
T
&
rhs
);
void
Assign
(
const
char
*
rhs
);
void
Assign
(
const
char
*
rhs
);
void
Assign
(
char
*
rhs
);
void
Assign
(
char
*
rhs
);
...
...
src/value/detail/node_data.cpp
View file @
020cd979
...
@@ -57,7 +57,7 @@ namespace YAML
...
@@ -57,7 +57,7 @@ namespace YAML
}
}
// indexing
// indexing
shared_node
node_data
::
operator
[]
(
shared_node
pKey
)
const
shared_node
node_data
::
get
(
shared_node
pKey
)
const
{
{
if
(
m_type
!=
ValueType
::
Map
)
if
(
m_type
!=
ValueType
::
Map
)
return
shared_node
(
new
node
);
return
shared_node
(
new
node
);
...
@@ -70,7 +70,7 @@ namespace YAML
...
@@ -70,7 +70,7 @@ namespace YAML
return
shared_node
(
new
node
);
return
shared_node
(
new
node
);
}
}
shared_node
node_data
::
operator
[]
(
shared_node
pKey
)
shared_node
node_data
::
get
(
shared_node
pKey
)
{
{
switch
(
m_type
)
{
switch
(
m_type
)
{
case
ValueType
::
Undefined
:
case
ValueType
::
Undefined
:
...
...
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