emitterstate.cpp
Go to the documentation of this file.
1 #include "emitterstate.h"
3 #include <limits>
4 
5 namespace YAML_PM
6 {
7  EmitterState::EmitterState(): m_isGood(true), m_curIndent(0), m_requiresSoftSeparation(false), m_requiresHardSeparation(false)
8  {
9  // start up
11 
12  // set default global manipulators
14  m_strFmt.set(Auto);
18  m_intFmt.set(Dec);
19  m_indent.set(2);
27  }
28 
30  {
31  }
32 
33  // SetLocalValue
34  // . We blindly tries to set all possible formatters to this value
35  // . Only the ones that make sense will be accepted
37  {
38  SetOutputCharset(value, LOCAL);
39  SetStringFormat(value, LOCAL);
40  SetBoolFormat(value, LOCAL);
41  SetBoolCaseFormat(value, LOCAL);
42  SetBoolLengthFormat(value, LOCAL);
43  SetIntFormat(value, LOCAL);
44  SetFlowType(GT_SEQ, value, LOCAL);
45  SetFlowType(GT_MAP, value, LOCAL);
46  SetMapKeyFormat(value, LOCAL);
47  }
48 
50  {
51  unsigned lastIndent = (m_groups.empty() ? 0 : m_groups.top().indent);
52  m_curIndent += lastIndent;
53 
54  std::auto_ptr<Group> pGroup(new Group(type));
55 
56  // transfer settings (which last until this group is done)
57  pGroup->modifiedSettings = m_modifiedSettings;
58 
59  // set up group
60  pGroup->flow = GetFlowType(type);
61  pGroup->indent = GetIndent();
62  pGroup->usingLongKey = (GetMapKeyFormat() == LongKey ? true : false);
63 
64  m_groups.push(pGroup);
65  }
66 
68  {
69  if(m_groups.empty())
71 
72  // get rid of the current group
73  {
74  std::auto_ptr<Group> pFinishedGroup = m_groups.pop();
75  if(pFinishedGroup->type != type)
77  }
78 
79  // reset old settings
80  unsigned lastIndent = (m_groups.empty() ? 0 : m_groups.top().indent);
81  assert(m_curIndent >= lastIndent);
82  m_curIndent -= lastIndent;
83 
84  // some global settings that we changed may have been overridden
85  // by a local setting we just popped, so we need to restore them
87  }
88 
90  {
91  if(m_groups.empty())
92  return GT_NONE;
93 
94  return m_groups.top().type;
95  }
96 
98  {
99  if(m_groups.empty())
100  return FT_NONE;
101 
102  return (m_groups.top().flow == Flow ? FT_FLOW : FT_BLOCK);
103  }
104 
106  {
107  if(m_groups.empty())
108  return false;
109  return m_groups.top().usingLongKey;
110  }
111 
113  {
114  if(!m_groups.empty())
115  m_groups.top().usingLongKey = true;
116  }
117 
119  {
120  if(!m_groups.empty())
121  m_groups.top().usingLongKey = false;
122  }
123 
125  {
127  }
128 
130  {
131  switch(value) {
132  case EmitNonAscii:
133  case EscapeNonAscii:
134  _Set(m_charset, value, scope);
135  return true;
136  default:
137  return false;
138  }
139  }
140 
142  {
143  switch(value) {
144  case Auto:
145  case SingleQuoted:
146  case DoubleQuoted:
147  case Literal:
148  _Set(m_strFmt, value, scope);
149  return true;
150  default:
151  return false;
152  }
153  }
154 
156  {
157  switch(value) {
158  case OnOffBool:
159  case TrueFalseBool:
160  case YesNoBool:
161  _Set(m_boolFmt, value, scope);
162  return true;
163  default:
164  return false;
165  }
166  }
167 
169  {
170  switch(value) {
171  case LongBool:
172  case ShortBool:
173  _Set(m_boolLengthFmt, value, scope);
174  return true;
175  default:
176  return false;
177  }
178  }
179 
181  {
182  switch(value) {
183  case UpperCase:
184  case LowerCase:
185  case CamelCase:
186  _Set(m_boolCaseFmt, value, scope);
187  return true;
188  default:
189  return false;
190  }
191  }
192 
194  {
195  switch(value) {
196  case Dec:
197  case Hex:
198  case Oct:
199  _Set(m_intFmt, value, scope);
200  return true;
201  default:
202  return false;
203  }
204  }
205 
206  bool EmitterState::SetIndent(unsigned value, FMT_SCOPE scope)
207  {
208  if(value == 0)
209  return false;
210 
211  _Set(m_indent, value, scope);
212  return true;
213  }
214 
215  bool EmitterState::SetPreCommentIndent(unsigned value, FMT_SCOPE scope)
216  {
217  if(value == 0)
218  return false;
219 
220  _Set(m_preCommentIndent, value, scope);
221  return true;
222  }
223 
224  bool EmitterState::SetPostCommentIndent(unsigned value, FMT_SCOPE scope)
225  {
226  if(value == 0)
227  return false;
228 
229  _Set(m_postCommentIndent, value, scope);
230  return true;
231  }
232 
234  {
235  switch(value) {
236  case Block:
237  case Flow:
238  _Set(groupType == GT_SEQ ? m_seqFmt : m_mapFmt, value, scope);
239  return true;
240  default:
241  return false;
242  }
243  }
244 
246  {
247  // force flow style if we're currently in a flow
248  FLOW_TYPE flowType = GetCurGroupFlowType();
249  if(flowType == FT_FLOW)
250  return Flow;
251 
252  // otherwise, go with what's asked of use
253  return (groupType == GT_SEQ ? m_seqFmt.get() : m_mapFmt.get());
254  }
255 
257  {
258  switch(value) {
259  case Auto:
260  case LongKey:
261  _Set(m_mapKeyFmt, value, scope);
262  return true;
263  default:
264  return false;
265  }
266  }
267 
269  {
270  if(value < 0 || value > std::numeric_limits<float>::digits10)
271  return false;
272  _Set(m_floatPrecision, value, scope);
273  return true;
274  }
275 
277  {
278  if(value < 0 || value > std::numeric_limits<double>::digits10)
279  return false;
280  _Set(m_doublePrecision, value, scope);
281  return true;
282  }
283 }
284 
void SetLocalValue(EMITTER_MANIP value)
Setting< int > m_floatPrecision
Definition: emitterstate.h:177
void EndGroup(GROUP_TYPE type)
bool SetBoolFormat(EMITTER_MANIP value, FMT_SCOPE scope)
bool SetFlowType(GROUP_TYPE groupType, EMITTER_MANIP value, FMT_SCOPE scope)
Setting< EMITTER_MANIP > m_intFmt
Definition: emitterstate.h:171
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
void _Set(Setting< T > &fmt, T value, FMT_SCOPE scope)
Definition: emitterstate.h:201
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
bool SetStringFormat(EMITTER_MANIP value, FMT_SCOPE scope)
bool SetFloatPrecision(int value, FMT_SCOPE scope)
Setting< int > m_doublePrecision
Definition: emitterstate.h:178
bool SetBoolCaseFormat(EMITTER_MANIP value, FMT_SCOPE scope)
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
Setting< EMITTER_MANIP > m_mapFmt
Definition: emitterstate.h:175
Setting< EMITTER_MANIP > m_seqFmt
Definition: emitterstate.h:174
Setting< unsigned > m_indent
Definition: emitterstate.h:172
EMITTER_MANIP GetFlowType(GROUP_TYPE groupType) const
void BeginGroup(GROUP_TYPE type)
const char *const UNMATCHED_GROUP_TAG
Definition: exceptions.h:62
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
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)
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