#ifndef __JLANG__JOBJECTOUTPUT__ #define __JLANG__JOBJECTOUTPUT__ #include "JLang/JTypeList.hh" #include "JLang/JNullType.hh" #include "JLang/JObjectIterator.hh" #include "JLang/JAccessible.hh" #include "JLang/JSingleton.hh" /** * \author mdejong */ namespace JLANG {} namespace JPP { using namespace JLANG; } namespace JLANG { /** * Template interface of object output for single data type. */ template class JObjectOutput { protected: /** * Default constructor. */ JObjectOutput() {} public: /** * Virtual destructor. */ virtual ~JObjectOutput() {} /** * Object output. * * \param object object * \return true if OK; else false */ virtual bool put(const T& object) = 0; /** * Copy from object iterator. * * \param out object output * \param in object iterator * \return object output */ friend inline JObjectOutput& operator<<(JObjectOutput & out, JObjectIterator& in) { while (in.hasNext()) { const T* p = in.next(); if (p != NULL) out.put(*p); else break; } return out; } }; /** * Implementation of object output for multiple data types. * * This class recursively defines the JObjectOutput interface * for all data types by deriving from: * - JObjectOutput; and * - JObjectOutput. */ template class JObjectOutput< JTypeList > : public virtual JObjectOutput, public virtual JObjectOutput { public: typedef JTypeList typelist; using JObjectOutput::put; using JObjectOutput::put; /** * Copy from object iterator. * * Note that all data types of the output are copied from the input. * * \param out object output * \param in object iterator * \return object output */ template friend inline JObjectOutput& operator<<(JObjectOutput& out, JInputIterator_t& in) { static_cast&>(out) << static_cast&>(in); static_cast&>(out) << in; return out; } }; /** * Terminator class of recursive JObjectOutput class. */ template class JObjectOutput< JTypeList > : public virtual JObjectOutput { public: using JObjectOutput::put; }; /** * Interface for object output with named access. */ template class JAccessibleObjectOutput : public virtual JObjectOutput, public virtual JAccessible {}; /** * Implementation of null output for single data type. */ template struct JNullOutput : public JSingleton< JNullOutput >, public virtual JObjectOutput { /** * Object output. * * \param object object * \return false */ virtual bool put(const T& object) override { return false; } }; /** * Implemenatation of null output for multiple data types. * * This class recursively implements the JLANG::JObjectOutput interface * for all data types by deriving from: * - JNullOutput; and * - JNullOutput. */ template struct JNullOutput< JTypeList > : public JSingleton< JTypeList >, public virtual JNullOutput, public virtual JNullOutput {}; /** * Terminator class of recursive JNullOutput class. */ template struct JNullOutput< JTypeList > : public virtual JNullOutput {}; /** * Implementation for null output with null access. */ template struct JNullAccessibleOutput : public virtual JAccessibleObjectOutput, public virtual JNullOutput, public virtual JNullAccess {}; } #endif