scide: implement selectionLength for openDocument
[supercollider.git] / external_libraries / yaml-cpp-0.3.0 / src / emitterstate.h
blob5698e3254bcc853609362cad58cbdba3af013d28
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
5 #pragma once
6 #endif
9 #include "ptr_stack.h"
10 #include "setting.h"
11 #include "yaml-cpp/emittermanip.h"
12 #include <cassert>
13 #include <vector>
14 #include <stack>
15 #include <memory>
17 namespace YAML
19 enum FMT_SCOPE {
20 LOCAL,
21 GLOBAL
24 enum GROUP_TYPE {
25 GT_NONE,
26 GT_SEQ,
27 GT_MAP
30 enum FLOW_TYPE {
31 FT_NONE,
32 FT_FLOW,
33 FT_BLOCK
36 enum NODE_STATE {
37 NS_START,
38 NS_READY_FOR_ATOM,
39 NS_END
42 enum EMITTER_STATE {
43 ES_WAITING_FOR_DOC,
44 ES_WRITING_DOC,
45 ES_DONE_WITH_DOC,
47 // block seq
48 ES_WAITING_FOR_BLOCK_SEQ_ENTRY,
49 ES_WRITING_BLOCK_SEQ_ENTRY,
50 ES_DONE_WITH_BLOCK_SEQ_ENTRY,
52 // flow seq
53 ES_WAITING_FOR_FLOW_SEQ_ENTRY,
54 ES_WRITING_FLOW_SEQ_ENTRY,
55 ES_DONE_WITH_FLOW_SEQ_ENTRY,
57 // block map
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,
66 // flow map
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
76 class EmitterState
78 public:
79 EmitterState();
80 ~EmitterState();
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);
95 // group handling
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();
104 void StartLongKey();
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();
116 // formatters
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(); }
154 private:
155 template <typename T>
156 void _Set(Setting<T>& fmt, T value, FMT_SCOPE scope);
158 private:
159 // basic state ok?
160 bool m_isGood;
161 std::string m_lastError;
163 // other state
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;
183 struct Group {
184 Group(GROUP_TYPE type_): type(type_), usingLongKey(false), indent(0) {}
186 GROUP_TYPE type;
187 EMITTER_MANIP flow;
188 bool usingLongKey;
189 int indent;
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) {
202 switch(scope) {
203 case LOCAL:
204 m_modifiedSettings.push(fmt.set(value));
205 break;
206 case GLOBAL:
207 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
210 break;
211 default:
212 assert(false);
217 #endif // EMITTERSTATE_H_62B23520_7C8E_11DE_8A39_0800200C9A66