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
YAML_PM::EmitterState::GetCurIndent
int GetCurIndent() const
Definition: emitterstate.h:101
YAML_PM::GROUP_TYPE
GROUP_TYPE
Definition: emitterstate.h:24
YAML_PM::NS_READY_FOR_ATOM
@ NS_READY_FOR_ATOM
Definition: emitterstate.h:38
YAML_PM::EmitterState::GetMapKeyFormat
EMITTER_MANIP GetMapKeyFormat() const
Definition: emitterstate.h:147
YAML_PM::ES_WRITING_BLOCK_MAP_KEY
@ ES_WRITING_BLOCK_MAP_KEY
Definition: emitterstate.h:60
YAML_PM::EmitterState::SetLocalValue
void SetLocalValue(EMITTER_MANIP value)
Definition: emitterstate.cpp:36
YAML_PM::EmitterState::CurrentlyInLongKey
bool CurrentlyInLongKey()
Definition: emitterstate.cpp:105
YAML_PM::EmitterState::m_boolFmt
Setting< EMITTER_MANIP > m_boolFmt
Definition: emitterstate.h:168
YAML_PM::EmitterState::Group::type
GROUP_TYPE type
Definition: emitterstate.h:186
YAML_PM::ES_WRITING_DOC
@ ES_WRITING_DOC
Definition: emitterstate.h:44
YAML_PM::ES_WRITING_BLOCK_SEQ_ENTRY
@ ES_WRITING_BLOCK_SEQ_ENTRY
Definition: emitterstate.h:49
YAML_PM::ES_DONE_WITH_BLOCK_MAP_KEY
@ ES_DONE_WITH_BLOCK_MAP_KEY
Definition: emitterstate.h:61
YAML_PM::SettingChanges::push
void push(std::auto_ptr< SettingChangeBase > pSettingChange)
Definition: setting.h:84
YAML_PM::EmitterState::m_indent
Setting< unsigned > m_indent
Definition: emitterstate.h:172
YAML_PM::ES_WRITING_FLOW_SEQ_ENTRY
@ ES_WRITING_FLOW_SEQ_ENTRY
Definition: emitterstate.h:54
YAML_PM::EmitterState::GetIntFormat
EMITTER_MANIP GetIntFormat() const
Definition: emitterstate.h:133
YAML_PM::EmitterState::SetMapKeyFormat
bool SetMapKeyFormat(EMITTER_MANIP value, FMT_SCOPE scope)
Definition: emitterstate.cpp:256
YAML_PM::EmitterState::RequireSoftSeparation
void RequireSoftSeparation()
Definition: emitterstate.h:109
YAML_PM
Definition: aliasmanager.h:11
YAML_PM::EmitterState::m_postCommentIndent
Setting< unsigned > m_postCommentIndent
Definition: emitterstate.h:173
YAML_PM::EmitterState::GetFlowType
EMITTER_MANIP GetFlowType(GROUP_TYPE groupType) const
Definition: emitterstate.cpp:245
YAML_PM::FT_NONE
@ FT_NONE
Definition: emitterstate.h:31
YAML_PM::EmitterState::SetBoolCaseFormat
bool SetBoolCaseFormat(EMITTER_MANIP value, FMT_SCOPE scope)
Definition: emitterstate.cpp:180
YAML_PM::EmitterState::RequiresHardSeparation
bool RequiresHardSeparation() const
Definition: emitterstate.h:108
YAML_PM::EmitterState::RequiresSoftSeparation
bool RequiresSoftSeparation() const
Definition: emitterstate.h:107
YAML_PM::ES_WAITING_FOR_FLOW_MAP_VALUE
@ ES_WAITING_FOR_FLOW_MAP_VALUE
Definition: emitterstate.h:71
YAML_PM::EmitterState::_Set
void _Set(Setting< T > &fmt, T value, FMT_SCOPE scope)
Definition: emitterstate.h:201
YAML_PM::EmitterState::m_modifiedSettings
SettingChanges m_modifiedSettings
Definition: emitterstate.h:180
YAML_PM::EmitterState::m_curIndent
unsigned m_curIndent
Definition: emitterstate.h:195
YAML_PM::EmitterState::Group
Definition: emitterstate.h:183
YAML_PM::EmitterState::GetIndent
int GetIndent() const
Definition: emitterstate.h:136
YAML_PM::EmitterState::EndGroup
void EndGroup(GROUP_TYPE type)
Definition: emitterstate.cpp:67
YAML_PM::EmitterState::SetPostCommentIndent
bool SetPostCommentIndent(unsigned value, FMT_SCOPE scope)
Definition: emitterstate.cpp:224
YAML_PM::EmitterState::Group::usingLongKey
bool usingLongKey
Definition: emitterstate.h:188
YAML_PM::EmitterState::GetPostCommentIndent
int GetPostCommentIndent() const
Definition: emitterstate.h:141
YAML_PM::EmitterState::GetCurGroupType
GROUP_TYPE GetCurGroupType() const
Definition: emitterstate.cpp:89
YAML_PM::EMITTER_STATE
EMITTER_STATE
Definition: emitterstate.h:42
YAML_PM::EmitterState::SetFlowType
bool SetFlowType(GROUP_TYPE groupType, EMITTER_MANIP value, FMT_SCOPE scope)
Definition: emitterstate.cpp:233
YAML_PM::FLOW_TYPE
FLOW_TYPE
Definition: emitterstate.h:30
YAML_PM::EmitterState::m_lastError
std::string m_lastError
Definition: emitterstate.h:161
YAML_PM::EmitterState::m_requiresHardSeparation
bool m_requiresHardSeparation
Definition: emitterstate.h:197
YAML_PM::EmitterState::GetStringFormat
EMITTER_MANIP GetStringFormat() const
Definition: emitterstate.h:121
YAML_PM::EmitterState::m_stateStack
std::stack< EMITTER_STATE > m_stateStack
Definition: emitterstate.h:164
YAML_PM::Setting
Definition: setting.h:18
YAML_PM::ES_WAITING_FOR_FLOW_SEQ_ENTRY
@ ES_WAITING_FOR_FLOW_SEQ_ENTRY
Definition: emitterstate.h:53
YAML_PM::EmitterState::SetPreCommentIndent
bool SetPreCommentIndent(unsigned value, FMT_SCOPE scope)
Definition: emitterstate.cpp:215
YAML_PM::EmitterState::GetBoolLengthFormat
EMITTER_MANIP GetBoolLengthFormat() const
Definition: emitterstate.h:127
YAML_PM::EmitterState::m_globalModifiedSettings
SettingChanges m_globalModifiedSettings
Definition: emitterstate.h:181
YAML_PM::NS_END
@ NS_END
Definition: emitterstate.h:39
YAML_PM::EmitterState::~EmitterState
~EmitterState()
Definition: emitterstate.cpp:29
YAML_PM::ES_WAITING_FOR_BLOCK_MAP_ENTRY
@ ES_WAITING_FOR_BLOCK_MAP_ENTRY
Definition: emitterstate.h:58
YAML_PM::EmitterState::m_boolLengthFmt
Setting< EMITTER_MANIP > m_boolLengthFmt
Definition: emitterstate.h:169
YAML_PM::EmitterState::m_boolCaseFmt
Setting< EMITTER_MANIP > m_boolCaseFmt
Definition: emitterstate.h:170
testing::internal::string
::std::string string
Definition: gtest.h:1979
YAML_PM::EmitterState::m_charset
Setting< EMITTER_MANIP > m_charset
Definition: emitterstate.h:166
YAML_PM::EmitterState::RequireHardSeparation
void RequireHardSeparation()
Definition: emitterstate.h:110
YAML_PM::EmitterState::GetDoublePrecision
unsigned GetDoublePrecision() const
Definition: emitterstate.h:152
YAML_PM::ES_DONE_WITH_FLOW_MAP_VALUE
@ ES_DONE_WITH_FLOW_MAP_VALUE
Definition: emitterstate.h:73
YAML_PM::EmitterState::m_requiresSoftSeparation
bool m_requiresSoftSeparation
Definition: emitterstate.h:196
YAML_PM::EmitterState::GetCurGroupFlowType
FLOW_TYPE GetCurGroupFlowType() const
Definition: emitterstate.cpp:97
YAML_PM::EmitterState::m_strFmt
Setting< EMITTER_MANIP > m_strFmt
Definition: emitterstate.h:167
YAML_PM::ES_WAITING_FOR_BLOCK_MAP_KEY
@ ES_WAITING_FOR_BLOCK_MAP_KEY
Definition: emitterstate.h:59
YAML_PM::EmitterState::SetFloatPrecision
bool SetFloatPrecision(int value, FMT_SCOPE scope)
Definition: emitterstate.cpp:268
YAML_PM::ES_DONE_WITH_FLOW_SEQ_ENTRY
@ ES_DONE_WITH_FLOW_SEQ_ENTRY
Definition: emitterstate.h:55
YAML_PM::GT_MAP
@ GT_MAP
Definition: emitterstate.h:27
YAML_PM::EmitterState::ClearModifiedSettings
void ClearModifiedSettings()
Definition: emitterstate.cpp:124
YAML_PM::EmitterState::m_floatPrecision
Setting< int > m_floatPrecision
Definition: emitterstate.h:177
YAML_PM::EmitterState::GetLastError
const std::string GetLastError() const
Definition: emitterstate.h:84
YAML_PM::GLOBAL
@ GLOBAL
Definition: emitterstate.h:21
YAML_PM::EmitterState::StartSimpleKey
void StartSimpleKey()
Definition: emitterstate.cpp:118
YAML_PM::EmitterState::SetOutputCharset
bool SetOutputCharset(EMITTER_MANIP value, FMT_SCOPE scope)
Definition: emitterstate.cpp:129
YAML_PM::EmitterState::m_mapKeyFmt
Setting< EMITTER_MANIP > m_mapKeyFmt
Definition: emitterstate.h:176
YAML_PM::FT_BLOCK
@ FT_BLOCK
Definition: emitterstate.h:33
YAML_PM::EmitterState::m_preCommentIndent
Setting< unsigned > m_preCommentIndent
Definition: emitterstate.h:173
YAML_PM::EmitterState::GetFloatPrecision
unsigned GetFloatPrecision() const
Definition: emitterstate.h:150
YAML_PM::NODE_STATE
NODE_STATE
Definition: emitterstate.h:36
YAML_PM::FMT_SCOPE
FMT_SCOPE
Definition: emitterstate.h:19
YAML_PM::ES_DONE_WITH_BLOCK_SEQ_ENTRY
@ ES_DONE_WITH_BLOCK_SEQ_ENTRY
Definition: emitterstate.h:50
YAML_PM::EmitterState::PopState
void PopState()
Definition: emitterstate.h:91
YAML_PM::ES_WAITING_FOR_DOC
@ ES_WAITING_FOR_DOC
Definition: emitterstate.h:43
YAML_PM::EmitterState::SetError
void SetError(const std::string &error)
Definition: emitterstate.h:85
YAML_PM::ES_WAITING_FOR_FLOW_MAP_ENTRY
@ ES_WAITING_FOR_FLOW_MAP_ENTRY
Definition: emitterstate.h:67
YAML_PM::EmitterState::Group::modifiedSettings
SettingChanges modifiedSettings
Definition: emitterstate.h:191
YAML_PM::EmitterState::m_mapFmt
Setting< EMITTER_MANIP > m_mapFmt
Definition: emitterstate.h:175
YAML_PM::EmitterState::Group::Group
Group(GROUP_TYPE type_)
Definition: emitterstate.h:184
YAML_PM::EmitterState::m_seqFmt
Setting< EMITTER_MANIP > m_seqFmt
Definition: emitterstate.h:174
YAML_PM::ES_DONE_WITH_DOC
@ ES_DONE_WITH_DOC
Definition: emitterstate.h:45
YAML_PM::EmitterState::SwitchState
void SwitchState(EMITTER_STATE state)
Definition: emitterstate.h:89
ptr_stack
Definition: ptr_stack.h:15
YAML_PM::ES_WAITING_FOR_BLOCK_MAP_VALUE
@ ES_WAITING_FOR_BLOCK_MAP_VALUE
Definition: emitterstate.h:62
YAML_PM::EMITTER_MANIP
EMITTER_MANIP
Definition: emittermanip.h:13
YAML_PM::EmitterState::m_doublePrecision
Setting< int > m_doublePrecision
Definition: emitterstate.h:178
YAML_PM::EmitterState::UnsetSeparation
void UnsetSeparation()
Definition: emitterstate.h:112
YAML_PM::ES_WRITING_FLOW_MAP_KEY
@ ES_WRITING_FLOW_MAP_KEY
Definition: emitterstate.h:69
YAML_PM::EmitterState::PushState
void PushState(EMITTER_STATE state)
Definition: emitterstate.h:90
YAML_PM::EmitterState::SetBoolFormat
bool SetBoolFormat(EMITTER_MANIP value, FMT_SCOPE scope)
Definition: emitterstate.cpp:155
YAML_PM::EmitterState
Definition: emitterstate.h:76
YAML_PM::ES_DONE_WITH_BLOCK_MAP_VALUE
@ ES_DONE_WITH_BLOCK_MAP_VALUE
Definition: emitterstate.h:64
YAML_PM::GT_NONE
@ GT_NONE
Definition: emitterstate.h:25
YAML_PM::EmitterState::Group::flow
EMITTER_MANIP flow
Definition: emitterstate.h:187
YAML_PM::EmitterState::StartLongKey
void StartLongKey()
Definition: emitterstate.cpp:112
YAML_PM::GT_SEQ
@ GT_SEQ
Definition: emitterstate.h:26
YAML_PM::EmitterState::EmitterState
EmitterState()
Definition: emitterstate.cpp:7
YAML_PM::LOCAL
@ LOCAL
Definition: emitterstate.h:20
YAML_PM::EmitterState::m_intFmt
Setting< EMITTER_MANIP > m_intFmt
Definition: emitterstate.h:171
YAML_PM::EmitterState::GetOutputCharset
EMITTER_MANIP GetOutputCharset() const
Definition: emitterstate.h:118
YAML_PM::EmitterState::SetDoublePrecision
bool SetDoublePrecision(int value, FMT_SCOPE scope)
Definition: emitterstate.cpp:276
YAML_PM::EmitterState::GetPreCommentIndent
int GetPreCommentIndent() const
Definition: emitterstate.h:139
YAML_PM::EmitterState::SetStringFormat
bool SetStringFormat(EMITTER_MANIP value, FMT_SCOPE scope)
Definition: emitterstate.cpp:141
YAML_PM::ES_WAITING_FOR_BLOCK_SEQ_ENTRY
@ ES_WAITING_FOR_BLOCK_SEQ_ENTRY
Definition: emitterstate.h:48
YAML_PM::EmitterState::GetBoolCaseFormat
EMITTER_MANIP GetBoolCaseFormat() const
Definition: emitterstate.h:130
YAML_PM::EmitterState::m_groups
ptr_stack< Group > m_groups
Definition: emitterstate.h:194
YAML_PM::ES_WRITING_FLOW_MAP_VALUE
@ ES_WRITING_FLOW_MAP_VALUE
Definition: emitterstate.h:72
YAML_PM::EmitterState::SetIndent
bool SetIndent(unsigned value, FMT_SCOPE scope)
Definition: emitterstate.cpp:206
YAML_PM::SettingChanges
Definition: setting.h:65
YAML_PM::EmitterState::ForceHardSeparation
void ForceHardSeparation()
Definition: emitterstate.h:111
setting.h
YAML_PM::EmitterState::GetBoolFormat
EMITTER_MANIP GetBoolFormat() const
Definition: emitterstate.h:124
YAML_PM::EmitterState::SetIntFormat
bool SetIntFormat(EMITTER_MANIP value, FMT_SCOPE scope)
Definition: emitterstate.cpp:193
YAML_PM::FT_FLOW
@ FT_FLOW
Definition: emitterstate.h:32
YAML_PM::Setting::get
const T get() const
Definition: setting.h:23
YAML_PM::EmitterState::m_isGood
bool m_isGood
Definition: emitterstate.h:160
YAML_PM::EmitterState::GetCurState
EMITTER_STATE GetCurState() const
Definition: emitterstate.h:88
YAML_PM::EmitterState::SetBoolLengthFormat
bool SetBoolLengthFormat(EMITTER_MANIP value, FMT_SCOPE scope)
Definition: emitterstate.cpp:168
YAML_PM::EmitterState::good
bool good() const
Definition: emitterstate.h:83
YAML_PM::EmitterState::BeginGroup
void BeginGroup(GROUP_TYPE type)
Definition: emitterstate.cpp:49
YAML_PM::ES_DONE_WITH_FLOW_MAP_KEY
@ ES_DONE_WITH_FLOW_MAP_KEY
Definition: emitterstate.h:70
YAML_PM::EmitterState::Group::indent
int indent
Definition: emitterstate.h:189
YAML_PM::ES_WRITING_BLOCK_MAP_VALUE
@ ES_WRITING_BLOCK_MAP_VALUE
Definition: emitterstate.h:63
ptr_stack.h
YAML_PM::Setting::set
std::auto_ptr< SettingChangeBase > set(const T &value)
Definition: setting.h:59
YAML_PM::NS_START
@ NS_START
Definition: emitterstate.h:37
YAML_PM::ES_WAITING_FOR_FLOW_MAP_KEY
@ ES_WAITING_FOR_FLOW_MAP_KEY
Definition: emitterstate.h:68
emittermanip.h


mp2p_icp
Author(s):
autogenerated on Fri Dec 20 2024 03:45:57