emitter.h
Go to the documentation of this file.
00001 #ifndef EMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
00002 #define EMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
00003 
00004 #if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
00005 #pragma once
00006 #endif
00007 
00008 
00009 #include "yaml-cpp-pm/dll.h"
00010 #include "yaml-cpp-pm/binary.h"
00011 #include "yaml-cpp-pm/emittermanip.h"
00012 #include "yaml-cpp-pm/ostream.h"
00013 #include "yaml-cpp-pm/noncopyable.h"
00014 #include "yaml-cpp-pm/null.h"
00015 #include <memory>
00016 #include <string>
00017 #include <sstream>
00018 
00019 namespace YAML_PM
00020 {
00021         class EmitterState;
00022         
00023         class YAML_CPP_API Emitter: private noncopyable
00024         {
00025         public:
00026                 Emitter();
00027                 ~Emitter();
00028                 
00029                 // output
00030                 const char *c_str() const;
00031                 unsigned size() const;
00032                 
00033                 // state checking
00034                 bool good() const;
00035                 const std::string GetLastError() const;
00036                 
00037                 // global setters
00038                 bool SetOutputCharset(EMITTER_MANIP value);
00039                 bool SetStringFormat(EMITTER_MANIP value);
00040                 bool SetBoolFormat(EMITTER_MANIP value);
00041                 bool SetIntBase(EMITTER_MANIP value);
00042                 bool SetSeqFormat(EMITTER_MANIP value);
00043                 bool SetMapFormat(EMITTER_MANIP value);
00044                 bool SetIndent(unsigned n);
00045                 bool SetPreCommentIndent(unsigned n);
00046                 bool SetPostCommentIndent(unsigned n);
00047         bool SetFloatPrecision(unsigned n);
00048         bool SetDoublePrecision(unsigned n);
00049                 
00050                 // local setters
00051                 Emitter& SetLocalValue(EMITTER_MANIP value);
00052                 Emitter& SetLocalIndent(const _Indent& indent);
00053         Emitter& SetLocalPrecision(const _Precision& precision);
00054                 
00055                 // overloads of write
00056                 Emitter& Write(const std::string& str);
00057                 Emitter& Write(bool b);
00058                 Emitter& Write(char ch);
00059                 Emitter& Write(const _Alias& alias);
00060                 Emitter& Write(const _Anchor& anchor);
00061                 Emitter& Write(const _Tag& tag);
00062                 Emitter& Write(const _Comment& comment);
00063                 Emitter& Write(const _Null& null);
00064                 Emitter& Write(const Binary& binary);
00065                 
00066                 template <typename T>
00067                 Emitter& WriteIntegralType(T value);
00068                 
00069                 template <typename T>
00070                 Emitter& WriteStreamable(T value);
00071 
00072         private:
00073                 void PreWriteIntegralType(std::stringstream& str);
00074                 void PreWriteStreamable(std::stringstream& str);
00075                 void PostWriteIntegralType(const std::stringstream& str);
00076                 void PostWriteStreamable(const std::stringstream& str);
00077         
00078         template<typename T> void SetStreamablePrecision(std::stringstream&) {}
00079         unsigned GetFloatPrecision() const;
00080         unsigned GetDoublePrecision() const;
00081         
00082         private:
00083                 void PreAtomicWrite();
00084                 bool GotoNextPreAtomicState();
00085                 void PostAtomicWrite();
00086                 void EmitSeparationIfNecessary();
00087                 
00088                 void EmitBeginDoc();
00089                 void EmitEndDoc();
00090                 void EmitBeginSeq();
00091                 void EmitEndSeq();
00092                 void EmitBeginMap();
00093                 void EmitEndMap();
00094                 void EmitKey();
00095                 void EmitValue();
00096                 void EmitNewline();
00097                 void EmitKindTag();
00098                 void EmitTag(bool verbatim, const _Tag& tag);
00099                 
00100                 const char *ComputeFullBoolName(bool b) const;
00101                 bool CanEmitNewline() const;
00102                 
00103         private:
00104                 ostream m_stream;
00105                 std::auto_ptr <EmitterState> m_pState;
00106         };
00107         
00108         template <typename T>
00109         inline Emitter& Emitter::WriteIntegralType(T value)
00110         {
00111                 if(!good())
00112                         return *this;
00113                 
00114                 std::stringstream str;
00115                 PreWriteIntegralType(str);
00116                 str << value;
00117                 PostWriteIntegralType(str);
00118                 return *this;
00119         }
00120 
00121         template <typename T>
00122         inline Emitter& Emitter::WriteStreamable(T value)
00123         {
00124                 if(!good())
00125                         return *this;
00126                 
00127                 std::stringstream str;
00128                 PreWriteStreamable(str);
00129         SetStreamablePrecision<T>(str);
00130                 str << value;
00131                 PostWriteStreamable(str);
00132                 return *this;
00133         }
00134         
00135     template<>
00136     inline void Emitter::SetStreamablePrecision<float>(std::stringstream& str)
00137     {
00138                 str.precision(GetFloatPrecision());
00139     }
00140 
00141     template<>
00142     inline void Emitter::SetStreamablePrecision<double>(std::stringstream& str)
00143     {
00144                 str.precision(GetDoublePrecision());
00145     }
00146 
00147         // overloads of insertion
00148         inline Emitter& operator << (Emitter& emitter, const std::string& v) { return emitter.Write(v); }
00149         inline Emitter& operator << (Emitter& emitter, bool v) { return emitter.Write(v); }
00150         inline Emitter& operator << (Emitter& emitter, char v) { return emitter.Write(v); }
00151         inline Emitter& operator << (Emitter& emitter, unsigned char v) { return emitter.Write(static_cast<char>(v)); }
00152         inline Emitter& operator << (Emitter& emitter, const _Alias& v) { return emitter.Write(v); }
00153         inline Emitter& operator << (Emitter& emitter, const _Anchor& v) { return emitter.Write(v); }
00154         inline Emitter& operator << (Emitter& emitter, const _Tag& v) { return emitter.Write(v); }
00155         inline Emitter& operator << (Emitter& emitter, const _Comment& v) { return emitter.Write(v); }
00156         inline Emitter& operator << (Emitter& emitter, const _Null& v) { return emitter.Write(v); }
00157         inline Emitter& operator << (Emitter& emitter, const Binary& b) { return emitter.Write(b); }
00158 
00159         inline Emitter& operator << (Emitter& emitter, const char *v) { return emitter.Write(std::string(v)); }
00160 
00161         inline Emitter& operator << (Emitter& emitter, int v) { return emitter.WriteIntegralType(v); }
00162         inline Emitter& operator << (Emitter& emitter, unsigned int v) { return emitter.WriteIntegralType(v); }
00163         inline Emitter& operator << (Emitter& emitter, short v) { return emitter.WriteIntegralType(v); }
00164         inline Emitter& operator << (Emitter& emitter, unsigned short v) { return emitter.WriteIntegralType(v); }
00165         inline Emitter& operator << (Emitter& emitter, long v) { return emitter.WriteIntegralType(v); }
00166         inline Emitter& operator << (Emitter& emitter, unsigned long v) { return emitter.WriteIntegralType(v); }
00167         inline Emitter& operator << (Emitter& emitter, long long v) { return emitter.WriteIntegralType(v); }
00168         inline Emitter& operator << (Emitter& emitter, unsigned long long v) { return emitter.WriteIntegralType(v); }
00169 
00170         inline Emitter& operator << (Emitter& emitter, float v) { return emitter.WriteStreamable(v); }
00171         inline Emitter& operator << (Emitter& emitter, double v) { return emitter.WriteStreamable(v); }
00172 
00173         inline Emitter& operator << (Emitter& emitter, EMITTER_MANIP value) {
00174                 return emitter.SetLocalValue(value);
00175         }
00176         
00177         inline Emitter& operator << (Emitter& emitter, _Indent indent) {
00178                 return emitter.SetLocalIndent(indent);
00179         }
00180     
00181     inline Emitter& operator << (Emitter& emitter, _Precision precision) {
00182         return emitter.SetLocalPrecision(precision);
00183     }
00184 }
00185 
00186 #endif // EMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM


libpointmatcher
Author(s):
autogenerated on Mon Sep 14 2015 02:59:04