#ifndef __JROOT__JSTREAMOBJECTOUTPUT__ #define __JROOT__JSTREAMOBJECTOUTPUT__ #include #include "JLang/JObjectOutput.hh" #include "JLang/JTypeList.hh" #include "JLang/JNullType.hh" #include "JROOT/JRootStreamer.hh" /** * \author mdejong */ namespace JROOT {} namespace JPP { using namespace JROOT; } namespace JROOT { using JLANG::JObjectOutput; using JLANG::JTypeList; using JLANG::JNullType; /** * Template implementation of stream output for single data type based on ROOT dictionary. * * This class implements the JLANG::JObjectOutput interface. */ template class JRootStreamObjectOutput : public virtual JObjectOutput { public: /** * Constructor. * * \param out output stream * \param sep token separator */ JRootStreamObjectOutput(JRootWriter& 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.putObject(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: JRootWriter& __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: * - JRootStreamObjectOutput; and * - JRootStreamObjectOutput. */ template class JRootStreamObjectOutput< JTypeList > : public virtual JObjectOutput< JTypeList >, public JRootStreamObjectOutput, public JRootStreamObjectOutput { public: using JRootStreamObjectOutput::put; using JRootStreamObjectOutput::put; /** * Constructor. * * \param out output stream * \param sep token separator */ JRootStreamObjectOutput(JRootWriter& out, const std::string& sep = "") : JRootStreamObjectOutput(out, sep), JRootStreamObjectOutput(out, sep) {} /** * Set token separator. * * \param sep separator */ void setSeparator(const std::string& sep) { JRootStreamObjectOutput::setSeparator(sep); JRootStreamObjectOutput::setSeparator(sep); } }; /** * Terminator class of recursive JRootStreamObjectOutput class. */ template class JRootStreamObjectOutput< JTypeList > : public JRootStreamObjectOutput { public: using JRootStreamObjectOutput::put; /** * Constructor. * * \param out output stream * \param sep token separator */ JRootStreamObjectOutput(JRootWriter& out, const std::string& sep = "") : JRootStreamObjectOutput(out, sep) {} }; } #endif