/src/trafficserver/lib/yamlcpp/src/emitterstate.h
Line | Count | Source |
1 | | #ifndef EMITTERSTATE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 |
2 | | #define EMITTERSTATE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 |
3 | | |
4 | | #if defined(_MSC_VER) || \ |
5 | | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ |
6 | | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 |
7 | | #pragma once |
8 | | #endif |
9 | | |
10 | | #include "setting.h" |
11 | | #include "yaml-cpp/emitterdef.h" |
12 | | #include "yaml-cpp/emittermanip.h" |
13 | | |
14 | | #include <cassert> |
15 | | #include <memory> |
16 | | #include <stack> |
17 | | #include <stdexcept> |
18 | | #include <vector> |
19 | | |
20 | | namespace YAML { |
21 | | struct FmtScope { |
22 | | enum value { Local, Global }; |
23 | | }; |
24 | | struct GroupType { |
25 | | enum value { NoType, Seq, Map }; |
26 | | }; |
27 | | struct FlowType { |
28 | | enum value { NoType, Flow, Block }; |
29 | | }; |
30 | | |
31 | | class EmitterState { |
32 | | public: |
33 | | EmitterState(); |
34 | | ~EmitterState(); |
35 | | |
36 | | // basic state checking |
37 | 909k | bool good() const { return m_isGood; } |
38 | 0 | const std::string GetLastError() const { return m_lastError; } |
39 | 0 | void SetError(const std::string& error) { |
40 | 0 | m_isGood = false; |
41 | 0 | m_lastError = error; |
42 | 0 | } |
43 | | |
44 | | // node handling |
45 | | void SetAnchor(); |
46 | | void SetAlias(); |
47 | | void SetTag(); |
48 | | void SetNonContent(); |
49 | | void SetLongKey(); |
50 | | void ForceFlow(); |
51 | | void StartedDoc(); |
52 | | void EndedDoc(); |
53 | | void StartedScalar(); |
54 | | void StartedGroup(GroupType::value type); |
55 | | void EndedGroup(GroupType::value type); |
56 | | |
57 | | EmitterNodeType::value NextGroupType(GroupType::value type) const; |
58 | | EmitterNodeType::value CurGroupNodeType() const; |
59 | | |
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; |
65 | | |
66 | | std::size_t LastIndent() const; |
67 | 81.0k | std::size_t CurIndent() const { return m_curIndent; } |
68 | 0 | bool HasAnchor() const { return m_hasAnchor; } |
69 | 162k | bool HasAlias() const { return m_hasAlias; } |
70 | 0 | bool HasTag() const { return m_hasTag; } |
71 | 361k | bool HasBegunNode() const { |
72 | 361k | return m_hasAnchor || m_hasTag || m_hasNonContent; |
73 | 361k | } |
74 | 367k | bool HasBegunContent() const { return m_hasAnchor || m_hasTag; } |
75 | | |
76 | | void ClearModifiedSettings(); |
77 | | void RestoreGlobalModifiedSettings(); |
78 | | |
79 | | // formatters |
80 | | void SetLocalValue(EMITTER_MANIP value); |
81 | | |
82 | | bool SetOutputCharset(EMITTER_MANIP value, FmtScope::value scope); |
83 | 244k | EMITTER_MANIP GetOutputCharset() const { return m_charset.get(); } |
84 | | |
85 | | bool SetStringFormat(EMITTER_MANIP value, FmtScope::value scope); |
86 | 244k | EMITTER_MANIP GetStringFormat() const { return m_strFmt.get(); } |
87 | | |
88 | | bool SetBoolFormat(EMITTER_MANIP value, FmtScope::value scope); |
89 | 0 | EMITTER_MANIP GetBoolFormat() const { return m_boolFmt.get(); } |
90 | | |
91 | | bool SetBoolLengthFormat(EMITTER_MANIP value, FmtScope::value scope); |
92 | 0 | EMITTER_MANIP GetBoolLengthFormat() const { return m_boolLengthFmt.get(); } |
93 | | |
94 | | bool SetBoolCaseFormat(EMITTER_MANIP value, FmtScope::value scope); |
95 | 0 | EMITTER_MANIP GetBoolCaseFormat() const { return m_boolCaseFmt.get(); } |
96 | | |
97 | | bool SetNullFormat(EMITTER_MANIP value, FmtScope::value scope); |
98 | 0 | EMITTER_MANIP GetNullFormat() const { return m_nullFmt.get(); } |
99 | | |
100 | | bool SetIntFormat(EMITTER_MANIP value, FmtScope::value scope); |
101 | 40.5k | EMITTER_MANIP GetIntFormat() const { return m_intFmt.get(); } |
102 | | |
103 | | bool SetIndent(std::size_t value, FmtScope::value scope); |
104 | 81.6k | std::size_t GetIndent() const { return m_indent.get(); } |
105 | | |
106 | | bool SetPreCommentIndent(std::size_t value, FmtScope::value scope); |
107 | 0 | std::size_t GetPreCommentIndent() const { return m_preCommentIndent.get(); } |
108 | | bool SetPostCommentIndent(std::size_t value, FmtScope::value scope); |
109 | 0 | std::size_t GetPostCommentIndent() const { return m_postCommentIndent.get(); } |
110 | | |
111 | | bool SetFlowType(GroupType::value groupType, EMITTER_MANIP value, |
112 | | FmtScope::value scope); |
113 | | EMITTER_MANIP GetFlowType(GroupType::value groupType) const; |
114 | | |
115 | | bool SetMapKeyFormat(EMITTER_MANIP value, FmtScope::value scope); |
116 | 162k | EMITTER_MANIP GetMapKeyFormat() const { return m_mapKeyFmt.get(); } |
117 | | |
118 | | bool SetFloatPrecision(std::size_t value, FmtScope::value scope); |
119 | 0 | std::size_t GetFloatPrecision() const { return m_floatPrecision.get(); } |
120 | | bool SetDoublePrecision(std::size_t value, FmtScope::value scope); |
121 | 0 | std::size_t GetDoublePrecision() const { return m_doublePrecision.get(); } |
122 | | |
123 | | private: |
124 | | template <typename T> |
125 | | void _Set(Setting<T>& fmt, T value, FmtScope::value scope); |
126 | | |
127 | | void StartedNode(); |
128 | | |
129 | | private: |
130 | | // basic state ok? |
131 | | bool m_isGood; |
132 | | std::string m_lastError; |
133 | | |
134 | | // other state |
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; |
149 | | |
150 | | SettingChanges m_modifiedSettings; |
151 | | SettingChanges m_globalModifiedSettings; |
152 | | |
153 | | struct Group { |
154 | | explicit Group(GroupType::value type_) |
155 | 81.6k | : type(type_), |
156 | 81.6k | flowType{}, |
157 | 81.6k | indent(0), |
158 | 81.6k | childCount(0), |
159 | 81.6k | longKey(false), |
160 | 81.6k | modifiedSettings{} {} |
161 | | |
162 | | GroupType::value type; |
163 | | FlowType::value flowType; |
164 | | std::size_t indent; |
165 | | std::size_t childCount; |
166 | | bool longKey; |
167 | | |
168 | | SettingChanges modifiedSettings; |
169 | | |
170 | 361k | EmitterNodeType::value NodeType() const { |
171 | 361k | if (type == GroupType::Seq) { |
172 | 35.1k | if (flowType == FlowType::Flow) |
173 | 35.1k | return EmitterNodeType::FlowSeq; |
174 | 0 | else |
175 | 0 | return EmitterNodeType::BlockSeq; |
176 | 325k | } else { |
177 | 325k | if (flowType == FlowType::Flow) |
178 | 325k | return EmitterNodeType::FlowMap; |
179 | 0 | else |
180 | 0 | return EmitterNodeType::BlockMap; |
181 | 325k | } |
182 | | |
183 | | // can't get here |
184 | 361k | assert(false); |
185 | 0 | return EmitterNodeType::NoType; |
186 | 0 | } |
187 | | }; |
188 | | |
189 | | std::vector<std::unique_ptr<Group>> m_groups; |
190 | | std::size_t m_curIndent; |
191 | | bool m_hasAnchor; |
192 | | bool m_hasAlias; |
193 | | bool m_hasTag; |
194 | | bool m_hasNonContent; |
195 | | std::size_t m_docCount; |
196 | | }; |
197 | | |
198 | | template <typename T> |
199 | 23.8k | void EmitterState::_Set(Setting<T>& fmt, T value, FmtScope::value scope) { |
200 | 23.8k | switch (scope) { |
201 | 17.8k | case FmtScope::Local: |
202 | 17.8k | m_modifiedSettings.push(fmt.set(value)); |
203 | 17.8k | break; |
204 | 5.96k | case FmtScope::Global: |
205 | 5.96k | fmt.set(value); |
206 | 5.96k | m_globalModifiedSettings.push( |
207 | 5.96k | fmt.set(value)); // this pushes an identity set, so when we restore, |
208 | | // it restores to the value here, and not the previous one |
209 | 5.96k | break; |
210 | 0 | default: |
211 | | assert(false); |
212 | 23.8k | } |
213 | 23.8k | } void YAML::EmitterState::_Set<YAML::EMITTER_MANIP>(YAML::Setting<YAML::EMITTER_MANIP>&, YAML::EMITTER_MANIP, YAML::FmtScope::value) Line | Count | Source | 199 | 23.8k | void EmitterState::_Set(Setting<T>& fmt, T value, FmtScope::value scope) { | 200 | 23.8k | switch (scope) { | 201 | 17.8k | case FmtScope::Local: | 202 | 17.8k | m_modifiedSettings.push(fmt.set(value)); | 203 | 17.8k | break; | 204 | 5.96k | case FmtScope::Global: | 205 | 5.96k | fmt.set(value); | 206 | 5.96k | m_globalModifiedSettings.push( | 207 | 5.96k | fmt.set(value)); // this pushes an identity set, so when we restore, | 208 | | // it restores to the value here, and not the previous one | 209 | 5.96k | break; | 210 | 0 | default: | 211 | | assert(false); | 212 | 23.8k | } | 213 | 23.8k | } |
Unexecuted instantiation: void YAML::EmitterState::_Set<unsigned long>(YAML::Setting<unsigned long>&, unsigned long, YAML::FmtScope::value) |
214 | | } // namespace YAML |
215 | | |
216 | | #endif // EMITTERSTATE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 |