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
923ccc8f
"tests/vscode:/vscode.git/clone" did not exist on "bb1b76d3bf9ef78a827086d1b9449975237ecbac"
Commit
923ccc8f
authored
May 21, 2012
by
Jesse Beder
Browse files
Implemented begin/end doc
parent
5a2183f5
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
93 additions
and
35 deletions
+93
-35
include/yaml-cpp/emitter.h
include/yaml-cpp/emitter.h
+0
-2
src/emitter.cpp
src/emitter.cpp
+56
-17
src/emitterstate.cpp
src/emitterstate.cpp
+20
-5
src/emitterstate.h
src/emitterstate.h
+15
-6
util/sandbox.cpp
util/sandbox.cpp
+2
-5
No files found.
include/yaml-cpp/emitter.h
View file @
923ccc8f
...
@@ -81,8 +81,6 @@ namespace YAML
...
@@ -81,8 +81,6 @@ namespace YAML
void
EmitEndSeq
();
void
EmitEndSeq
();
void
EmitBeginMap
();
void
EmitBeginMap
();
void
EmitEndMap
();
void
EmitEndMap
();
void
EmitKey
();
void
EmitValue
();
void
EmitNewline
();
void
EmitNewline
();
void
EmitKindTag
();
void
EmitKindTag
();
void
EmitTag
(
bool
verbatim
,
const
_Tag
&
tag
);
void
EmitTag
(
bool
verbatim
,
const
_Tag
&
tag
);
...
...
src/emitter.cpp
View file @
923ccc8f
...
@@ -131,10 +131,8 @@ namespace YAML
...
@@ -131,10 +131,8 @@ namespace YAML
EmitEndMap
();
EmitEndMap
();
break
;
break
;
case
Key
:
case
Key
:
EmitKey
();
break
;
case
Value
:
case
Value
:
EmitValue
();
// deprecated (these can be deduced by the parity of nodes in a map)
break
;
break
;
case
TagByKind
:
case
TagByKind
:
EmitKindTag
();
EmitKindTag
();
...
@@ -169,6 +167,20 @@ namespace YAML
...
@@ -169,6 +167,20 @@ namespace YAML
{
{
if
(
!
good
())
if
(
!
good
())
return
;
return
;
if
(
m_pState
->
CurGroupType
()
!=
GroupType
::
None
)
{
m_pState
->
SetError
(
"Unexpected begin document"
);
return
;
}
if
(
m_pState
->
HasAnchor
()
||
m_pState
->
HasTag
())
{
m_pState
->
SetError
(
"Unexpected begin document"
);
return
;
}
if
(
m_stream
.
col
()
>
0
)
m_stream
<<
"
\n
"
;
m_stream
<<
"---
\n
"
;
}
}
// EmitEndDoc
// EmitEndDoc
...
@@ -176,6 +188,20 @@ namespace YAML
...
@@ -176,6 +188,20 @@ namespace YAML
{
{
if
(
!
good
())
if
(
!
good
())
return
;
return
;
if
(
m_pState
->
CurGroupType
()
!=
GroupType
::
None
)
{
m_pState
->
SetError
(
"Unexpected begin document"
);
return
;
}
if
(
m_pState
->
HasAnchor
()
||
m_pState
->
HasTag
())
{
m_pState
->
SetError
(
"Unexpected begin document"
);
return
;
}
if
(
m_stream
.
col
()
>
0
)
m_stream
<<
"
\n
"
;
m_stream
<<
"...
\n
"
;
}
}
// EmitBeginSeq
// EmitBeginSeq
...
@@ -183,6 +209,8 @@ namespace YAML
...
@@ -183,6 +209,8 @@ namespace YAML
{
{
if
(
!
good
())
if
(
!
good
())
return
;
return
;
m_pState
->
BeginGroup
(
GroupType
::
Seq
);
}
}
// EmitEndSeq
// EmitEndSeq
...
@@ -190,6 +218,8 @@ namespace YAML
...
@@ -190,6 +218,8 @@ namespace YAML
{
{
if
(
!
good
())
if
(
!
good
())
return
;
return
;
m_pState
->
EndGroup
(
GroupType
::
Seq
);
}
}
// EmitBeginMap
// EmitBeginMap
...
@@ -197,27 +227,18 @@ namespace YAML
...
@@ -197,27 +227,18 @@ namespace YAML
{
{
if
(
!
good
())
if
(
!
good
())
return
;
return
;
m_pState
->
BeginGroup
(
GroupType
::
Map
);
}
}
// EmitEndMap
// EmitEndMap
void
Emitter
::
EmitEndMap
()
void
Emitter
::
EmitEndMap
()
{
if
(
!
good
())
return
;
}
// EmitKey
void
Emitter
::
EmitKey
()
{
{
if
(
!
good
())
if
(
!
good
())
return
;
return
;
}
m_pState
->
EndGroup
(
GroupType
::
Map
);
// EmitValue
}
void
Emitter
::
EmitValue
()
{
if
(
!
good
())
return
;
}
// EmitNewline
// EmitNewline
void
Emitter
::
EmitNewline
()
void
Emitter
::
EmitNewline
()
...
@@ -238,6 +259,9 @@ namespace YAML
...
@@ -238,6 +259,9 @@ namespace YAML
{
{
if
(
!
good
())
if
(
!
good
())
return
*
this
;
return
*
this
;
m_pState
->
BeginScalar
();
return
*
this
;
return
*
this
;
}
}
...
@@ -291,6 +315,8 @@ namespace YAML
...
@@ -291,6 +315,8 @@ namespace YAML
if
(
!
good
())
if
(
!
good
())
return
*
this
;
return
*
this
;
m_pState
->
BeginScalar
();
return
*
this
;
return
*
this
;
}
}
...
@@ -299,6 +325,8 @@ namespace YAML
...
@@ -299,6 +325,8 @@ namespace YAML
if
(
!
good
())
if
(
!
good
())
return
*
this
;
return
*
this
;
m_pState
->
BeginScalar
();
return
*
this
;
return
*
this
;
}
}
...
@@ -307,6 +335,8 @@ namespace YAML
...
@@ -307,6 +335,8 @@ namespace YAML
if
(
!
good
())
if
(
!
good
())
return
*
this
;
return
*
this
;
m_pState
->
BeginScalar
();
return
*
this
;
return
*
this
;
}
}
...
@@ -315,6 +345,8 @@ namespace YAML
...
@@ -315,6 +345,8 @@ namespace YAML
if
(
!
good
())
if
(
!
good
())
return
*
this
;
return
*
this
;
m_pState
->
BeginScalar
();
return
*
this
;
return
*
this
;
}
}
...
@@ -323,6 +355,7 @@ namespace YAML
...
@@ -323,6 +355,7 @@ namespace YAML
if
(
!
good
())
if
(
!
good
())
return
*
this
;
return
*
this
;
m_pState
->
BeginScalar
();
return
*
this
;
return
*
this
;
}
}
...
@@ -337,6 +370,8 @@ namespace YAML
...
@@ -337,6 +370,8 @@ namespace YAML
if
(
!
good
())
if
(
!
good
())
return
*
this
;
return
*
this
;
m_pState
->
BeginScalar
();
return
*
this
;
return
*
this
;
}
}
...
@@ -345,6 +380,8 @@ namespace YAML
...
@@ -345,6 +380,8 @@ namespace YAML
if
(
!
good
())
if
(
!
good
())
return
*
this
;
return
*
this
;
m_pState
->
BeginScalar
();
return
*
this
;
return
*
this
;
}
}
...
@@ -355,6 +392,8 @@ namespace YAML
...
@@ -355,6 +392,8 @@ namespace YAML
if
(
!
good
())
if
(
!
good
())
return
*
this
;
return
*
this
;
m_pState
->
BeginScalar
();
return
*
this
;
return
*
this
;
}
}
}
}
...
...
src/emitterstate.cpp
View file @
923ccc8f
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
namespace
YAML
namespace
YAML
{
{
EmitterState
::
EmitterState
()
:
m_isGood
(
true
),
m_curIndent
(
0
)
EmitterState
::
EmitterState
()
:
m_isGood
(
true
),
m_curIndent
(
0
)
,
m_hasAnchor
(
false
),
m_hasTag
(
false
)
{
{
// set default global manipulators
// set default global manipulators
m_charset
.
set
(
EmitNonAscii
);
m_charset
.
set
(
EmitNonAscii
);
...
@@ -43,8 +43,24 @@ namespace YAML
...
@@ -43,8 +43,24 @@ namespace YAML
SetMapKeyFormat
(
value
,
FmtScope
::
Local
);
SetMapKeyFormat
(
value
,
FmtScope
::
Local
);
}
}
void
EmitterState
::
BeginNode
()
{
if
(
!
m_groups
.
empty
())
m_groups
.
top
().
childCount
++
;
m_hasAnchor
=
false
;
m_hasTag
=
false
;
}
void
EmitterState
::
BeginScalar
()
{
BeginNode
();
}
void
EmitterState
::
BeginGroup
(
GroupType
::
value
type
)
void
EmitterState
::
BeginGroup
(
GroupType
::
value
type
)
{
{
BeginNode
();
unsigned
lastIndent
=
(
m_groups
.
empty
()
?
0
:
m_groups
.
top
().
indent
);
unsigned
lastIndent
=
(
m_groups
.
empty
()
?
0
:
m_groups
.
top
().
indent
);
m_curIndent
+=
lastIndent
;
m_curIndent
+=
lastIndent
;
...
@@ -82,7 +98,7 @@ namespace YAML
...
@@ -82,7 +98,7 @@ namespace YAML
m_globalModifiedSettings
.
restore
();
m_globalModifiedSettings
.
restore
();
}
}
GroupType
::
value
EmitterState
::
Get
CurGroupType
()
const
GroupType
::
value
EmitterState
::
CurGroupType
()
const
{
{
if
(
m_groups
.
empty
())
if
(
m_groups
.
empty
())
return
GroupType
::
None
;
return
GroupType
::
None
;
...
@@ -90,7 +106,7 @@ namespace YAML
...
@@ -90,7 +106,7 @@ namespace YAML
return
m_groups
.
top
().
type
;
return
m_groups
.
top
().
type
;
}
}
FlowType
::
value
EmitterState
::
Get
CurGroupFlowType
()
const
FlowType
::
value
EmitterState
::
CurGroupFlowType
()
const
{
{
if
(
m_groups
.
empty
())
if
(
m_groups
.
empty
())
return
FlowType
::
None
;
return
FlowType
::
None
;
...
@@ -222,8 +238,7 @@ namespace YAML
...
@@ -222,8 +238,7 @@ namespace YAML
EMITTER_MANIP
EmitterState
::
GetFlowType
(
GroupType
::
value
groupType
)
const
EMITTER_MANIP
EmitterState
::
GetFlowType
(
GroupType
::
value
groupType
)
const
{
{
// force flow style if we're currently in a flow
// force flow style if we're currently in a flow
FlowType
::
value
flowType
=
GetCurGroupFlowType
();
if
(
CurGroupFlowType
()
==
FlowType
::
Flow
)
if
(
flowType
==
FlowType
::
Flow
)
return
Flow
;
return
Flow
;
// otherwise, go with what's asked of us
// otherwise, go with what's asked of us
...
...
src/emitterstate.h
View file @
923ccc8f
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
#include <vector>
#include <vector>
#include <stack>
#include <stack>
#include <memory>
#include <memory>
#include <stdexcept>
namespace
YAML
namespace
YAML
{
{
...
@@ -29,15 +30,18 @@ namespace YAML
...
@@ -29,15 +30,18 @@ namespace YAML
// basic state checking
// basic state checking
bool
good
()
const
{
return
m_isGood
;
}
bool
good
()
const
{
return
m_isGood
;
}
const
std
::
string
GetLastError
()
const
{
return
m_lastError
;
}
const
std
::
string
GetLastError
()
const
{
return
m_lastError
;
}
void
SetError
(
const
std
::
string
&
error
)
{
m_isGood
=
false
;
m_lastError
=
error
;
}
void
SetError
(
const
std
::
string
&
error
)
{
throw
std
::
runtime_error
(
error
);
m_isGood
=
false
;
m_lastError
=
error
;
}
// group handling
// node handling
void
BeginScalar
();
void
BeginGroup
(
GroupType
::
value
type
);
void
BeginGroup
(
GroupType
::
value
type
);
void
EndGroup
(
GroupType
::
value
type
);
void
EndGroup
(
GroupType
::
value
type
);
GroupType
::
value
GetCurGroupType
()
const
;
GroupType
::
value
CurGroupType
()
const
;
FlowType
::
value
GetCurGroupFlowType
()
const
;
FlowType
::
value
CurGroupFlowType
()
const
;
int
GetCurIndent
()
const
{
return
m_curIndent
;
}
int
CurIndent
()
const
{
return
m_curIndent
;
}
bool
HasAnchor
()
const
{
return
m_hasAnchor
;
}
bool
HasTag
()
const
{
return
m_hasTag
;
}
void
ClearModifiedSettings
();
void
ClearModifiedSettings
();
...
@@ -84,6 +88,8 @@ namespace YAML
...
@@ -84,6 +88,8 @@ namespace YAML
private:
private:
template
<
typename
T
>
template
<
typename
T
>
void
_Set
(
Setting
<
T
>&
fmt
,
T
value
,
FmtScope
::
value
scope
);
void
_Set
(
Setting
<
T
>&
fmt
,
T
value
,
FmtScope
::
value
scope
);
void
BeginNode
();
private:
private:
// basic state ok?
// basic state ok?
...
@@ -109,17 +115,20 @@ namespace YAML
...
@@ -109,17 +115,20 @@ namespace YAML
SettingChanges
m_globalModifiedSettings
;
SettingChanges
m_globalModifiedSettings
;
struct
Group
{
struct
Group
{
Group
(
GroupType
::
value
type_
)
:
type
(
type_
),
indent
(
0
)
{}
explicit
Group
(
GroupType
::
value
type_
)
:
type
(
type_
),
indent
(
0
)
,
childCount
(
0
)
{}
GroupType
::
value
type
;
GroupType
::
value
type
;
EMITTER_MANIP
flow
;
EMITTER_MANIP
flow
;
int
indent
;
int
indent
;
std
::
size_t
childCount
;
SettingChanges
modifiedSettings
;
SettingChanges
modifiedSettings
;
};
};
ptr_stack
<
Group
>
m_groups
;
ptr_stack
<
Group
>
m_groups
;
unsigned
m_curIndent
;
unsigned
m_curIndent
;
bool
m_hasAnchor
;
bool
m_hasTag
;
};
};
template
<
typename
T
>
template
<
typename
T
>
...
...
util/sandbox.cpp
View file @
923ccc8f
...
@@ -4,14 +4,11 @@
...
@@ -4,14 +4,11 @@
int
main
()
int
main
()
{
{
YAML
::
Emitter
out
;
YAML
::
Emitter
out
;
out
<<
YAML
::
BeginDoc
;
out
<<
YAML
::
BeginSeq
;
out
<<
YAML
::
BeginSeq
;
out
<<
"foo"
;
out
<<
"foo"
;
out
<<
YAML
::
Comment
(
"Skills"
);
out
<<
YAML
::
BeginMap
;
out
<<
YAML
::
Key
<<
"attack"
<<
YAML
::
Value
<<
23
;
out
<<
YAML
::
Key
<<
"intelligence"
<<
YAML
::
Value
<<
56
;
out
<<
YAML
::
EndMap
;
out
<<
YAML
::
EndSeq
;
out
<<
YAML
::
EndSeq
;
out
<<
YAML
::
EndDoc
;
std
::
cout
<<
out
.
c_str
()
<<
"
\n
"
;
std
::
cout
<<
out
.
c_str
()
<<
"
\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