1 #ifndef EMITTERSTATE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
2 #define EMITTERSTATE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
4 #if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
11 #include "yaml-cpp/emittermanip.h"
48 ES_WAITING_FOR_BLOCK_SEQ_ENTRY
,
49 ES_WRITING_BLOCK_SEQ_ENTRY
,
50 ES_DONE_WITH_BLOCK_SEQ_ENTRY
,
53 ES_WAITING_FOR_FLOW_SEQ_ENTRY
,
54 ES_WRITING_FLOW_SEQ_ENTRY
,
55 ES_DONE_WITH_FLOW_SEQ_ENTRY
,
58 ES_WAITING_FOR_BLOCK_MAP_ENTRY
,
59 ES_WAITING_FOR_BLOCK_MAP_KEY
,
60 ES_WRITING_BLOCK_MAP_KEY
,
61 ES_DONE_WITH_BLOCK_MAP_KEY
,
62 ES_WAITING_FOR_BLOCK_MAP_VALUE
,
63 ES_WRITING_BLOCK_MAP_VALUE
,
64 ES_DONE_WITH_BLOCK_MAP_VALUE
,
67 ES_WAITING_FOR_FLOW_MAP_ENTRY
,
68 ES_WAITING_FOR_FLOW_MAP_KEY
,
69 ES_WRITING_FLOW_MAP_KEY
,
70 ES_DONE_WITH_FLOW_MAP_KEY
,
71 ES_WAITING_FOR_FLOW_MAP_VALUE
,
72 ES_WRITING_FLOW_MAP_VALUE
,
73 ES_DONE_WITH_FLOW_MAP_VALUE
82 // basic state checking
83 bool good() const { return m_isGood
; }
84 const std::string
GetLastError() const { return m_lastError
; }
85 void SetError(const std::string
& error
) { m_isGood
= false; m_lastError
= error
; }
87 // main state of the machine
88 EMITTER_STATE
GetCurState() const { return m_stateStack
.top(); }
89 void SwitchState(EMITTER_STATE state
) { PopState(); PushState(state
); }
90 void PushState(EMITTER_STATE state
) { m_stateStack
.push(state
); }
91 void PopState() { m_stateStack
.pop(); }
93 void SetLocalValue(EMITTER_MANIP value
);
96 void BeginGroup(GROUP_TYPE type
);
97 void EndGroup(GROUP_TYPE type
);
99 GROUP_TYPE
GetCurGroupType() const;
100 FLOW_TYPE
GetCurGroupFlowType() const;
101 int GetCurIndent() const { return m_curIndent
; }
103 bool CurrentlyInLongKey();
105 void StartSimpleKey();
107 bool RequiresSoftSeparation() const { return m_requiresSoftSeparation
; }
108 bool RequiresHardSeparation() const { return m_requiresHardSeparation
; }
109 void RequireSoftSeparation() { m_requiresSoftSeparation
= true; }
110 void RequireHardSeparation() { m_requiresSoftSeparation
= true; m_requiresHardSeparation
= true; }
111 void ForceHardSeparation() { m_requiresSoftSeparation
= false; }
112 void UnsetSeparation() { m_requiresSoftSeparation
= false; m_requiresHardSeparation
= false; }
114 void ClearModifiedSettings();
117 bool SetOutputCharset(EMITTER_MANIP value
, FMT_SCOPE scope
);
118 EMITTER_MANIP
GetOutputCharset() const { return m_charset
.get(); }
120 bool SetStringFormat(EMITTER_MANIP value
, FMT_SCOPE scope
);
121 EMITTER_MANIP
GetStringFormat() const { return m_strFmt
.get(); }
123 bool SetBoolFormat(EMITTER_MANIP value
, FMT_SCOPE scope
);
124 EMITTER_MANIP
GetBoolFormat() const { return m_boolFmt
.get(); }
126 bool SetBoolLengthFormat(EMITTER_MANIP value
, FMT_SCOPE scope
);
127 EMITTER_MANIP
GetBoolLengthFormat() const { return m_boolLengthFmt
.get(); }
129 bool SetBoolCaseFormat(EMITTER_MANIP value
, FMT_SCOPE scope
);
130 EMITTER_MANIP
GetBoolCaseFormat() const { return m_boolCaseFmt
.get(); }
132 bool SetIntFormat(EMITTER_MANIP value
, FMT_SCOPE scope
);
133 EMITTER_MANIP
GetIntFormat() const { return m_intFmt
.get(); }
135 bool SetIndent(unsigned value
, FMT_SCOPE scope
);
136 int GetIndent() const { return m_indent
.get(); }
138 bool SetPreCommentIndent(unsigned value
, FMT_SCOPE scope
);
139 int GetPreCommentIndent() const { return m_preCommentIndent
.get(); }
140 bool SetPostCommentIndent(unsigned value
, FMT_SCOPE scope
);
141 int GetPostCommentIndent() const { return m_postCommentIndent
.get(); }
143 bool SetFlowType(GROUP_TYPE groupType
, EMITTER_MANIP value
, FMT_SCOPE scope
);
144 EMITTER_MANIP
GetFlowType(GROUP_TYPE groupType
) const;
146 bool SetMapKeyFormat(EMITTER_MANIP value
, FMT_SCOPE scope
);
147 EMITTER_MANIP
GetMapKeyFormat() const { return m_mapKeyFmt
.get(); }
149 bool SetFloatPrecision(int value
, FMT_SCOPE scope
);
150 unsigned GetFloatPrecision() const { return m_floatPrecision
.get(); }
151 bool SetDoublePrecision(int value
, FMT_SCOPE scope
);
152 unsigned GetDoublePrecision() const { return m_doublePrecision
.get(); }
155 template <typename T
>
156 void _Set(Setting
<T
>& fmt
, T value
, FMT_SCOPE scope
);
161 std::string m_lastError
;
164 std::stack
<EMITTER_STATE
> m_stateStack
;
166 Setting
<EMITTER_MANIP
> m_charset
;
167 Setting
<EMITTER_MANIP
> m_strFmt
;
168 Setting
<EMITTER_MANIP
> m_boolFmt
;
169 Setting
<EMITTER_MANIP
> m_boolLengthFmt
;
170 Setting
<EMITTER_MANIP
> m_boolCaseFmt
;
171 Setting
<EMITTER_MANIP
> m_intFmt
;
172 Setting
<unsigned> m_indent
;
173 Setting
<unsigned> m_preCommentIndent
, m_postCommentIndent
;
174 Setting
<EMITTER_MANIP
> m_seqFmt
;
175 Setting
<EMITTER_MANIP
> m_mapFmt
;
176 Setting
<EMITTER_MANIP
> m_mapKeyFmt
;
177 Setting
<int> m_floatPrecision
;
178 Setting
<int> m_doublePrecision
;
180 SettingChanges m_modifiedSettings
;
181 SettingChanges m_globalModifiedSettings
;
184 Group(GROUP_TYPE type_
): type(type_
), usingLongKey(false), indent(0) {}
191 SettingChanges modifiedSettings
;
194 ptr_stack
<Group
> m_groups
;
195 unsigned m_curIndent
;
196 bool m_requiresSoftSeparation
;
197 bool m_requiresHardSeparation
;
200 template <typename T
>
201 void EmitterState::_Set(Setting
<T
>& fmt
, T value
, FMT_SCOPE scope
) {
204 m_modifiedSettings
.push(fmt
.set(value
));
208 m_globalModifiedSettings
.push(fmt
.set(value
)); // this pushes an identity set, so when we restore,
209 // it restores to the value here, and not the previous one
217 #endif // EMITTERSTATE_H_62B23520_7C8E_11DE_8A39_0800200C9A66