emitterstate.h
Go to the documentation of this file.
1 #ifndef EMITTERSTATE_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
2 #define EMITTERSTATE_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
3 
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
7 
8 
9 #include "ptr_stack.h"
10 #include "setting.h"
12 #include <cassert>
13 #include <vector>
14 #include <stack>
15 #include <memory>
16 
17 namespace YAML_PM
18 {
19  enum FMT_SCOPE {
22  };
23 
24  enum GROUP_TYPE {
28  };
29 
30  enum FLOW_TYPE {
34  };
35 
36  enum NODE_STATE {
40  };
41 
46 
47  // block seq
51 
52  // flow seq
56 
57  // block map
65 
66  // flow map
74  };
75 
77  {
78  public:
79  EmitterState();
80  ~EmitterState();
81 
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; }
86 
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(); }
92 
93  void SetLocalValue(EMITTER_MANIP value);
94 
95  // group handling
96  void BeginGroup(GROUP_TYPE type);
97  void EndGroup(GROUP_TYPE type);
98 
101  int GetCurIndent() const { return m_curIndent; }
102 
103  bool CurrentlyInLongKey();
104  void StartLongKey();
105  void StartSimpleKey();
106 
113 
114  void ClearModifiedSettings();
115 
116  // formatters
117  bool SetOutputCharset(EMITTER_MANIP value, FMT_SCOPE scope);
119 
120  bool SetStringFormat(EMITTER_MANIP value, FMT_SCOPE scope);
122 
123  bool SetBoolFormat(EMITTER_MANIP value, FMT_SCOPE scope);
124  EMITTER_MANIP GetBoolFormat() const { return m_boolFmt.get(); }
125 
126  bool SetBoolLengthFormat(EMITTER_MANIP value, FMT_SCOPE scope);
128 
129  bool SetBoolCaseFormat(EMITTER_MANIP value, FMT_SCOPE scope);
131 
132  bool SetIntFormat(EMITTER_MANIP value, FMT_SCOPE scope);
133  EMITTER_MANIP GetIntFormat() const { return m_intFmt.get(); }
134 
135  bool SetIndent(unsigned value, FMT_SCOPE scope);
136  int GetIndent() const { return m_indent.get(); }
137 
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(); }
142 
143  bool SetFlowType(GROUP_TYPE groupType, EMITTER_MANIP value, FMT_SCOPE scope);
144  EMITTER_MANIP GetFlowType(GROUP_TYPE groupType) const;
145 
146  bool SetMapKeyFormat(EMITTER_MANIP value, FMT_SCOPE scope);
148 
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(); }
153 
154  private:
155  template <typename T>
156  void _Set(Setting<T>& fmt, T value, FMT_SCOPE scope);
157 
158  private:
159  // basic state ok?
160  bool m_isGood;
162 
163  // other state
164  std::stack<EMITTER_STATE> m_stateStack;
165 
179 
182 
183  struct Group {
184  Group(GROUP_TYPE type_): type(type_), usingLongKey(false), indent(0) {}
185 
189  int indent;
190 
192  };
193 
195  unsigned m_curIndent;
198  };
199 
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);
213  }
214  }
215 }
216 
217 #endif // EMITTERSTATE_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
void SetLocalValue(EMITTER_MANIP value)
EMITTER_STATE GetCurState() const
Definition: emitterstate.h:88
Setting< int > m_floatPrecision
Definition: emitterstate.h:177
void EndGroup(GROUP_TYPE type)
EMITTER_MANIP GetStringFormat() const
Definition: emitterstate.h:121
EMITTER_MANIP GetBoolLengthFormat() const
Definition: emitterstate.h:127
bool SetBoolFormat(EMITTER_MANIP value, FMT_SCOPE scope)
::std::string string
Definition: gtest.h:1979
bool SetFlowType(GROUP_TYPE groupType, EMITTER_MANIP value, FMT_SCOPE scope)
void push(std::auto_ptr< SettingChangeBase > pSettingChange)
Definition: setting.h:84
Setting< EMITTER_MANIP > m_intFmt
Definition: emitterstate.h:171
SettingChanges modifiedSettings
Definition: emitterstate.h:191
std::auto_ptr< SettingChangeBase > set(const T &value)
Definition: setting.h:59
bool SetOutputCharset(EMITTER_MANIP value, FMT_SCOPE scope)
void SetError(const std::string &error)
Definition: emitterstate.h:85
std::string m_lastError
Definition: emitterstate.h:161
void _Set(Setting< T > &fmt, T value, FMT_SCOPE scope)
Definition: emitterstate.h:201
const std::string GetLastError() const
Definition: emitterstate.h:84
Setting< EMITTER_MANIP > m_boolLengthFmt
Definition: emitterstate.h:169
std::stack< EMITTER_STATE > m_stateStack
Definition: emitterstate.h:164
bool SetIntFormat(EMITTER_MANIP value, FMT_SCOPE scope)
SettingChanges m_modifiedSettings
Definition: emitterstate.h:180
EMITTER_MANIP GetBoolFormat() const
Definition: emitterstate.h:124
bool SetStringFormat(EMITTER_MANIP value, FMT_SCOPE scope)
bool SetFloatPrecision(int value, FMT_SCOPE scope)
EMITTER_MANIP GetIntFormat() const
Definition: emitterstate.h:133
Setting< int > m_doublePrecision
Definition: emitterstate.h:178
bool SetBoolCaseFormat(EMITTER_MANIP value, FMT_SCOPE scope)
int GetCurIndent() const
Definition: emitterstate.h:101
bool SetPreCommentIndent(unsigned value, FMT_SCOPE scope)
Setting< EMITTER_MANIP > m_boolFmt
Definition: emitterstate.h:168
Setting< unsigned > m_preCommentIndent
Definition: emitterstate.h:173
Setting< EMITTER_MANIP > m_mapKeyFmt
Definition: emitterstate.h:176
unsigned GetDoublePrecision() const
Definition: emitterstate.h:152
Setting< EMITTER_MANIP > m_mapFmt
Definition: emitterstate.h:175
Setting< EMITTER_MANIP > m_seqFmt
Definition: emitterstate.h:174
void PushState(EMITTER_STATE state)
Definition: emitterstate.h:90
bool RequiresSoftSeparation() const
Definition: emitterstate.h:107
Setting< unsigned > m_indent
Definition: emitterstate.h:172
EMITTER_MANIP GetFlowType(GROUP_TYPE groupType) const
int GetPostCommentIndent() const
Definition: emitterstate.h:141
void BeginGroup(GROUP_TYPE type)
int GetPreCommentIndent() const
Definition: emitterstate.h:139
bool RequiresHardSeparation() const
Definition: emitterstate.h:108
void SwitchState(EMITTER_STATE state)
Definition: emitterstate.h:89
EMITTER_MANIP GetBoolCaseFormat() const
Definition: emitterstate.h:130
bool SetIndent(unsigned value, FMT_SCOPE scope)
SettingChanges m_globalModifiedSettings
Definition: emitterstate.h:181
EMITTER_MANIP GetMapKeyFormat() const
Definition: emitterstate.h:147
bool SetBoolLengthFormat(EMITTER_MANIP value, FMT_SCOPE scope)
FLOW_TYPE GetCurGroupFlowType() const
EMITTER_MANIP GetOutputCharset() const
Definition: emitterstate.h:118
GROUP_TYPE GetCurGroupType() const
Setting< EMITTER_MANIP > m_boolCaseFmt
Definition: emitterstate.h:170
const T get() const
Definition: setting.h:23
Setting< unsigned > m_postCommentIndent
Definition: emitterstate.h:173
bool SetMapKeyFormat(EMITTER_MANIP value, FMT_SCOPE scope)
unsigned GetFloatPrecision() const
Definition: emitterstate.h:150
Setting< EMITTER_MANIP > m_charset
Definition: emitterstate.h:166
bool SetPostCommentIndent(unsigned value, FMT_SCOPE scope)
bool SetDoublePrecision(int value, FMT_SCOPE scope)
ptr_stack< Group > m_groups
Definition: emitterstate.h:194
Setting< EMITTER_MANIP > m_strFmt
Definition: emitterstate.h:167


libpointmatcher
Author(s):
autogenerated on Sat May 27 2023 02:36:30