Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yaml-cpp
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
yaml-cpp
Commits
41c2ddc0
Commit
41c2ddc0
authored
May 21, 2012
by
Jesse Beder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Switched the emitter state enums to scoped enums
parent
39165338
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
107 additions
and
120 deletions
+107
-120
src/emitter.cpp
+44
-44
src/emitterstate.cpp
+35
-35
src/emitterstate.h
+28
-41
No files found.
src/emitter.cpp
View file @
41c2ddc0
This diff is collapsed.
Click to expand it.
src/emitterstate.cpp
View file @
41c2ddc0
...
...
@@ -35,18 +35,18 @@ namespace YAML
// . Only the ones that make sense will be accepted
void
EmitterState
::
SetLocalValue
(
EMITTER_MANIP
value
)
{
SetOutputCharset
(
value
,
LOCAL
);
SetStringFormat
(
value
,
LOCAL
);
SetBoolFormat
(
value
,
LOCAL
);
SetBoolCaseFormat
(
value
,
LOCAL
);
SetBoolLengthFormat
(
value
,
LOCAL
);
SetIntFormat
(
value
,
LOCAL
);
SetFlowType
(
G
T_SEQ
,
value
,
LOCAL
);
SetFlowType
(
G
T_MAP
,
value
,
LOCAL
);
SetMapKeyFormat
(
value
,
LOCAL
);
SetOutputCharset
(
value
,
FmtScope
::
Local
);
SetStringFormat
(
value
,
FmtScope
::
Local
);
SetBoolFormat
(
value
,
FmtScope
::
Local
);
SetBoolCaseFormat
(
value
,
FmtScope
::
Local
);
SetBoolLengthFormat
(
value
,
FmtScope
::
Local
);
SetIntFormat
(
value
,
FmtScope
::
Local
);
SetFlowType
(
G
roupType
::
Seq
,
value
,
FmtScope
::
Local
);
SetFlowType
(
G
roupType
::
Map
,
value
,
FmtScope
::
Local
);
SetMapKeyFormat
(
value
,
FmtScope
::
Local
);
}
void
EmitterState
::
BeginGroup
(
G
ROUP_TYPE
type
)
void
EmitterState
::
BeginGroup
(
G
roupType
::
value
type
)
{
unsigned
lastIndent
=
(
m_groups
.
empty
()
?
0
:
m_groups
.
top
().
indent
);
m_curIndent
+=
lastIndent
;
...
...
@@ -64,7 +64,7 @@ namespace YAML
m_groups
.
push
(
pGroup
);
}
void
EmitterState
::
EndGroup
(
G
ROUP_TYPE
type
)
void
EmitterState
::
EndGroup
(
G
roupType
::
value
type
)
{
if
(
m_groups
.
empty
())
return
SetError
(
ErrorMsg
::
UNMATCHED_GROUP_TAG
);
...
...
@@ -86,20 +86,20 @@ namespace YAML
m_globalModifiedSettings
.
restore
();
}
G
ROUP_TYPE
EmitterState
::
GetCurGroupType
()
const
G
roupType
::
value
EmitterState
::
GetCurGroupType
()
const
{
if
(
m_groups
.
empty
())
return
G
T_NONE
;
return
G
roupType
::
None
;
return
m_groups
.
top
().
type
;
}
FLOW_TYPE
EmitterState
::
GetCurGroupFlowType
()
const
FlowType
::
value
EmitterState
::
GetCurGroupFlowType
()
const
{
if
(
m_groups
.
empty
())
return
F
T_NONE
;
return
F
lowType
::
None
;
return
(
m_groups
.
top
().
flow
==
Flow
?
F
T_FLOW
:
FT_BLOCK
);
return
(
m_groups
.
top
().
flow
==
Flow
?
F
lowType
::
Flow
:
FlowType
::
Block
);
}
bool
EmitterState
::
CurrentlyInLongKey
()
...
...
@@ -126,7 +126,7 @@ namespace YAML
m_modifiedSettings
.
clear
();
}
bool
EmitterState
::
SetOutputCharset
(
EMITTER_MANIP
value
,
F
MT_SCOPE
scope
)
bool
EmitterState
::
SetOutputCharset
(
EMITTER_MANIP
value
,
F
mtScope
::
value
scope
)
{
switch
(
value
)
{
case
EmitNonAscii
:
...
...
@@ -138,7 +138,7 @@ namespace YAML
}
}
bool
EmitterState
::
SetStringFormat
(
EMITTER_MANIP
value
,
F
MT_SCOPE
scope
)
bool
EmitterState
::
SetStringFormat
(
EMITTER_MANIP
value
,
F
mtScope
::
value
scope
)
{
switch
(
value
)
{
case
Auto
:
...
...
@@ -152,7 +152,7 @@ namespace YAML
}
}
bool
EmitterState
::
SetBoolFormat
(
EMITTER_MANIP
value
,
F
MT_SCOPE
scope
)
bool
EmitterState
::
SetBoolFormat
(
EMITTER_MANIP
value
,
F
mtScope
::
value
scope
)
{
switch
(
value
)
{
case
OnOffBool
:
...
...
@@ -165,7 +165,7 @@ namespace YAML
}
}
bool
EmitterState
::
SetBoolLengthFormat
(
EMITTER_MANIP
value
,
F
MT_SCOPE
scope
)
bool
EmitterState
::
SetBoolLengthFormat
(
EMITTER_MANIP
value
,
F
mtScope
::
value
scope
)
{
switch
(
value
)
{
case
LongBool
:
...
...
@@ -177,7 +177,7 @@ namespace YAML
}
}
bool
EmitterState
::
SetBoolCaseFormat
(
EMITTER_MANIP
value
,
F
MT_SCOPE
scope
)
bool
EmitterState
::
SetBoolCaseFormat
(
EMITTER_MANIP
value
,
F
mtScope
::
value
scope
)
{
switch
(
value
)
{
case
UpperCase
:
...
...
@@ -190,7 +190,7 @@ namespace YAML
}
}
bool
EmitterState
::
SetIntFormat
(
EMITTER_MANIP
value
,
F
MT_SCOPE
scope
)
bool
EmitterState
::
SetIntFormat
(
EMITTER_MANIP
value
,
F
mtScope
::
value
scope
)
{
switch
(
value
)
{
case
Dec
:
...
...
@@ -203,7 +203,7 @@ namespace YAML
}
}
bool
EmitterState
::
SetIndent
(
unsigned
value
,
F
MT_SCOPE
scope
)
bool
EmitterState
::
SetIndent
(
unsigned
value
,
F
mtScope
::
value
scope
)
{
if
(
value
==
0
)
return
false
;
...
...
@@ -212,7 +212,7 @@ namespace YAML
return
true
;
}
bool
EmitterState
::
SetPreCommentIndent
(
unsigned
value
,
F
MT_SCOPE
scope
)
bool
EmitterState
::
SetPreCommentIndent
(
unsigned
value
,
F
mtScope
::
value
scope
)
{
if
(
value
==
0
)
return
false
;
...
...
@@ -221,7 +221,7 @@ namespace YAML
return
true
;
}
bool
EmitterState
::
SetPostCommentIndent
(
unsigned
value
,
F
MT_SCOPE
scope
)
bool
EmitterState
::
SetPostCommentIndent
(
unsigned
value
,
F
mtScope
::
value
scope
)
{
if
(
value
==
0
)
return
false
;
...
...
@@ -230,30 +230,30 @@ namespace YAML
return
true
;
}
bool
EmitterState
::
SetFlowType
(
G
ROUP_TYPE
groupType
,
EMITTER_MANIP
value
,
FMT_SCOPE
scope
)
bool
EmitterState
::
SetFlowType
(
G
roupType
::
value
groupType
,
EMITTER_MANIP
value
,
FmtScope
::
value
scope
)
{
switch
(
value
)
{
case
Block
:
case
Flow
:
_Set
(
groupType
==
G
T_SEQ
?
m_seqFmt
:
m_mapFmt
,
value
,
scope
);
_Set
(
groupType
==
G
roupType
::
Seq
?
m_seqFmt
:
m_mapFmt
,
value
,
scope
);
return
true
;
default
:
return
false
;
}
}
EMITTER_MANIP
EmitterState
::
GetFlowType
(
G
ROUP_TYPE
groupType
)
const
EMITTER_MANIP
EmitterState
::
GetFlowType
(
G
roupType
::
value
groupType
)
const
{
// force flow style if we're currently in a flow
FLOW_TYPE
flowType
=
GetCurGroupFlowType
();
if
(
flowType
==
F
T_FLOW
)
FlowType
::
value
flowType
=
GetCurGroupFlowType
();
if
(
flowType
==
F
lowType
::
Flow
)
return
Flow
;
// otherwise, go with what's asked of us
e
return
(
groupType
==
G
T_SEQ
?
m_seqFmt
.
get
()
:
m_mapFmt
.
get
());
// otherwise, go with what's asked of us
return
(
groupType
==
G
roupType
::
Seq
?
m_seqFmt
.
get
()
:
m_mapFmt
.
get
());
}
bool
EmitterState
::
SetMapKeyFormat
(
EMITTER_MANIP
value
,
F
MT_SCOPE
scope
)
bool
EmitterState
::
SetMapKeyFormat
(
EMITTER_MANIP
value
,
F
mtScope
::
value
scope
)
{
switch
(
value
)
{
case
Auto
:
...
...
@@ -265,7 +265,7 @@ namespace YAML
}
}
bool
EmitterState
::
SetFloatPrecision
(
int
value
,
F
MT_SCOPE
scope
)
bool
EmitterState
::
SetFloatPrecision
(
int
value
,
F
mtScope
::
value
scope
)
{
if
(
value
<
0
||
value
>
std
::
numeric_limits
<
float
>::
digits10
)
return
false
;
...
...
@@ -273,7 +273,7 @@ namespace YAML
return
true
;
}
bool
EmitterState
::
SetDoublePrecision
(
int
value
,
F
MT_SCOPE
scope
)
bool
EmitterState
::
SetDoublePrecision
(
int
value
,
F
mtScope
::
value
scope
)
{
if
(
value
<
0
||
value
>
std
::
numeric_limits
<
double
>::
digits10
)
return
false
;
...
...
src/emitterstate.h
View file @
41c2ddc0
...
...
@@ -16,23 +16,10 @@
namespace
YAML
{
enum
FMT_SCOPE
{
LOCAL
,
GLOBAL
};
enum
GROUP_TYPE
{
GT_NONE
,
GT_SEQ
,
GT_MAP
};
enum
FLOW_TYPE
{
FT_NONE
,
FT_FLOW
,
FT_BLOCK
};
struct
FmtScope
{
enum
value
{
Local
,
Global
};
};
struct
GroupType
{
enum
value
{
None
,
Seq
,
Map
};
};
struct
FlowType
{
enum
value
{
None
,
Flow
,
Block
};
};
enum
NODE_STATE
{
NS_START
,
NS_READY_FOR_ATOM
,
...
...
@@ -93,11 +80,11 @@ namespace YAML
void
SetLocalValue
(
EMITTER_MANIP
value
);
// group handling
void
BeginGroup
(
G
ROUP_TYPE
type
);
void
EndGroup
(
G
ROUP_TYPE
type
);
void
BeginGroup
(
G
roupType
::
value
type
);
void
EndGroup
(
G
roupType
::
value
type
);
G
ROUP_TYPE
GetCurGroupType
()
const
;
FLOW_TYPE
GetCurGroupFlowType
()
const
;
G
roupType
::
value
GetCurGroupType
()
const
;
FlowType
::
value
GetCurGroupFlowType
()
const
;
int
GetCurIndent
()
const
{
return
m_curIndent
;
}
bool
CurrentlyInLongKey
();
...
...
@@ -114,46 +101,46 @@ namespace YAML
void
ClearModifiedSettings
();
// formatters
bool
SetOutputCharset
(
EMITTER_MANIP
value
,
F
MT_SCOPE
scope
);
bool
SetOutputCharset
(
EMITTER_MANIP
value
,
F
mtScope
::
value
scope
);
EMITTER_MANIP
GetOutputCharset
()
const
{
return
m_charset
.
get
();
}
bool
SetStringFormat
(
EMITTER_MANIP
value
,
F
MT_SCOPE
scope
);
bool
SetStringFormat
(
EMITTER_MANIP
value
,
F
mtScope
::
value
scope
);
EMITTER_MANIP
GetStringFormat
()
const
{
return
m_strFmt
.
get
();
}
bool
SetBoolFormat
(
EMITTER_MANIP
value
,
F
MT_SCOPE
scope
);
bool
SetBoolFormat
(
EMITTER_MANIP
value
,
F
mtScope
::
value
scope
);
EMITTER_MANIP
GetBoolFormat
()
const
{
return
m_boolFmt
.
get
();
}
bool
SetBoolLengthFormat
(
EMITTER_MANIP
value
,
F
MT_SCOPE
scope
);
bool
SetBoolLengthFormat
(
EMITTER_MANIP
value
,
F
mtScope
::
value
scope
);
EMITTER_MANIP
GetBoolLengthFormat
()
const
{
return
m_boolLengthFmt
.
get
();
}
bool
SetBoolCaseFormat
(
EMITTER_MANIP
value
,
F
MT_SCOPE
scope
);
bool
SetBoolCaseFormat
(
EMITTER_MANIP
value
,
F
mtScope
::
value
scope
);
EMITTER_MANIP
GetBoolCaseFormat
()
const
{
return
m_boolCaseFmt
.
get
();
}
bool
SetIntFormat
(
EMITTER_MANIP
value
,
F
MT_SCOPE
scope
);
bool
SetIntFormat
(
EMITTER_MANIP
value
,
F
mtScope
::
value
scope
);
EMITTER_MANIP
GetIntFormat
()
const
{
return
m_intFmt
.
get
();
}
bool
SetIndent
(
unsigned
value
,
F
MT_SCOPE
scope
);
bool
SetIndent
(
unsigned
value
,
F
mtScope
::
value
scope
);
int
GetIndent
()
const
{
return
m_indent
.
get
();
}
bool
SetPreCommentIndent
(
unsigned
value
,
F
MT_SCOPE
scope
);
bool
SetPreCommentIndent
(
unsigned
value
,
F
mtScope
::
value
scope
);
int
GetPreCommentIndent
()
const
{
return
m_preCommentIndent
.
get
();
}
bool
SetPostCommentIndent
(
unsigned
value
,
F
MT_SCOPE
scope
);
bool
SetPostCommentIndent
(
unsigned
value
,
F
mtScope
::
value
scope
);
int
GetPostCommentIndent
()
const
{
return
m_postCommentIndent
.
get
();
}
bool
SetFlowType
(
G
ROUP_TYPE
groupType
,
EMITTER_MANIP
value
,
FMT_SCOPE
scope
);
EMITTER_MANIP
GetFlowType
(
G
ROUP_TYPE
groupType
)
const
;
bool
SetFlowType
(
G
roupType
::
value
groupType
,
EMITTER_MANIP
value
,
FmtScope
::
value
scope
);
EMITTER_MANIP
GetFlowType
(
G
roupType
::
value
groupType
)
const
;
bool
SetMapKeyFormat
(
EMITTER_MANIP
value
,
F
MT_SCOPE
scope
);
bool
SetMapKeyFormat
(
EMITTER_MANIP
value
,
F
mtScope
::
value
scope
);
EMITTER_MANIP
GetMapKeyFormat
()
const
{
return
m_mapKeyFmt
.
get
();
}
bool
SetFloatPrecision
(
int
value
,
F
MT_SCOPE
scope
);
bool
SetFloatPrecision
(
int
value
,
F
mtScope
::
value
scope
);
unsigned
GetFloatPrecision
()
const
{
return
m_floatPrecision
.
get
();
}
bool
SetDoublePrecision
(
int
value
,
F
MT_SCOPE
scope
);
bool
SetDoublePrecision
(
int
value
,
F
mtScope
::
value
scope
);
unsigned
GetDoublePrecision
()
const
{
return
m_doublePrecision
.
get
();
}
private
:
template
<
typename
T
>
void
_Set
(
Setting
<
T
>&
fmt
,
T
value
,
F
MT_SCOPE
scope
);
void
_Set
(
Setting
<
T
>&
fmt
,
T
value
,
F
mtScope
::
value
scope
);
private
:
// basic state ok?
...
...
@@ -181,9 +168,9 @@ namespace YAML
SettingChanges
m_globalModifiedSettings
;
struct
Group
{
Group
(
G
ROUP_TYPE
type_
)
:
type
(
type_
),
usingLongKey
(
false
),
indent
(
0
)
{}
Group
(
G
roupType
::
value
type_
)
:
type
(
type_
),
usingLongKey
(
false
),
indent
(
0
)
{}
GROUP_TYPE
type
;
GroupType
::
value
type
;
EMITTER_MANIP
flow
;
bool
usingLongKey
;
int
indent
;
...
...
@@ -198,12 +185,12 @@ namespace YAML
};
template
<
typename
T
>
void
EmitterState
::
_Set
(
Setting
<
T
>&
fmt
,
T
value
,
F
MT_SCOPE
scope
)
{
void
EmitterState
::
_Set
(
Setting
<
T
>&
fmt
,
T
value
,
F
mtScope
::
value
scope
)
{
switch
(
scope
)
{
case
LOCAL
:
case
FmtScope
:
:
Local
:
m_modifiedSettings
.
push
(
fmt
.
set
(
value
));
break
;
case
GLOBAL
:
case
FmtScope
:
:
Global
:
fmt
.
set
(
value
);
m_globalModifiedSettings
.
push
(
fmt
.
set
(
value
));
// this pushes an identity set, so when we restore,
// it restores to the value here, and not the previous one
...
...
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