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
1ab16bac
Commit
1ab16bac
authored
Sep 07, 2011
by
Jesse Beder
Browse files
Set the 'memory' to only store node_refs, not nodes
parent
4aa61944
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
32 additions
and
31 deletions
+32
-31
include/yaml-cpp/value/detail/impl.h
include/yaml-cpp/value/detail/impl.h
+4
-4
include/yaml-cpp/value/detail/memory.h
include/yaml-cpp/value/detail/memory.h
+1
-1
include/yaml-cpp/value/detail/node.h
include/yaml-cpp/value/detail/node.h
+4
-4
include/yaml-cpp/value/detail/node_data.h
include/yaml-cpp/value/detail/node_data.h
+4
-4
include/yaml-cpp/value/detail/node_ref.h
include/yaml-cpp/value/detail/node_ref.h
+3
-3
include/yaml-cpp/value/impl.h
include/yaml-cpp/value/impl.h
+3
-3
src/value/detail/memory.cpp
src/value/detail/memory.cpp
+3
-3
src/value/detail/node_data.cpp
src/value/detail/node_data.cpp
+10
-9
No files found.
include/yaml-cpp/value/detail/impl.h
View file @
1ab16bac
...
@@ -18,14 +18,14 @@ namespace YAML
...
@@ -18,14 +18,14 @@ namespace YAML
inline
shared_node
node_data
::
get
(
const
Key
&
key
,
shared_memory_holder
pMemory
)
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
pMemory
->
create_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
(
equals
(
it
->
first
,
key
,
pMemory
))
if
(
equals
(
it
->
first
,
key
,
pMemory
))
return
it
->
second
;
return
it
->
second
;
}
}
return
shared_node
(
new
node
);
return
pMemory
->
create_node
(
);
}
}
template
<
typename
Key
>
template
<
typename
Key
>
...
@@ -41,7 +41,7 @@ namespace YAML
...
@@ -41,7 +41,7 @@ namespace YAML
m_map
.
clear
();
m_map
.
clear
();
break
;
break
;
case
ValueType
::
Sequence
:
case
ValueType
::
Sequence
:
convert_sequence_to_map
();
convert_sequence_to_map
(
pMemory
);
break
;
break
;
case
ValueType
::
Map
:
case
ValueType
::
Map
:
break
;
break
;
...
@@ -53,7 +53,7 @@ namespace YAML
...
@@ -53,7 +53,7 @@ namespace YAML
}
}
shared_node
pKey
=
convert_to_node
(
key
,
pMemory
);
shared_node
pKey
=
convert_to_node
(
key
,
pMemory
);
shared_node
pValue
(
new
node
);
shared_node
pValue
=
pMemory
->
create_
node
(
);
m_map
.
push_back
(
kv_pair
(
pKey
,
pValue
));
m_map
.
push_back
(
kv_pair
(
pKey
,
pValue
));
return
pValue
;
return
pValue
;
}
}
...
...
include/yaml-cpp/value/detail/memory.h
View file @
1ab16bac
...
@@ -19,7 +19,7 @@ namespace YAML
...
@@ -19,7 +19,7 @@ namespace YAML
void
merge
(
const
memory
&
rhs
);
void
merge
(
const
memory
&
rhs
);
private:
private:
typedef
std
::
set
<
shared_node
>
Nodes
;
typedef
std
::
set
<
shared_node
_ref
>
Nodes
;
Nodes
m_nodes
;
Nodes
m_nodes
;
};
};
...
...
include/yaml-cpp/value/detail/node.h
View file @
1ab16bac
...
@@ -18,7 +18,7 @@ namespace YAML
...
@@ -18,7 +18,7 @@ namespace YAML
class
node
class
node
{
{
public:
public:
node
()
:
m_pRef
(
new
node_r
ef
)
{}
explicit
node
(
shared_node_ref
pRef
)
:
m_pRef
(
pR
ef
)
{}
ValueType
::
value
type
()
const
{
return
m_pRef
->
type
();
}
ValueType
::
value
type
()
const
{
return
m_pRef
->
type
();
}
...
@@ -36,9 +36,9 @@ namespace YAML
...
@@ -36,9 +36,9 @@ namespace YAML
template
<
typename
Key
>
shared_node
get
(
const
Key
&
key
,
shared_memory_holder
pMemory
)
{
return
m_pRef
->
get
(
key
,
pMemory
);
}
template
<
typename
Key
>
shared_node
get
(
const
Key
&
key
,
shared_memory_holder
pMemory
)
{
return
m_pRef
->
get
(
key
,
pMemory
);
}
template
<
typename
Key
>
bool
remove
(
const
Key
&
key
,
shared_memory_holder
pMemory
)
{
return
m_pRef
->
remove
(
key
,
pMemory
);
}
template
<
typename
Key
>
bool
remove
(
const
Key
&
key
,
shared_memory_holder
pMemory
)
{
return
m_pRef
->
remove
(
key
,
pMemory
);
}
shared_node
get
(
shared_node
pKey
)
const
{
return
static_cast
<
const
node_ref
&>
(
*
m_pRef
).
get
(
pKey
);
}
shared_node
get
(
shared_node
pKey
,
shared_memory_holder
pMemory
)
const
{
return
static_cast
<
const
node_ref
&>
(
*
m_pRef
).
get
(
pKey
,
pMemory
);
}
shared_node
get
(
shared_node
pKey
)
{
return
m_pRef
->
get
(
pKey
);
}
shared_node
get
(
shared_node
pKey
,
shared_memory_holder
pMemory
)
{
return
m_pRef
->
get
(
pKey
,
pMemory
);
}
bool
remove
(
shared_node
pKey
)
{
return
m_pRef
->
remove
(
pKey
);
}
bool
remove
(
shared_node
pKey
,
shared_memory_holder
pMemory
)
{
return
m_pRef
->
remove
(
pKey
,
pMemory
);
}
private:
private:
shared_node_ref
m_pRef
;
shared_node_ref
m_pRef
;
...
...
include/yaml-cpp/value/detail/node_data.h
View file @
1ab16bac
...
@@ -34,12 +34,12 @@ namespace YAML
...
@@ -34,12 +34,12 @@ namespace YAML
template
<
typename
Key
>
shared_node
get
(
const
Key
&
key
,
shared_memory_holder
pMemory
);
template
<
typename
Key
>
shared_node
get
(
const
Key
&
key
,
shared_memory_holder
pMemory
);
template
<
typename
Key
>
bool
remove
(
const
Key
&
key
,
shared_memory_holder
pMemory
);
template
<
typename
Key
>
bool
remove
(
const
Key
&
key
,
shared_memory_holder
pMemory
);
shared_node
get
(
shared_node
pKey
)
const
;
shared_node
get
(
shared_node
pKey
,
shared_memory_holder
pMemory
)
const
;
shared_node
get
(
shared_node
pKey
);
shared_node
get
(
shared_node
pKey
,
shared_memory_holder
pMemory
);
bool
remove
(
shared_node
pKey
);
bool
remove
(
shared_node
pKey
,
shared_memory_holder
pMemory
);
private:
private:
void
convert_sequence_to_map
();
void
convert_sequence_to_map
(
shared_memory_holder
pMemory
);
template
<
typename
T
>
template
<
typename
T
>
static
bool
equals
(
detail
::
shared_node
pNode
,
const
T
&
rhs
,
detail
::
shared_memory_holder
pMemory
);
static
bool
equals
(
detail
::
shared_node
pNode
,
const
T
&
rhs
,
detail
::
shared_memory_holder
pMemory
);
...
...
include/yaml-cpp/value/detail/node_ref.h
View file @
1ab16bac
...
@@ -33,9 +33,9 @@ namespace YAML
...
@@ -33,9 +33,9 @@ namespace YAML
template
<
typename
Key
>
shared_node
get
(
const
Key
&
key
,
shared_memory_holder
pMemory
)
{
return
m_pData
->
get
(
key
,
pMemory
);
}
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
,
shared_memory_holder
pMemory
)
{
return
m_pData
->
remove
(
key
,
pMemory
);
}
template
<
typename
Key
>
bool
remove
(
const
Key
&
key
,
shared_memory_holder
pMemory
)
{
return
m_pData
->
remove
(
key
,
pMemory
);
}
shared_node
get
(
shared_node
pKey
)
const
{
return
static_cast
<
const
node_data
&>
(
*
m_pData
).
get
(
pKey
);
}
shared_node
get
(
shared_node
pKey
,
shared_memory_holder
pMemory
)
const
{
return
static_cast
<
const
node_data
&>
(
*
m_pData
).
get
(
pKey
,
pMemory
);
}
shared_node
get
(
shared_node
pKey
)
{
return
m_pData
->
get
(
pKey
);
}
shared_node
get
(
shared_node
pKey
,
shared_memory_holder
pMemory
)
{
return
m_pData
->
get
(
pKey
,
pMemory
);
}
bool
remove
(
shared_node
pKey
)
{
return
m_pData
->
remove
(
pKey
);
}
bool
remove
(
shared_node
pKey
,
shared_memory_holder
pMemory
)
{
return
m_pData
->
remove
(
pKey
,
pMemory
);
}
private:
private:
shared_node_data
m_pData
;
shared_node_data
m_pData
;
...
...
include/yaml-cpp/value/impl.h
View file @
1ab16bac
...
@@ -160,19 +160,19 @@ namespace YAML
...
@@ -160,19 +160,19 @@ namespace YAML
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
).
get
(
key
.
m_pNode
);
detail
::
shared_node
pValue
=
static_cast
<
const
detail
::
node
&>
(
*
m_pNode
).
get
(
key
.
m_pNode
,
m_pMemory
);
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
->
get
(
key
.
m_pNode
);
detail
::
shared_node
pValue
=
m_pNode
->
get
(
key
.
m_pNode
,
m_pMemory
);
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
,
m_pMemory
);
}
}
inline
const
Value
Value
::
operator
[](
const
char
*
key
)
const
inline
const
Value
Value
::
operator
[](
const
char
*
key
)
const
...
...
src/value/detail/memory.cpp
View file @
1ab16bac
...
@@ -16,9 +16,9 @@ namespace YAML
...
@@ -16,9 +16,9 @@ namespace YAML
shared_node
memory
::
create_node
()
shared_node
memory
::
create_node
()
{
{
shared_node
pNode
(
new
node
);
shared_node
_ref
pRef
(
new
node
_ref
);
m_nodes
.
insert
(
p
Node
);
m_nodes
.
insert
(
p
Ref
);
return
pNode
;
return
shared_node
(
new
node
(
pRef
))
;
}
}
void
memory
::
merge
(
const
memory
&
rhs
)
void
memory
::
merge
(
const
memory
&
rhs
)
...
...
src/value/detail/node_data.cpp
View file @
1ab16bac
#include "yaml-cpp/value/detail/node_data.h"
#include "yaml-cpp/value/detail/node_data.h"
#include "yaml-cpp/value/detail/memory.h"
#include "yaml-cpp/value/detail/node.h"
#include "yaml-cpp/value/detail/node.h"
#include <sstream>
#include <sstream>
...
@@ -57,20 +58,20 @@ namespace YAML
...
@@ -57,20 +58,20 @@ namespace YAML
}
}
// indexing
// indexing
shared_node
node_data
::
get
(
shared_node
pKey
)
const
shared_node
node_data
::
get
(
shared_node
pKey
,
shared_memory_holder
pMemory
)
const
{
{
if
(
m_type
!=
ValueType
::
Map
)
if
(
m_type
!=
ValueType
::
Map
)
return
shared_node
(
new
node
);
return
pMemory
->
create_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
==
pKey
)
if
(
it
->
first
==
pKey
)
return
it
->
second
;
return
it
->
second
;
}
}
return
shared_node
(
new
node
);
return
pMemory
->
create_node
(
);
}
}
shared_node
node_data
::
get
(
shared_node
pKey
)
shared_node
node_data
::
get
(
shared_node
pKey
,
shared_memory_holder
pMemory
)
{
{
switch
(
m_type
)
{
switch
(
m_type
)
{
case
ValueType
::
Undefined
:
case
ValueType
::
Undefined
:
...
@@ -80,7 +81,7 @@ namespace YAML
...
@@ -80,7 +81,7 @@ namespace YAML
m_map
.
clear
();
m_map
.
clear
();
break
;
break
;
case
ValueType
::
Sequence
:
case
ValueType
::
Sequence
:
convert_sequence_to_map
();
convert_sequence_to_map
(
pMemory
);
break
;
break
;
case
ValueType
::
Map
:
case
ValueType
::
Map
:
break
;
break
;
...
@@ -91,12 +92,12 @@ namespace YAML
...
@@ -91,12 +92,12 @@ namespace YAML
return
it
->
second
;
return
it
->
second
;
}
}
shared_node
pValue
(
new
node
);
shared_node
pValue
=
pMemory
->
create_
node
(
);
m_map
.
push_back
(
kv_pair
(
pKey
,
pValue
));
m_map
.
push_back
(
kv_pair
(
pKey
,
pValue
));
return
pValue
;
return
pValue
;
}
}
bool
node_data
::
remove
(
shared_node
pKey
)
bool
node_data
::
remove
(
shared_node
pKey
,
shared_memory_holder
/* pMemory */
)
{
{
if
(
m_type
!=
ValueType
::
Map
)
if
(
m_type
!=
ValueType
::
Map
)
return
false
;
return
false
;
...
@@ -111,7 +112,7 @@ namespace YAML
...
@@ -111,7 +112,7 @@ namespace YAML
return
false
;
return
false
;
}
}
void
node_data
::
convert_sequence_to_map
()
void
node_data
::
convert_sequence_to_map
(
shared_memory_holder
pMemory
)
{
{
assert
(
m_type
==
ValueType
::
Sequence
);
assert
(
m_type
==
ValueType
::
Sequence
);
...
@@ -120,7 +121,7 @@ namespace YAML
...
@@ -120,7 +121,7 @@ namespace YAML
std
::
stringstream
stream
;
std
::
stringstream
stream
;
stream
<<
i
;
stream
<<
i
;
shared_node
pKey
(
new
node
);
shared_node
pKey
=
pMemory
->
create_
node
(
);
pKey
->
set_scalar
(
stream
.
str
());
pKey
->
set_scalar
(
stream
.
str
());
m_map
.
push_back
(
kv_pair
(
pKey
,
m_sequence
[
i
]));
m_map
.
push_back
(
kv_pair
(
pKey
,
m_sequence
[
i
]));
}
}
...
...
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