Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/yaml-cpp/emitter.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 #ifndef EMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
0002 #define EMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
0003 
0004 #if defined(_MSC_VER) ||                                            \
0005     (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
0006      (__GNUC__ >= 4))  // GCC supports "pragma once" correctly since 3.4
0007 #pragma once
0008 #endif
0009 
0010 #include <cmath>
0011 #include <cstddef>
0012 #include <limits>
0013 #include <memory>
0014 #include <sstream>
0015 #include <string>
0016 #include <type_traits>
0017 
0018 #include "yaml-cpp/binary.h"
0019 #include "yaml-cpp/dll.h"
0020 #include "yaml-cpp/emitterdef.h"
0021 #include "yaml-cpp/emittermanip.h"
0022 #include "yaml-cpp/null.h"
0023 #include "yaml-cpp/ostream_wrapper.h"
0024 
0025 namespace YAML {
0026 class Binary;
0027 struct _Null;
0028 }  // namespace YAML
0029 
0030 namespace YAML {
0031 class EmitterState;
0032 
0033 class YAML_CPP_API Emitter {
0034  public:
0035   Emitter();
0036   explicit Emitter(std::ostream& stream);
0037   Emitter(const Emitter&) = delete;
0038   Emitter& operator=(const Emitter&) = delete;
0039   ~Emitter();
0040 
0041   // output
0042   const char* c_str() const;
0043   std::size_t size() const;
0044 
0045   // state checking
0046   bool good() const;
0047   const std::string GetLastError() const;
0048 
0049   // global setters
0050   bool SetOutputCharset(EMITTER_MANIP value);
0051   bool SetStringFormat(EMITTER_MANIP value);
0052   bool SetBoolFormat(EMITTER_MANIP value);
0053   bool SetNullFormat(EMITTER_MANIP value);
0054   bool SetIntBase(EMITTER_MANIP value);
0055   bool SetSeqFormat(EMITTER_MANIP value);
0056   bool SetMapFormat(EMITTER_MANIP value);
0057   bool SetIndent(std::size_t n);
0058   bool SetPreCommentIndent(std::size_t n);
0059   bool SetPostCommentIndent(std::size_t n);
0060   bool SetFloatPrecision(std::size_t n);
0061   bool SetDoublePrecision(std::size_t n);
0062   void RestoreGlobalModifiedSettings();
0063 
0064   // local setters
0065   Emitter& SetLocalValue(EMITTER_MANIP value);
0066   Emitter& SetLocalIndent(const _Indent& indent);
0067   Emitter& SetLocalPrecision(const _Precision& precision);
0068 
0069   // overloads of write
0070   Emitter& Write(const std::string& str);
0071   Emitter& Write(bool b);
0072   Emitter& Write(char ch);
0073   Emitter& Write(const _Alias& alias);
0074   Emitter& Write(const _Anchor& anchor);
0075   Emitter& Write(const _Tag& tag);
0076   Emitter& Write(const _Comment& comment);
0077   Emitter& Write(const _Null& n);
0078   Emitter& Write(const Binary& binary);
0079 
0080   template <typename T>
0081   Emitter& WriteIntegralType(T value);
0082 
0083   template <typename T>
0084   Emitter& WriteStreamable(T value);
0085 
0086  private:
0087   template <typename T>
0088   void SetStreamablePrecision(std::stringstream&) {}
0089   std::size_t GetFloatPrecision() const;
0090   std::size_t GetDoublePrecision() const;
0091 
0092   void PrepareIntegralStream(std::stringstream& stream) const;
0093   void StartedScalar();
0094 
0095  private:
0096   void EmitBeginDoc();
0097   void EmitEndDoc();
0098   void EmitBeginSeq();
0099   void EmitEndSeq();
0100   void EmitBeginMap();
0101   void EmitEndMap();
0102   void EmitNewline();
0103   void EmitKindTag();
0104   void EmitTag(bool verbatim, const _Tag& tag);
0105 
0106   void PrepareNode(EmitterNodeType::value child);
0107   void PrepareTopNode(EmitterNodeType::value child);
0108   void FlowSeqPrepareNode(EmitterNodeType::value child);
0109   void BlockSeqPrepareNode(EmitterNodeType::value child);
0110 
0111   void FlowMapPrepareNode(EmitterNodeType::value child);
0112 
0113   void FlowMapPrepareLongKey(EmitterNodeType::value child);
0114   void FlowMapPrepareLongKeyValue(EmitterNodeType::value child);
0115   void FlowMapPrepareSimpleKey(EmitterNodeType::value child);
0116   void FlowMapPrepareSimpleKeyValue(EmitterNodeType::value child);
0117 
0118   void BlockMapPrepareNode(EmitterNodeType::value child);
0119 
0120   void BlockMapPrepareLongKey(EmitterNodeType::value child);
0121   void BlockMapPrepareLongKeyValue(EmitterNodeType::value child);
0122   void BlockMapPrepareSimpleKey(EmitterNodeType::value child);
0123   void BlockMapPrepareSimpleKeyValue(EmitterNodeType::value child);
0124 
0125   void SpaceOrIndentTo(bool requireSpace, std::size_t indent);
0126 
0127   const char* ComputeFullBoolName(bool b) const;
0128   const char* ComputeNullName() const;
0129   bool CanEmitNewline() const;
0130 
0131  private:
0132   std::unique_ptr<EmitterState> m_pState;
0133   ostream_wrapper m_stream;
0134 };
0135 
0136 template <typename T>
0137 inline Emitter& Emitter::WriteIntegralType(T value) {
0138   if (!good())
0139     return *this;
0140 
0141   PrepareNode(EmitterNodeType::Scalar);
0142 
0143   std::stringstream stream;
0144   PrepareIntegralStream(stream);
0145   stream << value;
0146   m_stream << stream.str();
0147 
0148   StartedScalar();
0149 
0150   return *this;
0151 }
0152 
0153 template <typename T>
0154 inline Emitter& Emitter::WriteStreamable(T value) {
0155   if (!good())
0156     return *this;
0157 
0158   PrepareNode(EmitterNodeType::Scalar);
0159 
0160   std::stringstream stream;
0161   SetStreamablePrecision<T>(stream);
0162 
0163   bool special = false;
0164   if (std::is_floating_point<T>::value) {
0165     if ((std::numeric_limits<T>::has_quiet_NaN ||
0166          std::numeric_limits<T>::has_signaling_NaN) &&
0167         std::isnan(value)) {
0168       special = true;
0169       stream << ".nan";
0170     } else if (std::numeric_limits<T>::has_infinity && std::isinf(value)) {
0171       special = true;
0172       if (std::signbit(value)) {
0173         stream << "-.inf";
0174       } else {
0175         stream << ".inf";
0176       }
0177     }
0178   }
0179 
0180   if (!special) {
0181     stream << value;
0182   }
0183   m_stream << stream.str();
0184 
0185   StartedScalar();
0186 
0187   return *this;
0188 }
0189 
0190 template <>
0191 inline void Emitter::SetStreamablePrecision<float>(std::stringstream& stream) {
0192   stream.precision(static_cast<std::streamsize>(GetFloatPrecision()));
0193 }
0194 
0195 template <>
0196 inline void Emitter::SetStreamablePrecision<double>(std::stringstream& stream) {
0197   stream.precision(static_cast<std::streamsize>(GetDoublePrecision()));
0198 }
0199 
0200 // overloads of insertion
0201 inline Emitter& operator<<(Emitter& emitter, const std::string& v) {
0202   return emitter.Write(v);
0203 }
0204 inline Emitter& operator<<(Emitter& emitter, bool v) {
0205   return emitter.Write(v);
0206 }
0207 inline Emitter& operator<<(Emitter& emitter, char v) {
0208   return emitter.Write(v);
0209 }
0210 inline Emitter& operator<<(Emitter& emitter, unsigned char v) {
0211   return emitter.Write(static_cast<char>(v));
0212 }
0213 inline Emitter& operator<<(Emitter& emitter, const _Alias& v) {
0214   return emitter.Write(v);
0215 }
0216 inline Emitter& operator<<(Emitter& emitter, const _Anchor& v) {
0217   return emitter.Write(v);
0218 }
0219 inline Emitter& operator<<(Emitter& emitter, const _Tag& v) {
0220   return emitter.Write(v);
0221 }
0222 inline Emitter& operator<<(Emitter& emitter, const _Comment& v) {
0223   return emitter.Write(v);
0224 }
0225 inline Emitter& operator<<(Emitter& emitter, const _Null& v) {
0226   return emitter.Write(v);
0227 }
0228 inline Emitter& operator<<(Emitter& emitter, const Binary& b) {
0229   return emitter.Write(b);
0230 }
0231 
0232 inline Emitter& operator<<(Emitter& emitter, const char* v) {
0233   return emitter.Write(std::string(v));
0234 }
0235 
0236 inline Emitter& operator<<(Emitter& emitter, int v) {
0237   return emitter.WriteIntegralType(v);
0238 }
0239 inline Emitter& operator<<(Emitter& emitter, unsigned int v) {
0240   return emitter.WriteIntegralType(v);
0241 }
0242 inline Emitter& operator<<(Emitter& emitter, short v) {
0243   return emitter.WriteIntegralType(v);
0244 }
0245 inline Emitter& operator<<(Emitter& emitter, unsigned short v) {
0246   return emitter.WriteIntegralType(v);
0247 }
0248 inline Emitter& operator<<(Emitter& emitter, long v) {
0249   return emitter.WriteIntegralType(v);
0250 }
0251 inline Emitter& operator<<(Emitter& emitter, unsigned long v) {
0252   return emitter.WriteIntegralType(v);
0253 }
0254 inline Emitter& operator<<(Emitter& emitter, long long v) {
0255   return emitter.WriteIntegralType(v);
0256 }
0257 inline Emitter& operator<<(Emitter& emitter, unsigned long long v) {
0258   return emitter.WriteIntegralType(v);
0259 }
0260 
0261 inline Emitter& operator<<(Emitter& emitter, float v) {
0262   return emitter.WriteStreamable(v);
0263 }
0264 inline Emitter& operator<<(Emitter& emitter, double v) {
0265   return emitter.WriteStreamable(v);
0266 }
0267 
0268 inline Emitter& operator<<(Emitter& emitter, EMITTER_MANIP value) {
0269   return emitter.SetLocalValue(value);
0270 }
0271 
0272 inline Emitter& operator<<(Emitter& emitter, _Indent indent) {
0273   return emitter.SetLocalIndent(indent);
0274 }
0275 
0276 inline Emitter& operator<<(Emitter& emitter, _Precision precision) {
0277   return emitter.SetLocalPrecision(precision);
0278 }
0279 }  // namespace YAML
0280 
0281 #endif  // EMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66