#ifndef __JLANG__JSTREAMOBJECTOUTPUT__ #define __JLANG__JSTREAMOBJECTOUTPUT__ #include #include #include "JLang/JObjectOutput.hh" #include "JLang/JTypeList.hh" #include "JLang/JNullType.hh" /** * \author mdejong */ namespace JLANG {} namespace JPP { using namespace JLANG; } namespace JLANG { /** * Template implementation of stream output for single data type. * * This class implements the JLANG::JObjectOutput interface. */ template class JStreamObjectOutput : public virtual JObjectOutput { public: /** * Constructor. * * \param out output stream * \param sep token separator */ JStreamObjectOutput(std::ostream& out, const std::string& sep = "") : __out(out), __sep(sep) {} /** * Object output. * * \param object object * \return true if OK; else false */ virtual bool put(const T& object) override { __out << object << __sep; return (bool) __out; } /** * Get token separator. * * \return separator */ const std::string& getSeparator() const { return this->__sep; } /** * Set token separator. * * \param sep separator */ void setSeparator(const std::string& sep) { this->__sep = sep; } private: std::ostream& __out; std::string __sep; }; /** * Template specialisationimplementation of stream object output for multiple data types. * * This class recursively implements the JLANG::JObjectOutput interface * for all data types by deriving from: * - JStreamObjectOutput; and * - JStreamObjectOutput. */ template class JStreamObjectOutput< JTypeList > : public virtual JObjectOutput< JTypeList >, public JStreamObjectOutput, public JStreamObjectOutput { public: using JStreamObjectOutput::put; using JStreamObjectOutput::put; /** * Constructor. * * \param out output stream * \param sep token separator */ JStreamObjectOutput(std::ostream& out, const std::string& sep = "") : JStreamObjectOutput(out, sep), JStreamObjectOutput(out, sep) {} /** * Set token separator. * * \param sep separator */ void setSeparator(const std::string& sep) { JStreamObjectOutput::setSeparator(sep); JStreamObjectOutput::setSeparator(sep); } }; /** * Terminator class of recursive JStreamObjectOutput class. */ template class JStreamObjectOutput< JTypeList > : public JStreamObjectOutput { public: using JStreamObjectOutput::put; /** * Constructor. * * \param out output stream * \param sep token separator */ JStreamObjectOutput(std::ostream& out, const std::string& sep = "") : JStreamObjectOutput(out, sep) {} }; } #endif