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
09beb5c4
Commit
09beb5c4
authored
Sep 09, 2011
by
Jesse Beder
Browse files
Implemented sugar Parse() functions
parent
6e03bebe
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
67 additions
and
20 deletions
+67
-20
include/yaml-cpp/value.h
include/yaml-cpp/value.h
+1
-0
include/yaml-cpp/value/impl.h
include/yaml-cpp/value/impl.h
+2
-2
include/yaml-cpp/value/parse.h
include/yaml-cpp/value/parse.h
+21
-0
include/yaml-cpp/value/value.h
include/yaml-cpp/value/value.h
+1
-0
src/value/parse.cpp
src/value/parse.cpp
+29
-0
src/value/valuebuilder.cpp
src/value/valuebuilder.cpp
+10
-2
src/value/valuebuilder.h
src/value/valuebuilder.h
+2
-0
util/value.cpp
util/value.cpp
+1
-16
No files found.
include/yaml-cpp/value.h
View file @
09beb5c4
...
@@ -11,5 +11,6 @@
...
@@ -11,5 +11,6 @@
#include "yaml-cpp/value/convert.h"
#include "yaml-cpp/value/convert.h"
#include "yaml-cpp/value/iterator.h"
#include "yaml-cpp/value/iterator.h"
#include "yaml-cpp/value/detail/impl.h"
#include "yaml-cpp/value/detail/impl.h"
#include "yaml-cpp/value/parse.h"
#endif // VALUE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#endif // VALUE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
include/yaml-cpp/value/impl.h
View file @
09beb5c4
...
@@ -112,13 +112,13 @@ namespace YAML
...
@@ -112,13 +112,13 @@ namespace YAML
return
*
this
;
return
*
this
;
}
}
void
Value
::
AssignData
(
const
Value
&
rhs
)
inline
void
Value
::
AssignData
(
const
Value
&
rhs
)
{
{
m_pNode
->
set_data
(
*
rhs
.
m_pNode
);
m_pNode
->
set_data
(
*
rhs
.
m_pNode
);
m_pMemory
->
merge
(
*
rhs
.
m_pMemory
);
m_pMemory
->
merge
(
*
rhs
.
m_pMemory
);
}
}
void
Value
::
AssignNode
(
const
Value
&
rhs
)
inline
void
Value
::
AssignNode
(
const
Value
&
rhs
)
{
{
m_pNode
->
set_ref
(
*
rhs
.
m_pNode
);
m_pNode
->
set_ref
(
*
rhs
.
m_pNode
);
m_pMemory
->
merge
(
*
rhs
.
m_pMemory
);
m_pMemory
->
merge
(
*
rhs
.
m_pMemory
);
...
...
include/yaml-cpp/value/parse.h
0 → 100644
View file @
09beb5c4
#ifndef VALUE_PARSE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define VALUE_PARSE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include <string>
#include <iosfwd>
namespace
YAML
{
class
Value
;
Value
Parse
(
const
std
::
string
&
input
);
Value
Parse
(
const
char
*
input
);
Value
Parse
(
std
::
istream
&
input
);
}
#endif // VALUE_PARSE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
include/yaml-cpp/value/value.h
View file @
09beb5c4
...
@@ -17,6 +17,7 @@ namespace YAML
...
@@ -17,6 +17,7 @@ namespace YAML
class
Value
class
Value
{
{
public:
public:
friend
class
ValueBuilder
;
friend
class
detail
::
node_data
;
friend
class
detail
::
node_data
;
template
<
typename
,
typename
,
typename
>
friend
class
detail
::
iterator_base
;
template
<
typename
,
typename
,
typename
>
friend
class
detail
::
iterator_base
;
...
...
src/value/parse.cpp
0 → 100644
View file @
09beb5c4
#include "yaml-cpp/value/parse.h"
#include "yaml-cpp/value/value.h"
#include "yaml-cpp/value/impl.h"
#include "yaml-cpp/parser.h"
#include "valuebuilder.h"
#include <sstream>
namespace
YAML
{
Value
Parse
(
const
std
::
string
&
input
)
{
std
::
stringstream
stream
(
input
);
return
Parse
(
stream
);
}
Value
Parse
(
const
char
*
input
)
{
std
::
stringstream
stream
(
input
);
return
Parse
(
stream
);
}
Value
Parse
(
std
::
istream
&
input
)
{
Parser
parser
(
input
);
ValueBuilder
builder
;
if
(
!
parser
.
HandleNextDocument
(
builder
))
return
Value
();
return
builder
.
Root
();
}
}
src/value/valuebuilder.cpp
View file @
09beb5c4
...
@@ -14,6 +14,14 @@ namespace YAML
...
@@ -14,6 +14,14 @@ namespace YAML
{
{
}
}
Value
ValueBuilder
::
Root
()
{
if
(
!
m_pRoot
)
return
Value
();
return
Value
(
*
m_pRoot
,
m_pMemory
);
}
void
ValueBuilder
::
OnDocumentStart
(
const
Mark
&
)
void
ValueBuilder
::
OnDocumentStart
(
const
Mark
&
)
{
{
}
}
...
@@ -70,13 +78,13 @@ namespace YAML
...
@@ -70,13 +78,13 @@ namespace YAML
detail
::
node
&
ValueBuilder
::
Push
(
anchor_t
anchor
)
detail
::
node
&
ValueBuilder
::
Push
(
anchor_t
anchor
)
{
{
detail
::
node
&
top
=
*
m_stack
.
back
(
);
const
bool
needsKey
=
(
!
m_stack
.
empty
()
&&
m_stack
.
back
()
->
type
()
==
ValueType
::
Map
&&
m_keys
.
size
()
<
m_mapDepth
);
detail
::
node
&
node
=
m_pMemory
->
create_node
();
detail
::
node
&
node
=
m_pMemory
->
create_node
();
m_stack
.
push_back
(
&
node
);
m_stack
.
push_back
(
&
node
);
RegisterAnchor
(
anchor
,
node
);
RegisterAnchor
(
anchor
,
node
);
if
(
top
.
type
()
==
ValueType
::
Map
&&
m_keys
.
size
()
<
m_mapDepth
)
if
(
needsKey
)
m_keys
.
push_back
(
&
node
);
m_keys
.
push_back
(
&
node
);
return
node
;
return
node
;
...
...
src/value/valuebuilder.h
View file @
09beb5c4
...
@@ -19,6 +19,8 @@ namespace YAML
...
@@ -19,6 +19,8 @@ namespace YAML
ValueBuilder
();
ValueBuilder
();
virtual
~
ValueBuilder
();
virtual
~
ValueBuilder
();
Value
Root
();
virtual
void
OnDocumentStart
(
const
Mark
&
mark
);
virtual
void
OnDocumentStart
(
const
Mark
&
mark
);
virtual
void
OnDocumentEnd
();
virtual
void
OnDocumentEnd
();
...
...
util/value.cpp
View file @
09beb5c4
...
@@ -3,22 +3,7 @@
...
@@ -3,22 +3,7 @@
int
main
()
int
main
()
{
{
YAML
::
Value
value
;
YAML
::
Value
value
=
YAML
::
Parse
(
"foo: bar"
);
value
[
"seq"
]
=
YAML
::
Value
(
YAML
::
ValueType
::
Sequence
);
for
(
int
i
=
0
;
i
<
5
;
i
++
)
value
[
"seq"
].
append
(
i
);
value
[
"map"
][
"one"
]
=
"I"
;
value
[
"map"
][
"two"
]
=
"II"
;
value
[
"map"
][
"three"
]
=
"III"
;
value
[
"map"
][
"four"
]
=
"IV"
;
for
(
YAML
::
const_iterator
it
=
value
[
"seq"
].
begin
();
it
!=
value
[
"seq"
].
end
();
++
it
)
{
std
::
cout
<<
it
->
as
<
int
>
()
<<
"
\n
"
;
}
for
(
YAML
::
const_iterator
it
=
value
[
"map"
].
begin
();
it
!=
value
[
"map"
].
end
();
++
it
)
{
std
::
cout
<<
it
->
first
.
as
<
std
::
string
>
()
<<
" -> "
<<
it
->
second
.
as
<
std
::
string
>
()
<<
"
\n
"
;
}
return
0
;
return
0
;
}
}
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