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
abe0af76
Commit
abe0af76
authored
Aug 24, 2009
by
Jesse Beder
Browse files
Added Node::Clone function
parent
8e636436
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
78 additions
and
2 deletions
+78
-2
include/node.h
include/node.h
+5
-0
src/aliascontent.cpp
src/aliascontent.cpp
+5
-0
src/aliascontent.h
src/aliascontent.h
+2
-0
src/content.h
src/content.h
+2
-0
src/map.cpp
src/map.cpp
+14
-0
src/map.h
src/map.h
+7
-2
src/node.cpp
src/node.cpp
+15
-0
src/scalar.cpp
src/scalar.cpp
+10
-0
src/scalar.h
src/scalar.h
+4
-0
src/sequence.cpp
src/sequence.cpp
+11
-0
src/sequence.h
src/sequence.h
+3
-0
No files found.
include/node.h
View file @
abe0af76
...
...
@@ -14,6 +14,7 @@
#include <string>
#include <vector>
#include <map>
#include <memory>
namespace
YAML
{
...
...
@@ -30,6 +31,7 @@ namespace YAML
~
Node
();
void
Clear
();
std
::
auto_ptr
<
Node
>
Clone
()
const
;
void
Parse
(
Scanner
*
pScanner
,
const
ParserState
&
state
);
CONTENT_TYPE
GetType
()
const
;
...
...
@@ -89,6 +91,9 @@ namespace YAML
template
<
typename
T
>
const
Node
*
FindValueForKey
(
const
T
&
key
)
const
;
// helper for cloning
Node
(
const
Mark
&
mark
,
const
std
::
string
&
anchor
,
const
std
::
string
&
tag
,
const
Content
*
pContent
);
// helpers for parsing
void
ParseHeader
(
Scanner
*
pScanner
,
const
ParserState
&
state
);
...
...
src/aliascontent.cpp
View file @
abe0af76
...
...
@@ -8,6 +8,11 @@ namespace YAML
{
}
Content
*
AliasContent
::
Clone
()
const
{
return
0
;
// TODO: how to clone an alias?
}
void
AliasContent
::
Parse
(
Scanner
*
/*pScanner*/
,
const
ParserState
&
/*state*/
)
{
}
...
...
src/aliascontent.h
View file @
abe0af76
...
...
@@ -12,6 +12,8 @@ namespace YAML
{
public:
AliasContent
(
Content
*
pNodeContent
);
virtual
Content
*
Clone
()
const
;
virtual
void
Parse
(
Scanner
*
pScanner
,
const
ParserState
&
state
);
virtual
void
Write
(
Emitter
&
)
const
;
...
...
src/content.h
View file @
abe0af76
...
...
@@ -25,6 +25,8 @@ namespace YAML
public:
Content
();
virtual
~
Content
();
virtual
Content
*
Clone
()
const
=
0
;
virtual
void
Parse
(
Scanner
*
pScanner
,
const
ParserState
&
state
)
=
0
;
virtual
void
Write
(
Emitter
&
out
)
const
=
0
;
...
...
src/map.cpp
View file @
abe0af76
...
...
@@ -12,6 +12,15 @@ namespace YAML
Map
::
Map
()
{
}
Map
::
Map
(
const
node_map
&
data
)
{
for
(
node_map
::
const_iterator
it
=
data
.
begin
();
it
!=
data
.
end
();
++
it
)
{
std
::
auto_ptr
<
Node
>
pKey
=
it
->
first
->
Clone
();
std
::
auto_ptr
<
Node
>
pValue
=
it
->
second
->
Clone
();
m_data
[
pKey
.
release
()]
=
pValue
.
release
();
}
}
Map
::~
Map
()
{
...
...
@@ -27,6 +36,11 @@ namespace YAML
m_data
.
clear
();
}
Content
*
Map
::
Clone
()
const
{
return
new
Map
(
m_data
);
}
bool
Map
::
GetBegin
(
std
::
map
<
Node
*
,
Node
*
,
ltnode
>::
const_iterator
&
it
)
const
{
it
=
m_data
.
begin
();
...
...
src/map.h
View file @
abe0af76
...
...
@@ -13,11 +13,17 @@ namespace YAML
class
Map
:
public
Content
{
private:
typedef
std
::
map
<
Node
*
,
Node
*
,
ltnode
>
node_map
;
public:
Map
();
Map
(
const
node_map
&
data
);
virtual
~
Map
();
void
Clear
();
virtual
Content
*
Clone
()
const
;
virtual
bool
GetBegin
(
std
::
map
<
Node
*
,
Node
*
,
ltnode
>::
const_iterator
&
it
)
const
;
virtual
bool
GetEnd
(
std
::
map
<
Node
*
,
Node
*
,
ltnode
>::
const_iterator
&
it
)
const
;
virtual
void
Parse
(
Scanner
*
pScanner
,
const
ParserState
&
state
);
...
...
@@ -35,8 +41,7 @@ namespace YAML
void
ParseBlock
(
Scanner
*
pScanner
,
const
ParserState
&
state
);
void
ParseFlow
(
Scanner
*
pScanner
,
const
ParserState
&
state
);
protected:
typedef
std
::
map
<
Node
*
,
Node
*
,
ltnode
>
node_map
;
private:
node_map
m_data
;
};
}
...
...
src/node.cpp
View file @
abe0af76
...
...
@@ -24,6 +24,13 @@ namespace YAML
{
}
Node
::
Node
(
const
Mark
&
mark
,
const
std
::
string
&
anchor
,
const
std
::
string
&
tag
,
const
Content
*
pContent
)
:
m_mark
(
mark
),
m_anchor
(
anchor
),
m_tag
(
tag
),
m_pContent
(
0
),
m_alias
(
false
),
m_pIdentity
(
this
),
m_referenced
(
false
)
{
if
(
m_pContent
)
m_pContent
=
pContent
->
Clone
();
}
Node
::~
Node
()
{
Clear
();
...
...
@@ -38,6 +45,14 @@ namespace YAML
m_anchor
.
clear
();
m_tag
.
clear
();
}
std
::
auto_ptr
<
Node
>
Node
::
Clone
()
const
{
if
(
m_alias
)
throw
std
::
runtime_error
(
"yaml-cpp: Can't clone alias"
);
// TODO: what to do about aliases?
return
std
::
auto_ptr
<
Node
>
(
new
Node
(
m_mark
,
m_anchor
,
m_tag
,
m_pContent
));
}
void
Node
::
Parse
(
Scanner
*
pScanner
,
const
ParserState
&
state
)
{
...
...
src/scalar.cpp
View file @
abe0af76
...
...
@@ -12,10 +12,19 @@ namespace YAML
{
}
Scalar
::
Scalar
(
const
std
::
string
&
data
)
:
m_data
(
data
)
{
}
Scalar
::~
Scalar
()
{
}
Content
*
Scalar
::
Clone
()
const
{
return
new
Scalar
(
m_data
);
}
void
Scalar
::
Parse
(
Scanner
*
pScanner
,
const
ParserState
&
/*state*/
)
{
Token
&
token
=
pScanner
->
peek
();
...
...
@@ -43,3 +52,4 @@ namespace YAML
return
0
;
}
}
src/scalar.h
View file @
abe0af76
...
...
@@ -13,8 +13,11 @@ namespace YAML
{
public:
Scalar
();
Scalar
(
const
std
::
string
&
data
);
virtual
~
Scalar
();
virtual
Content
*
Clone
()
const
;
virtual
void
Parse
(
Scanner
*
pScanner
,
const
ParserState
&
state
);
virtual
void
Write
(
Emitter
&
out
)
const
;
...
...
@@ -38,3 +41,4 @@ namespace YAML
}
#endif // SCALAR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
src/sequence.cpp
View file @
abe0af76
...
...
@@ -13,6 +13,12 @@ namespace YAML
}
Sequence
::
Sequence
(
const
std
::
vector
<
Node
*>&
data
)
{
for
(
std
::
size_t
i
=
0
;
i
<
data
.
size
();
i
++
)
m_data
.
push_back
(
data
[
i
]
->
Clone
().
release
());
}
Sequence
::~
Sequence
()
{
Clear
();
...
...
@@ -25,6 +31,11 @@ namespace YAML
m_data
.
clear
();
}
Content
*
Sequence
::
Clone
()
const
{
return
new
Sequence
(
m_data
);
}
bool
Sequence
::
GetBegin
(
std
::
vector
<
Node
*>::
const_iterator
&
it
)
const
{
it
=
m_data
.
begin
();
...
...
src/sequence.h
View file @
abe0af76
...
...
@@ -15,9 +15,12 @@ namespace YAML
{
public:
Sequence
();
Sequence
(
const
std
::
vector
<
Node
*>&
data
);
virtual
~
Sequence
();
void
Clear
();
virtual
Content
*
Clone
()
const
;
virtual
bool
GetBegin
(
std
::
vector
<
Node
*>::
const_iterator
&
it
)
const
;
virtual
bool
GetEnd
(
std
::
vector
<
Node
*>::
const_iterator
&
it
)
const
;
virtual
Node
*
GetNode
(
std
::
size_t
i
)
const
;
...
...
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