1 #ifndef EMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
2 #define EMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
4 #if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
9 #include "yaml-cpp/dll.h"
10 #include "yaml-cpp/binary.h"
11 #include "yaml-cpp/emittermanip.h"
12 #include "yaml-cpp/ostream.h"
13 #include "yaml-cpp/noncopyable.h"
14 #include "yaml-cpp/null.h"
23 class YAML_CPP_API Emitter
: private noncopyable
30 const char *c_str() const;
31 unsigned size() const;
35 const std::string
GetLastError() const;
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
);
51 Emitter
& SetLocalValue(EMITTER_MANIP value
);
52 Emitter
& SetLocalIndent(const _Indent
& indent
);
53 Emitter
& SetLocalPrecision(const _Precision
& precision
);
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
);
67 Emitter
& WriteIntegralType(T value
);
70 Emitter
& WriteStreamable(T value
);
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
);
78 template<typename T
> void SetStreamablePrecision(std::stringstream
&) {}
79 unsigned GetFloatPrecision() const;
80 unsigned GetDoublePrecision() const;
83 void PreAtomicWrite();
84 bool GotoNextPreAtomicState();
85 void PostAtomicWrite();
86 void EmitSeparationIfNecessary();
98 void EmitTag(bool verbatim
, const _Tag
& tag
);
100 const char *ComputeFullBoolName(bool b
) const;
101 bool CanEmitNewline() const;
105 std::auto_ptr
<EmitterState
> m_pState
;
108 template <typename T
>
109 inline Emitter
& Emitter::WriteIntegralType(T value
)
114 std::stringstream str
;
115 PreWriteIntegralType(str
);
117 PostWriteIntegralType(str
);
121 template <typename T
>
122 inline Emitter
& Emitter::WriteStreamable(T value
)
127 std::stringstream str
;
128 PreWriteStreamable(str
);
129 SetStreamablePrecision
<T
>(str
);
131 PostWriteStreamable(str
);
136 inline void Emitter::SetStreamablePrecision
<float>(std::stringstream
& str
)
138 str
.precision(GetFloatPrecision());
142 inline void Emitter::SetStreamablePrecision
<double>(std::stringstream
& str
)
144 str
.precision(GetDoublePrecision());
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
); }
159 inline Emitter
& operator << (Emitter
& emitter
, const char *v
) { return emitter
.Write(std::string(v
)); }
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
); }
170 inline Emitter
& operator << (Emitter
& emitter
, float v
) { return emitter
.WriteStreamable(v
); }
171 inline Emitter
& operator << (Emitter
& emitter
, double v
) { return emitter
.WriteStreamable(v
); }
173 inline Emitter
& operator << (Emitter
& emitter
, EMITTER_MANIP value
) {
174 return emitter
.SetLocalValue(value
);
177 inline Emitter
& operator << (Emitter
& emitter
, _Indent indent
) {
178 return emitter
.SetLocalIndent(indent
);
181 inline Emitter
& operator << (Emitter
& emitter
, _Precision precision
) {
182 return emitter
.SetLocalPrecision(precision
);
186 #endif // EMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66