1 #ifndef EMITTERSTATE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 #define EMITTERSTATE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 4 #if defined(_MSC_VER) || \ 5 (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 11 #include "yaml-cpp/emitterdef.h" 12 #include "yaml-cpp/emittermanip.h" 22 enum value { Local, Global };
25 enum value { NoType, Seq, Map };
28 enum value { NoType, Flow, Block };
37 bool good()
const {
return m_isGood; }
38 const std::string GetLastError()
const {
return m_lastError; }
39 void SetError(
const std::string& error) {
54 void StartedGroup(GroupType::value type);
55 void EndedGroup(GroupType::value type);
57 EmitterNodeType::value NextGroupType(GroupType::value type)
const;
58 EmitterNodeType::value CurGroupNodeType()
const;
60 GroupType::value CurGroupType()
const;
61 FlowType::value CurGroupFlowType()
const;
62 std::size_t CurGroupIndent()
const;
63 std::size_t CurGroupChildCount()
const;
64 bool CurGroupLongKey()
const;
66 std::size_t LastIndent()
const;
67 std::size_t CurIndent()
const {
return m_curIndent; }
68 bool HasAnchor()
const {
return m_hasAnchor; }
69 bool HasAlias()
const {
return m_hasAlias; }
70 bool HasTag()
const {
return m_hasTag; }
71 bool HasBegunNode()
const {
72 return m_hasAnchor || m_hasTag || m_hasNonContent;
74 bool HasBegunContent()
const {
return m_hasAnchor || m_hasTag; }
76 void ClearModifiedSettings();
77 void RestoreGlobalModifiedSettings();
80 void SetLocalValue(EMITTER_MANIP value);
82 bool SetOutputCharset(EMITTER_MANIP value, FmtScope::value scope);
83 EMITTER_MANIP GetOutputCharset()
const {
return m_charset.get(); }
85 bool SetStringFormat(EMITTER_MANIP value, FmtScope::value scope);
86 EMITTER_MANIP GetStringFormat()
const {
return m_strFmt.get(); }
88 bool SetBoolFormat(EMITTER_MANIP value, FmtScope::value scope);
89 EMITTER_MANIP GetBoolFormat()
const {
return m_boolFmt.get(); }
91 bool SetBoolLengthFormat(EMITTER_MANIP value, FmtScope::value scope);
92 EMITTER_MANIP GetBoolLengthFormat()
const {
return m_boolLengthFmt.get(); }
94 bool SetBoolCaseFormat(EMITTER_MANIP value, FmtScope::value scope);
95 EMITTER_MANIP GetBoolCaseFormat()
const {
return m_boolCaseFmt.get(); }
97 bool SetNullFormat(EMITTER_MANIP value, FmtScope::value scope);
98 EMITTER_MANIP GetNullFormat()
const {
return m_nullFmt.get(); }
100 bool SetIntFormat(EMITTER_MANIP value, FmtScope::value scope);
101 EMITTER_MANIP GetIntFormat()
const {
return m_intFmt.get(); }
103 bool SetIndent(std::size_t value, FmtScope::value scope);
104 std::size_t GetIndent()
const {
return m_indent.get(); }
106 bool SetPreCommentIndent(std::size_t value, FmtScope::value scope);
107 std::size_t GetPreCommentIndent()
const {
return m_preCommentIndent.get(); }
108 bool SetPostCommentIndent(std::size_t value, FmtScope::value scope);
109 std::size_t GetPostCommentIndent()
const {
return m_postCommentIndent.get(); }
111 bool SetFlowType(GroupType::value groupType, EMITTER_MANIP value,
112 FmtScope::value scope);
113 EMITTER_MANIP GetFlowType(GroupType::value groupType)
const;
115 bool SetMapKeyFormat(EMITTER_MANIP value, FmtScope::value scope);
116 EMITTER_MANIP GetMapKeyFormat()
const {
return m_mapKeyFmt.get(); }
118 bool SetFloatPrecision(std::size_t value, FmtScope::value scope);
119 std::size_t GetFloatPrecision()
const {
return m_floatPrecision.get(); }
120 bool SetDoublePrecision(std::size_t value, FmtScope::value scope);
121 std::size_t GetDoublePrecision()
const {
return m_doublePrecision.get(); }
124 template <
typename T>
125 void _Set(Setting<T>& fmt, T value, FmtScope::value scope);
132 std::string m_lastError;
135 Setting<EMITTER_MANIP> m_charset;
136 Setting<EMITTER_MANIP> m_strFmt;
137 Setting<EMITTER_MANIP> m_boolFmt;
138 Setting<EMITTER_MANIP> m_boolLengthFmt;
139 Setting<EMITTER_MANIP> m_boolCaseFmt;
140 Setting<EMITTER_MANIP> m_nullFmt;
141 Setting<EMITTER_MANIP> m_intFmt;
142 Setting<std::size_t> m_indent;
143 Setting<std::size_t> m_preCommentIndent, m_postCommentIndent;
144 Setting<EMITTER_MANIP> m_seqFmt;
145 Setting<EMITTER_MANIP> m_mapFmt;
146 Setting<EMITTER_MANIP> m_mapKeyFmt;
147 Setting<std::size_t> m_floatPrecision;
148 Setting<std::size_t> m_doublePrecision;
150 SettingChanges m_modifiedSettings;
151 SettingChanges m_globalModifiedSettings;
154 explicit Group(GroupType::value type_)
160 modifiedSettings{} {}
162 GroupType::value type;
163 FlowType::value flowType;
165 std::size_t childCount;
168 SettingChanges modifiedSettings;
170 EmitterNodeType::value NodeType()
const {
171 if (type == GroupType::Seq) {
172 if (flowType == FlowType::Flow)
173 return EmitterNodeType::FlowSeq;
175 return EmitterNodeType::BlockSeq;
177 if (flowType == FlowType::Flow)
178 return EmitterNodeType::FlowMap;
180 return EmitterNodeType::BlockMap;
185 return EmitterNodeType::NoType;
189 std::vector<std::unique_ptr<Group>> m_groups;
190 std::size_t m_curIndent;
194 bool m_hasNonContent;
195 std::size_t m_docCount;
198 template <
typename T>
199 void EmitterState::_Set(Setting<T>& fmt, T value, FmtScope::value scope) {
201 case FmtScope::Local:
202 m_modifiedSettings.push(fmt.set(value));
204 case FmtScope::Global:
206 m_globalModifiedSettings.push(
216 #endif // EMITTERSTATE_H_62B23520_7C8E_11DE_8A39_0800200C9A66