Jpp  master_rocky-40-g5f0272dcd
the software that should make you happy
JControlHostObjectOutput.hh
Go to the documentation of this file.
1 #ifndef __JNET__JCONTROLHOSTOBJECTOUTPUT__
2 #define __JNET__JCONTROLHOSTOBJECTOUTPUT__
3 
4 #include <string>
5 
6 #include "JNet/JControlHost.hh"
7 #include "JLang/JObjectOutput.hh"
8 #include "JLang/JTypeList.hh"
9 #include "JLang/JNullType.hh"
10 #include "JIO/JByteArrayIO.hh"
11 
12 
13 /**
14  * \author mdejong
15  */
16 
17 namespace JNET {}
18 namespace JPP { using namespace JNET; }
19 
20 namespace JNET {
21 
23  using JLANG::JTypeList;
24  using JLANG::JNullType;
25  using JLANG::JType;
27 
28 
29  /**
30  * Implemenation of object output through ControlHost.
31  *
32  * Note that if the tag is not specified, it is obtained by the template method ::getTag(JLANG::JType).\n
33  * This class implements the JLANG::JObjectOutput interface.
34  */
35  template<class T>
37  public virtual JControlHost,
38  public virtual JObjectOutput<T>,
39  public JTag
40  {
41  protected:
42  /**
43  * Constructor.
44  */
46  JControlHost(),
47  JObjectOutput<T>(),
48  JTag(::getTag(JType<T>()))
49  {}
50 
51 
52  public:
53  /**
54  * Constructor.
55  *
56  * \param server host name and optional port number
57  */
59  JControlHost(),
60  JObjectOutput<T>(),
61  JTag(::getTag(JType<T>()))
62  {
63  this->connect(server.hostname, server.port);
64  }
65 
66 
67  /**
68  * Constructor.
69  *
70  * \param server host name and optional port number
71  * \param tag tag
72  */
74  const JTag& tag) :
75  JControlHost(),
76  JObjectOutput<T>(),
77  JTag(tag)
78  {
79  this->connect(server.hostname, server.port);
80  }
81 
82 
83  /**
84  * Object output.
85  *
86  * \param object object
87  * \return true if OK; else false
88  */
89  virtual bool put(const T& object) override
90  {
91  out.clear();
92 
93  out << object;
94 
95  return this->PutFullData(this->getTag(), out.data(), out.size()) == 0;
96  }
97 
98  private:
100  };
101 
102 
103  /**
104  * Implementation of object output for multiple data types.
105  *
106  * This class recursively implements the JLANG::ObjectOutput interface
107  * for all data types by deriving from:
108  * - JControlHostObjectOutput<JHead_t>; and
109  * - JControlHostObjectOutput<JTail_t>.
110  */
111  template<class JHead_t, class JTail_t>
112  class JControlHostObjectOutput< JTypeList<JHead_t, JTail_t> > :
113  public virtual JObjectOutput< JTypeList<JHead_t, JTail_t> >,
114  public JControlHostObjectOutput<JHead_t>,
115  public JControlHostObjectOutput<JTail_t>
116 
117  {
118  public:
119 
122 
123 
124  /**
125  * Constructor.
126  *
127  * \param server host name and optional port number
128  */
130  JControlHostObjectOutput<JHead_t>(),
131  JControlHostObjectOutput<JTail_t>(server)
132  {}
133  };
134 
135 
136  /**
137  * Terminator class of recursive JControlHostObjectOutput class.
138  *
139  * This class extends class JControlHostObjectOutput<JHead_t>.\n
140  * The corresponding tag is obtained by the template method JNET::getTag.\n
141  * This class actually makes the connection to the server.
142  */
143  template<class JHead_t>
145  public JControlHostObjectOutput<JHead_t>
146  {
147  public:
148 
150 
151 
152  /**
153  * Constructor.
154  *
155  * \param server host name and optional port number
156  */
158  JControlHostObjectOutput<JHead_t>()
159  {
160  this->connect(server.hostname, server.port);
161  }
162  };
163 }
164 
165 #endif
Byte array binary output.
void clear()
Clear buffer.
Template interface of object output for single data type.
Implemenation of object output through ControlHost.
JControlHostObjectOutput(const JHostname &server)
Constructor.
virtual bool put(const T &object) override
Object output.
JControlHostObjectOutput(const JHostname &server, const JTag &tag)
Constructor.
ControlHost class.
int PutFullData(const JTag &tag, const void *buffer, const long long int length)
Send data.
void connect(const int port)
Connect to port on local host.
Definition: JTCPSocket.hh:166
ControlHost tag.
Definition: JTag.hh:38
const JTag & getTag() const
Get tag.
Definition: JTag.hh:86
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary class for no type definition.
Definition: JNullType.hh:19
Type list.
Definition: JTypeList.hh:23
Auxiliary class for a type holder.
Definition: JType.hh:19
Auxiliary data structure for hostname and port number.
Definition: JHostname.hh:35
std::string hostname
Definition: JHostname.hh:171