#ifndef __JLANG__JABSTRACTOBJECTWRITER__ #define __JLANG__JABSTRACTOBJECTWRITER__ #include "JLang/JObjectOutput.hh" #include "JLang/JTypeList.hh" #include "JLang/JNullType.hh" #include "JLang/JException.hh" /** * \author mdejong */ namespace JLANG {} namespace JPP { using namespace JLANG; } namespace JLANG { /** * Abstract interface for object writing. * * This class implements the JObjectOutput interface by transferring * the interface methods to a helper object via a single interface method getHelper(). */ template struct JAbstractObjectWriter : public virtual JObjectOutput { /** * Get helper. * * \return pointer to helper */ virtual JObjectOutput* getHelper() const = 0; /** * Object output. * * \param object object * \return true if OK; else false */ virtual bool put(const T& object) override { return (this->getHelper() != NULL && this->getHelper()->put(object)); } }; /** * Abstract interface for object writing for multiple data types. * * This class recursively implements the JLANG::JObjectOutput interface * for all data types by deriving from: * - JAbstractObjectWriter; and * - JAbstractObjectWriter. */ template struct JAbstractObjectWriter< JTypeList > : public virtual JObjectOutput< JTypeList >, public JAbstractObjectWriter, public JAbstractObjectWriter { using JAbstractObjectWriter::put; using JAbstractObjectWriter::put; }; /** * Terminator class of recursive JAbstractObjectWriter class. */ template struct JAbstractObjectWriter< JTypeList > : public JAbstractObjectWriter {}; /** * Abstract interface for object writing with named access. * * This class implements the JAccessibleObjectOutput interface by transferring * the interface methods to a helper object via a single interface method getHelper(). */ template struct JAbstractAccessibleObjectWriter : public virtual JAccessibleObjectOutput, public JAbstractObjectWriter { /** * Get helper. * * \return pointer to helper */ virtual JAccessibleObjectOutput* getHelper() const override = 0; /** * Check is device is open. * * \return true if open; else false */ virtual bool is_open() const override { if (this->getHelper() != NULL) return this->getHelper()->is_open(); else return false; } /** * Open device. * * \param file_name file name */ virtual void open(const char* file_name) override { if (this->getHelper() != NULL) { this->getHelper()->open(file_name); } } /** * Close device. */ virtual void close() override { if (this->getHelper() != NULL) { this->getHelper()->close(); } } }; } #endif