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 
YAML_PM::GROUP_TYPE
GROUP_TYPE
Definition: emitterstate.h:24
YAML_PM::Oct
@ Oct
Definition: emittermanip.h:42
YAML_PM::ErrorMsg::UNMATCHED_GROUP_TAG
const char *const UNMATCHED_GROUP_TAG
Definition: exceptions.h:62
YAML_PM::EmitterState::GetMapKeyFormat
EMITTER_MANIP GetMapKeyFormat() const
Definition: emitterstate.h:147
YAML_PM::Literal
@ Literal
Definition: emittermanip.h:27
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
exceptions.h
YAML_PM::EmitterState::m_indent
Setting< unsigned > m_indent
Definition: emitterstate.h:172
YAML_PM::EmitterState::SetMapKeyFormat
bool SetMapKeyFormat(EMITTER_MANIP value, FMT_SCOPE scope)
Definition: emitterstate.cpp:256
YAML_PM
Definition: aliasmanager.h:11
YAML_PM::EmitterState::m_postCommentIndent
Setting< unsigned > m_postCommentIndent
Definition: emitterstate.h:173
YAML_PM::CamelCase
@ CamelCase
Definition: emittermanip.h:35
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::ShortBool
@ ShortBool
Definition: emittermanip.h:37
YAML_PM::LongKey
@ LongKey
Definition: emittermanip.h:62
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::EndGroup
void EndGroup(GROUP_TYPE type)
Definition: emitterstate.cpp:67
YAML_PM::EmitterState::GetIndent
int GetIndent() const
Definition: emitterstate.h:136
YAML_PM::EmitterState::SetPostCommentIndent
bool SetPostCommentIndent(unsigned value, FMT_SCOPE scope)
Definition: emitterstate.cpp:224
YAML_PM::EmitterState::GetCurGroupType
GROUP_TYPE GetCurGroupType() const
Definition: emitterstate.cpp:89
YAML_PM::EmitterState::SetFlowType
bool SetFlowType(GROUP_TYPE groupType, EMITTER_MANIP value, FMT_SCOPE scope)
Definition: emitterstate.cpp:233
YAML_PM::DoubleQuoted
@ DoubleQuoted
Definition: emittermanip.h:26
YAML_PM::FLOW_TYPE
FLOW_TYPE
Definition: emitterstate.h:30
YAML_PM::Flow
@ Flow
Definition: emittermanip.h:51
YAML_PM::EmitterState::m_stateStack
std::stack< EMITTER_STATE > m_stateStack
Definition: emitterstate.h:164
YAML_PM::SettingChanges::restore
void restore()
Definition: setting.h:79
YAML_PM::EmitterState::SetPreCommentIndent
bool SetPreCommentIndent(unsigned value, FMT_SCOPE scope)
Definition: emitterstate.cpp:215
YAML_PM::EmitterState::m_globalModifiedSettings
SettingChanges m_globalModifiedSettings
Definition: emitterstate.h:181
YAML_PM::EmitterState::~EmitterState
~EmitterState()
Definition: emitterstate.cpp:29
YAML_PM::Hex
@ Hex
Definition: emittermanip.h:41
YAML_PM::EmitterState::m_boolLengthFmt
Setting< EMITTER_MANIP > m_boolLengthFmt
Definition: emitterstate.h:169
YAML_PM::Block
@ Block
Definition: emittermanip.h:52
YAML_PM::EmitterState::m_boolCaseFmt
Setting< EMITTER_MANIP > m_boolCaseFmt
Definition: emitterstate.h:170
YAML_PM::EmitterState::m_charset
Setting< EMITTER_MANIP > m_charset
Definition: emitterstate.h:166
YAML_PM::TrueFalseBool
@ TrueFalseBool
Definition: emittermanip.h:31
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::EmitterState::SetFloatPrecision
bool SetFloatPrecision(int value, FMT_SCOPE scope)
Definition: emitterstate.cpp:268
YAML_PM::GT_MAP
@ GT_MAP
Definition: emitterstate.h:27
YAML_PM::UpperCase
@ UpperCase
Definition: emittermanip.h:33
YAML_PM::SingleQuoted
@ SingleQuoted
Definition: emittermanip.h:25
YAML_PM::EmitterState::ClearModifiedSettings
void ClearModifiedSettings()
Definition: emitterstate.cpp:124
YAML_PM::OnOffBool
@ OnOffBool
Definition: emittermanip.h:32
YAML_PM::EmitterState::m_floatPrecision
Setting< int > m_floatPrecision
Definition: emitterstate.h:177
emitterstate.h
YAML_PM::Auto
@ Auto
Definition: emittermanip.h:15
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::FMT_SCOPE
FMT_SCOPE
Definition: emitterstate.h:19
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::Dec
@ Dec
Definition: emittermanip.h:40
YAML_PM::EmitterState::m_mapFmt
Setting< EMITTER_MANIP > m_mapFmt
Definition: emitterstate.h:175
YAML_PM::EmitterState::m_seqFmt
Setting< EMITTER_MANIP > m_seqFmt
Definition: emitterstate.h:174
YAML_PM::YesNoBool
@ YesNoBool
Definition: emittermanip.h:30
YAML_PM::EmitNonAscii
@ EmitNonAscii
Definition: emittermanip.h:20
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::SetBoolFormat
bool SetBoolFormat(EMITTER_MANIP value, FMT_SCOPE scope)
Definition: emitterstate.cpp:155
YAML_PM::GT_NONE
@ GT_NONE
Definition: emitterstate.h:25
YAML_PM::EscapeNonAscii
@ EscapeNonAscii
Definition: emittermanip.h:21
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::LongBool
@ LongBool
Definition: emittermanip.h:36
YAML_PM::EmitterState::SetDoublePrecision
bool SetDoublePrecision(int value, FMT_SCOPE scope)
Definition: emitterstate.cpp:276
YAML_PM::EmitterState::SetStringFormat
bool SetStringFormat(EMITTER_MANIP value, FMT_SCOPE scope)
Definition: emitterstate.cpp:141
YAML_PM::EmitterState::m_groups
ptr_stack< Group > m_groups
Definition: emitterstate.h:194
YAML_PM::EmitterState::SetIndent
bool SetIndent(unsigned value, FMT_SCOPE scope)
Definition: emitterstate.cpp:206
YAML_PM::SettingChanges::clear
void clear()
Definition: setting.h:71
YAML_PM::LowerCase
@ LowerCase
Definition: emittermanip.h:34
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::SetBoolLengthFormat
bool SetBoolLengthFormat(EMITTER_MANIP value, FMT_SCOPE scope)
Definition: emitterstate.cpp:168
YAML_PM::EmitterState::BeginGroup
void BeginGroup(GROUP_TYPE type)
Definition: emitterstate.cpp:49
YAML_PM::Setting::set
std::auto_ptr< SettingChangeBase > set(const T &value)
Definition: setting.h:59


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