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;
115  PreWriteIntegralType(str);
116  str << value;
117  PostWriteIntegralType(str);
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
ostream m_stream
Definition: emitter.h:104
Emitter & SetLocalPrecision(const _Precision &precision)
Definition: emitter.cpp:158
Emitter & WriteStreamable(T value)
Definition: emitter.h:122
Emitter & SetLocalIndent(const _Indent &indent)
Definition: emitter.cpp:152
::std::string string
Definition: gtest.h:1979
Emitter & Write(const std::string &str)
Definition: emitter.cpp:618
#define YAML_CPP_API
Definition: dll.h:25
Emitter & operator<<(Emitter &emitter, const std::string &v)
Definition: emitter.h:148
int Write(int fd, const void *buf, unsigned int count)
Definition: gtest.h:2893
void SetStreamablePrecision(std::stringstream &)
Definition: emitter.h:78
Emitter & WriteIntegralType(T value)
Definition: emitter.h:109
Emitter & SetLocalValue(EMITTER_MANIP value)
Definition: emitter.cpp:109
std::auto_ptr< EmitterState > m_pState
Definition: emitter.h:105


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