#ifndef __JNET__JCONTROLHOSTOBJECTOUTPUT__ #define __JNET__JCONTROLHOSTOBJECTOUTPUT__ #include #include "JNet/JControlHost.hh" #include "JLang/JObjectOutput.hh" #include "JLang/JTypeList.hh" #include "JLang/JNullType.hh" #include "JIO/JByteArrayIO.hh" /** * \author mdejong */ namespace JNET {} namespace JPP { using namespace JNET; } namespace JNET { using JLANG::JObjectOutput; using JLANG::JTypeList; using JLANG::JNullType; using JLANG::JType; using JIO::JByteArrayWriter; /** * Implemenation of object output through ControlHost. * * Note that if the tag is not specified, it is obtained by the template method ::getTag(JLANG::JType).\n * This class implements the JLANG::JObjectOutput interface. */ template class JControlHostObjectOutput : public virtual JControlHost, public virtual JObjectOutput, public JTag { protected: /** * Constructor. */ JControlHostObjectOutput() : JControlHost(), JObjectOutput(), JTag(::getTag(JType())) {} public: /** * Constructor. * * \param server host name and optional port number */ JControlHostObjectOutput(const JHostname& server) : JControlHost(), JObjectOutput(), JTag(::getTag(JType())) { this->connect(server.hostname, server.port); } /** * Constructor. * * \param server host name and optional port number * \param tag tag */ JControlHostObjectOutput(const JHostname& server, const JTag& tag) : JControlHost(), JObjectOutput(), JTag(tag) { this->connect(server.hostname, server.port); } /** * Object output. * * \param object object * \return true if OK; else false */ virtual bool put(const T& object) override { out.clear(); out << object; return this->PutFullData(this->getTag(), out.data(), out.size()) == 0; } private: JByteArrayWriter out; }; /** * Implementation of object output for multiple data types. * * This class recursively implements the JLANG::ObjectOutput interface * for all data types by deriving from: * - JControlHostObjectOutput; and * - JControlHostObjectOutput. */ template class JControlHostObjectOutput< JTypeList > : public virtual JObjectOutput< JTypeList >, public JControlHostObjectOutput, public JControlHostObjectOutput { public: using JControlHostObjectOutput::put; using JControlHostObjectOutput::put; /** * Constructor. * * \param server host name and optional port number */ JControlHostObjectOutput(const JHostname& server) : JControlHostObjectOutput(), JControlHostObjectOutput(server) {} }; /** * Terminator class of recursive JControlHostObjectOutput class. * * This class extends class JControlHostObjectOutput.\n * The corresponding tag is obtained by the template method JNET::getTag.\n * This class actually makes the connection to the server. */ template class JControlHostObjectOutput< JTypeList > : public JControlHostObjectOutput { public: using JControlHostObjectOutput::put; /** * Constructor. * * \param server host name and optional port number */ JControlHostObjectOutput(const JHostname& server) : JControlHostObjectOutput() { this->connect(server.hostname, server.port); } }; } #endif