emitter.h
Go to the documentation of this file.
1 #ifndef EMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
2 #define EMITTER_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 "yaml-cpp-pm/dll.h"
10 #include "yaml-cpp-pm/binary.h"
12 #include "yaml-cpp-pm/ostream.h"
14 #include "yaml-cpp-pm/null.h"
15 #include <memory>
16 #include <string>
17 #include <sstream>
18 
19 namespace YAML_PM
20 {
21  class EmitterState;
22 
24  {
25  public:
26  Emitter();
27  ~Emitter();
28 
29  // output
30  const char *c_str() const;
31  unsigned size() const;
32 
33  // state checking
34  bool good() const;
35  const std::string GetLastError() const;
36 
37  // global setters
38  bool SetOutputCharset(EMITTER_MANIP value);
39  bool SetStringFormat(EMITTER_MANIP value);
40  bool SetBoolFormat(EMITTER_MANIP value);
41  bool SetIntBase(EMITTER_MANIP value);
42  bool SetSeqFormat(EMITTER_MANIP value);
43  bool SetMapFormat(EMITTER_MANIP value);
44  bool SetIndent(unsigned n);
45  bool SetPreCommentIndent(unsigned n);
46  bool SetPostCommentIndent(unsigned n);
47  bool SetFloatPrecision(unsigned n);
48  bool SetDoublePrecision(unsigned n);
49 
50  // local setters
51  Emitter& SetLocalValue(EMITTER_MANIP value);
52  Emitter& SetLocalIndent(const _Indent& indent);
53  Emitter& SetLocalPrecision(const _Precision& precision);
54 
55  // overloads of write
56  Emitter& Write(const std::string& str);
57  Emitter& Write(bool b);
58  Emitter& Write(char ch);
59  Emitter& Write(const _Alias& alias);
60  Emitter& Write(const _Anchor& anchor);
61  Emitter& Write(const _Tag& tag);
62  Emitter& Write(const _Comment& comment);
63  Emitter& Write(const _Null& null);
64  Emitter& Write(const Binary& binary);
65 
66  template <typename T>
67  Emitter& WriteIntegralType(T value);
68 
69  template <typename T>
70  Emitter& WriteStreamable(T value);
71 
72  private:
73  void PreWriteIntegralType(std::stringstream& str);
74  void PreWriteStreamable(std::stringstream& str);
75  void PostWriteIntegralType(const std::stringstream& str);
76  void PostWriteStreamable(const std::stringstream& str);
77 
78  template<typename T> void SetStreamablePrecision(std::stringstream&) {}
79  unsigned GetFloatPrecision() const;
80  unsigned GetDoublePrecision() const;
81 
82  private:
83  void PreAtomicWrite();
84  bool GotoNextPreAtomicState();
85  void PostAtomicWrite();
86  void EmitSeparationIfNecessary();
87 
88  void EmitBeginDoc();
89  void EmitEndDoc();
90  void EmitBeginSeq();
91  void EmitEndSeq();
92  void EmitBeginMap();
93  void EmitEndMap();
94  void EmitKey();
95  void EmitValue();
96  void EmitNewline();
97  void EmitKindTag();
98  void EmitTag(bool verbatim, const _Tag& tag);
99 
100  const char *ComputeFullBoolName(bool b) const;
101  bool CanEmitNewline() const;
102 
103  private:
105  std::auto_ptr <EmitterState> m_pState;
106  };
107 
108  template <typename T>
110  {
111  if(!good())
112  return *this;
113 
114  std::stringstream str;
116  str << value;
118  return *this;
119  }
120 
121  template <typename T>
123  {
124  if(!good())
125  return *this;
126 
127  std::stringstream str;
128  PreWriteStreamable(str);
129  SetStreamablePrecision<T>(str);
130  str << value;
131  PostWriteStreamable(str);
132  return *this;
133  }
134 
135  template<>
136  inline void Emitter::SetStreamablePrecision<float>(std::stringstream& str)
137  {
138  str.precision(GetFloatPrecision());
139  }
140 
141  template<>
142  inline void Emitter::SetStreamablePrecision<double>(std::stringstream& str)
143  {
144  str.precision(GetDoublePrecision());
145  }
146 
147  // overloads of insertion
148  inline Emitter& operator << (Emitter& emitter, const std::string& v) { return emitter.Write(v); }
149  inline Emitter& operator << (Emitter& emitter, bool v) { return emitter.Write(v); }
150  inline Emitter& operator << (Emitter& emitter, char v) { return emitter.Write(v); }
151  inline Emitter& operator << (Emitter& emitter, unsigned char v) { return emitter.Write(static_cast<char>(v)); }
152  inline Emitter& operator << (Emitter& emitter, const _Alias& v) { return emitter.Write(v); }
153  inline Emitter& operator << (Emitter& emitter, const _Anchor& v) { return emitter.Write(v); }
154  inline Emitter& operator << (Emitter& emitter, const _Tag& v) { return emitter.Write(v); }
155  inline Emitter& operator << (Emitter& emitter, const _Comment& v) { return emitter.Write(v); }
156  inline Emitter& operator << (Emitter& emitter, const _Null& v) { return emitter.Write(v); }
157  inline Emitter& operator << (Emitter& emitter, const Binary& b) { return emitter.Write(b); }
158 
159  inline Emitter& operator << (Emitter& emitter, const char *v) { return emitter.Write(std::string(v)); }
160 
161  inline Emitter& operator << (Emitter& emitter, int v) { return emitter.WriteIntegralType(v); }
162  inline Emitter& operator << (Emitter& emitter, unsigned int v) { return emitter.WriteIntegralType(v); }
163  inline Emitter& operator << (Emitter& emitter, short v) { return emitter.WriteIntegralType(v); }
164  inline Emitter& operator << (Emitter& emitter, unsigned short v) { return emitter.WriteIntegralType(v); }
165  inline Emitter& operator << (Emitter& emitter, long v) { return emitter.WriteIntegralType(v); }
166  inline Emitter& operator << (Emitter& emitter, unsigned long v) { return emitter.WriteIntegralType(v); }
167  inline Emitter& operator << (Emitter& emitter, long long v) { return emitter.WriteIntegralType(v); }
168  inline Emitter& operator << (Emitter& emitter, unsigned long long v) { return emitter.WriteIntegralType(v); }
169 
170  inline Emitter& operator << (Emitter& emitter, float v) { return emitter.WriteStreamable(v); }
171  inline Emitter& operator << (Emitter& emitter, double v) { return emitter.WriteStreamable(v); }
172 
173  inline Emitter& operator << (Emitter& emitter, EMITTER_MANIP value) {
174  return emitter.SetLocalValue(value);
175  }
176 
177  inline Emitter& operator << (Emitter& emitter, _Indent indent) {
178  return emitter.SetLocalIndent(indent);
179  }
180 
181  inline Emitter& operator << (Emitter& emitter, _Precision precision) {
182  return emitter.SetLocalPrecision(precision);
183  }
184 }
185 
186 #endif // EMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
YAML_PM::Emitter::GetFloatPrecision
unsigned GetFloatPrecision() const
Definition: emitter.cpp:691
ostream.h
YAML_PM::Emitter::SetLocalValue
Emitter & SetLocalValue(EMITTER_MANIP value)
Definition: emitter.cpp:109
YAML_PM
Definition: aliasmanager.h:11
YAML_PM::_Anchor
Definition: emittermanip.h:83
YAML_PM::Binary
Definition: binary.h:18
YAML_PM::Emitter::good
bool good() const
Definition: emitter.cpp:29
YAML_PM::Emitter::SetStreamablePrecision
void SetStreamablePrecision(std::stringstream &)
Definition: emitter.h:78
YAML_PM::Emitter::PreWriteIntegralType
void PreWriteIntegralType(std::stringstream &str)
Definition: emitter.cpp:662
YAML_PM::Emitter::PostWriteStreamable
void PostWriteStreamable(const std::stringstream &str)
Definition: emitter.cpp:707
testing::internal::string
::std::string string
Definition: gtest.h:1979
YAML_PM::_Precision
Definition: emittermanip.h:129
YAML_PM::_Indent
Definition: emittermanip.h:65
YAML_CPP_API
#define YAML_CPP_API
Definition: dll.h:25
null.h
YAML_PM::Emitter::m_pState
std::auto_ptr< EmitterState > m_pState
Definition: emitter.h:105
YAML_PM::_Tag
Definition: emittermanip.h:92
Write
Write
YAML_PM::EMITTER_MANIP
EMITTER_MANIP
Definition: emittermanip.h:13
binary.h
YAML_PM::operator<<
Emitter & operator<<(Emitter &emitter, const std::string &v)
Definition: emitter.h:148
YAML_PM::Emitter::GetDoublePrecision
unsigned GetDoublePrecision() const
Definition: emitter.cpp:696
noncopyable.h
YAML_PM::Emitter::WriteStreamable
Emitter & WriteStreamable(T value)
Definition: emitter.h:122
YAML_PM::Emitter
Definition: emitter.h:23
YAML_PM::Emitter::PreWriteStreamable
void PreWriteStreamable(std::stringstream &str)
Definition: emitter.cpp:685
YAML_PM::Emitter::m_stream
ostream m_stream
Definition: emitter.h:104
YAML_PM::ostream
Definition: ostream.h:13
YAML_PM::_Comment
Definition: emittermanip.h:120
YAML_PM::Emitter::WriteIntegralType
Emitter & WriteIntegralType(T value)
Definition: emitter.h:109
YAML_PM::Emitter::SetLocalPrecision
Emitter & SetLocalPrecision(const _Precision &precision)
Definition: emitter.cpp:158
YAML_PM::_Alias
Definition: emittermanip.h:74
YAML_PM::Emitter::PostWriteIntegralType
void PostWriteIntegralType(const std::stringstream &str)
Definition: emitter.cpp:701
dll.h
YAML_PM::Emitter::SetLocalIndent
Emitter & SetLocalIndent(const _Indent &indent)
Definition: emitter.cpp:152
YAML_PM::_Null
Definition: null.h:15
YAML_PM::noncopyable
Definition: noncopyable.h:13
emittermanip.h
YAML_PM::Emitter::Write
Emitter & Write(const std::string &str)
Definition: emitter.cpp:618


mp2p_icp
Author(s):
autogenerated on Wed Oct 23 2024 02:45:39