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
0e3e6791
Commit
0e3e6791
authored
May 22, 2012
by
Jesse Beder
Browse files
Added flow map, simple key/value
parent
b8a87c43
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
115 additions
and
2 deletions
+115
-2
include/yaml-cpp/emitter.h
include/yaml-cpp/emitter.h
+9
-1
src/emitter.cpp
src/emitter.cpp
+96
-0
src/emitterstate.cpp
src/emitterstate.cpp
+9
-1
src/emitterstate.h
src/emitterstate.h
+1
-0
No files found.
include/yaml-cpp/emitter.h
View file @
0e3e6791
...
@@ -93,11 +93,19 @@ namespace YAML
...
@@ -93,11 +93,19 @@ namespace YAML
void
PrepareTopNode
(
EmitterNodeType
::
value
child
);
void
PrepareTopNode
(
EmitterNodeType
::
value
child
);
void
FlowSeqPrepareNode
(
EmitterNodeType
::
value
child
);
void
FlowSeqPrepareNode
(
EmitterNodeType
::
value
child
);
void
BlockSeqPrepareNode
(
EmitterNodeType
::
value
child
);
void
BlockSeqPrepareNode
(
EmitterNodeType
::
value
child
);
void
FlowMapPrepareNode
(
EmitterNodeType
::
value
child
);
void
FlowMapPrepareNode
(
EmitterNodeType
::
value
child
);
void
FlowMapPrepareLongKey
(
EmitterNodeType
::
value
child
);
void
FlowMapPrepareLongKeyValue
(
EmitterNodeType
::
value
child
);
void
FlowMapPrepareSimpleKey
(
EmitterNodeType
::
value
child
);
void
FlowMapPrepareSimpleKeyValue
(
EmitterNodeType
::
value
child
);
void
BlockMapPrepareNode
(
EmitterNodeType
::
value
child
);
void
BlockMapPrepareNode
(
EmitterNodeType
::
value
child
);
void
BlockMapPrepareLongKey
(
EmitterNodeType
::
value
child
);
void
BlockMapPrepareLongKey
(
EmitterNodeType
::
value
child
);
void
BlockMapPrepareSimpleKey
(
EmitterNodeType
::
value
child
);
void
BlockMapPrepareLongKeyValue
(
EmitterNodeType
::
value
child
);
void
BlockMapPrepareLongKeyValue
(
EmitterNodeType
::
value
child
);
void
BlockMapPrepareSimpleKey
(
EmitterNodeType
::
value
child
);
void
BlockMapPrepareSimpleKeyValue
(
EmitterNodeType
::
value
child
);
void
BlockMapPrepareSimpleKeyValue
(
EmitterNodeType
::
value
child
);
void
SpaceOrIndentTo
(
bool
requireSpace
,
unsigned
indent
);
void
SpaceOrIndentTo
(
bool
requireSpace
,
unsigned
indent
);
...
...
src/emitter.cpp
View file @
0e3e6791
...
@@ -221,6 +221,9 @@ namespace YAML
...
@@ -221,6 +221,9 @@ namespace YAML
if
(
!
good
())
if
(
!
good
())
return
;
return
;
if
(
m_pState
->
CurGroupChildCount
()
==
0
)
m_pState
->
ForceFlow
();
if
(
m_pState
->
CurGroupFlowType
()
==
FlowType
::
Flow
)
{
if
(
m_pState
->
CurGroupFlowType
()
==
FlowType
::
Flow
)
{
if
(
m_stream
.
comment
())
if
(
m_stream
.
comment
())
m_stream
<<
"
\n
"
;
m_stream
<<
"
\n
"
;
...
@@ -250,6 +253,18 @@ namespace YAML
...
@@ -250,6 +253,18 @@ namespace YAML
if
(
!
good
())
if
(
!
good
())
return
;
return
;
if
(
m_pState
->
CurGroupChildCount
()
==
0
)
m_pState
->
ForceFlow
();
if
(
m_pState
->
CurGroupFlowType
()
==
FlowType
::
Flow
)
{
if
(
m_stream
.
comment
())
m_stream
<<
"
\n
"
;
m_stream
<<
IndentTo
(
m_pState
->
CurIndent
());
if
(
m_pState
->
CurGroupChildCount
()
==
0
)
m_stream
<<
"{"
;
m_stream
<<
"}"
;
}
m_pState
->
EndedGroup
(
GroupType
::
Map
);
m_pState
->
EndedGroup
(
GroupType
::
Map
);
}
}
...
@@ -390,6 +405,87 @@ namespace YAML
...
@@ -390,6 +405,87 @@ namespace YAML
void
Emitter
::
FlowMapPrepareNode
(
EmitterNodeType
::
value
child
)
void
Emitter
::
FlowMapPrepareNode
(
EmitterNodeType
::
value
child
)
{
{
if
(
m_pState
->
CurGroupChildCount
()
%
2
==
0
)
{
if
(
m_pState
->
GetMapKeyFormat
()
==
LongKey
)
m_pState
->
SetLongKey
();
if
(
m_pState
->
CurGroupLongKey
())
FlowMapPrepareLongKey
(
child
);
else
FlowMapPrepareSimpleKey
(
child
);
}
else
{
if
(
m_pState
->
CurGroupLongKey
())
FlowMapPrepareLongKeyValue
(
child
);
else
FlowMapPrepareSimpleKeyValue
(
child
);
}
}
void
Emitter
::
FlowMapPrepareLongKey
(
EmitterNodeType
::
value
child
)
{
}
void
Emitter
::
FlowMapPrepareLongKeyValue
(
EmitterNodeType
::
value
child
)
{
}
void
Emitter
::
FlowMapPrepareSimpleKey
(
EmitterNodeType
::
value
child
)
{
const
unsigned
curIndent
=
m_pState
->
CurIndent
();
const
unsigned
lastIndent
=
m_pState
->
LastIndent
();
if
(
!
m_pState
->
HasBegunNode
())
{
if
(
m_stream
.
comment
())
m_stream
<<
"
\n
"
;
m_stream
<<
IndentTo
(
lastIndent
);
if
(
m_pState
->
CurGroupChildCount
()
==
0
)
m_stream
<<
"{"
;
else
m_stream
<<
","
;
}
switch
(
child
)
{
case
EmitterNodeType
::
None
:
break
;
case
EmitterNodeType
::
Property
:
case
EmitterNodeType
::
Scalar
:
case
EmitterNodeType
::
FlowSeq
:
case
EmitterNodeType
::
FlowMap
:
SpaceOrIndentTo
(
m_pState
->
HasBegunContent
()
||
m_pState
->
CurGroupChildCount
()
>
0
,
curIndent
);
break
;
case
EmitterNodeType
::
BlockSeq
:
case
EmitterNodeType
::
BlockMap
:
assert
(
false
);
break
;
}
}
void
Emitter
::
FlowMapPrepareSimpleKeyValue
(
EmitterNodeType
::
value
child
)
{
const
unsigned
curIndent
=
m_pState
->
CurIndent
();
const
unsigned
lastIndent
=
m_pState
->
LastIndent
();
if
(
!
m_pState
->
HasBegunNode
())
{
if
(
m_stream
.
comment
())
m_stream
<<
"
\n
"
;
m_stream
<<
IndentTo
(
lastIndent
);
m_stream
<<
":"
;
}
switch
(
child
)
{
case
EmitterNodeType
::
None
:
break
;
case
EmitterNodeType
::
Property
:
case
EmitterNodeType
::
Scalar
:
case
EmitterNodeType
::
FlowSeq
:
case
EmitterNodeType
::
FlowMap
:
SpaceOrIndentTo
(
m_pState
->
HasBegunContent
()
||
m_pState
->
CurGroupChildCount
()
>
0
,
curIndent
);
break
;
case
EmitterNodeType
::
BlockSeq
:
case
EmitterNodeType
::
BlockMap
:
assert
(
false
);
break
;
}
}
}
void
Emitter
::
BlockMapPrepareNode
(
EmitterNodeType
::
value
child
)
void
Emitter
::
BlockMapPrepareNode
(
EmitterNodeType
::
value
child
)
...
...
src/emitterstate.cpp
View file @
0e3e6791
...
@@ -65,10 +65,18 @@ namespace YAML
...
@@ -65,10 +65,18 @@ namespace YAML
return
;
return
;
assert
(
m_groups
.
top
().
type
==
GroupType
::
Map
);
assert
(
m_groups
.
top
().
type
==
GroupType
::
Map
);
assert
(
m_groups
.
top
().
flowType
==
FlowType
::
Block
);
m_groups
.
top
().
longKey
=
true
;
m_groups
.
top
().
longKey
=
true
;
}
}
void
EmitterState
::
ForceFlow
()
{
assert
(
!
m_groups
.
empty
());
if
(
m_groups
.
empty
())
return
;
m_groups
.
top
().
flowType
=
FlowType
::
Flow
;
}
void
EmitterState
::
StartedNode
()
void
EmitterState
::
StartedNode
()
{
{
if
(
m_groups
.
empty
())
{
if
(
m_groups
.
empty
())
{
...
...
src/emitterstate.h
View file @
0e3e6791
...
@@ -38,6 +38,7 @@ namespace YAML
...
@@ -38,6 +38,7 @@ namespace YAML
void
SetTag
();
void
SetTag
();
void
SetNonContent
();
void
SetNonContent
();
void
SetLongKey
();
void
SetLongKey
();
void
ForceFlow
();
void
StartedScalar
();
void
StartedScalar
();
void
StartedGroup
(
GroupType
::
value
type
);
void
StartedGroup
(
GroupType
::
value
type
);
void
EndedGroup
(
GroupType
::
value
type
);
void
EndedGroup
(
GroupType
::
value
type
);
...
...
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