Jpp 20.0.0-rc.8
the software that should make you happy
Loading...
Searching...
No Matches
JSerialisable.hh
Go to the documentation of this file.
1#ifndef __JIO__JSERIALISABLE__
2#define __JIO__JSERIALISABLE__
3
4#include "JLang/JBinaryIO.hh"
5#include "JLang/JObjectID.hh"
6#include "JLang/JStatus.hh"
8
9
10/**
11 * \author mdejong
12 */
13
14/**
15 * Auxiliary classes and methods for binary I/O.
16 */
17namespace JIO {}
18namespace JPP { using namespace JIO; }
19
20namespace JIO {
21
25
26 class JReader; //!< Forward declaration of binary input.
27 class JWriter; //!< Forward declaration of binary output.
28
29
30 /**
31 * Interface class for a data structure with binary I/O.
32 */
34 public:
35 /**
36 * Virtual destructor.
37 */
39 {}
40
41
42 /**
43 * Read from input.
44 *
45 * \param in JReader
46 * \return JReader
47 */
48 virtual JReader& read(JReader& in) = 0;
49
50
51 /**
52 * Write to output.
53 *
54 * \param out JWriter
55 * \return JWriter
56 */
57 virtual JWriter& write(JWriter& out) const = 0;
58 };
59
60
61 /**
62 * Interface for binary input.
63 */
64 class JReader :
67 {
68 public:
69 /**
70 * Clear status of reader.
71 */
72 virtual void clear()
73 {}
74
75
76 /**
77 * Read serialisable data object.
78 *
79 * \param object serialisable data object
80 * \return JReader
81 */
83 {
84 return object.read(*this);
85 }
86
87
88 JReader& operator>>(bool& value) { read((char*) &value, sizeof(bool)); return *this; }
89 JReader& operator>>(char& value) { read((char*) &value, sizeof(char)); return *this; }
90 JReader& operator>>(unsigned char& value) { read((char*) &value, sizeof(unsigned char)); return *this; }
91 JReader& operator>>(short& value) { read((char*) &value, sizeof(short)); return *this; }
92 JReader& operator>>(unsigned short& value) { read((char*) &value, sizeof(unsigned short)); return *this; }
93 JReader& operator>>(int& value) { read((char*) &value, sizeof(int)); return *this; }
94 JReader& operator>>(unsigned int& value) { read((char*) &value, sizeof(unsigned int)); return *this; }
95 JReader& operator>>(long int& value) { read((char*) &value, sizeof(long int)); return *this; }
96 JReader& operator>>(unsigned long int& value) { read((char*) &value, sizeof(unsigned long int)); return *this; }
97 JReader& operator>>(long long int& value) { read((char*) &value, sizeof(long long int)); return *this; }
98 JReader& operator>>(unsigned long long int& value) { read((char*) &value, sizeof(unsigned long long int)); return *this; }
99 JReader& operator>>(float& value) { read((char*) &value, sizeof(float)); return *this; }
100 JReader& operator>>(double& value) { read((char*) &value, sizeof(double)); return *this; }
101 JReader& operator>>(long double& value) { read((char*) &value, sizeof(long double)); return *this; }
102 JReader& operator>>(JLANG::JObjectID& value) { return (*this) >> value.getID(); }
104
105
106 /**
107 * Read object.
108 *
109 * \param object object
110 * \return this reader
111 */
112 inline JReader& load(JSerialisable& object)
113 {
114 return object.read(*this);
115 }
116
117
118 /**
119 * Read object.
120 *
121 * \param object object
122 * \return this reader
123 */
124 template<class T>
125 inline JReader& load(T& object)
126 {
127 return *this >> object;
128 }
129 };
130
131
132 /**
133 * Interface for binary output.
134 */
135 class JWriter :
138 {
139 public:
140 /**
141 * Write serialisable data object.
142 *
143 * \param object serialisable data object
144 * \return JWriter
145 */
147 {
148 return object.write(*this);
149 }
150
151
152 JWriter& operator<<(const bool value) { write((const char*) &value, sizeof(bool)); return *this; }
153 JWriter& operator<<(const char value) { write((const char*) &value, sizeof(char)); return *this; }
154 JWriter& operator<<(const unsigned char value) { write((const char*) &value, sizeof(unsigned char)); return *this; }
155 JWriter& operator<<(const short value) { write((const char*) &value, sizeof(short)); return *this; }
156 JWriter& operator<<(const unsigned short value) { write((const char*) &value, sizeof(unsigned short)); return *this; }
157 JWriter& operator<<(const int value) { write((const char*) &value, sizeof(int)); return *this; }
158 JWriter& operator<<(const unsigned int value) { write((const char*) &value, sizeof(unsigned int)); return *this; }
159 JWriter& operator<<(const long int value) { write((const char*) &value, sizeof(long int)); return *this; }
160 JWriter& operator<<(const unsigned long int value) { write((const char*) &value, sizeof(unsigned long int)); return *this; }
161 JWriter& operator<<(const long long int value) { write((const char*) &value, sizeof(long long int)); return *this; }
162 JWriter& operator<<(const unsigned long long int value) { write((const char*) &value, sizeof(unsigned long long int)); return *this; }
163 JWriter& operator<<(const float value) { write((const char*) &value, sizeof(float)); return *this; }
164 JWriter& operator<<(const double value) { write((const char*) &value, sizeof(double)); return *this; }
165 JWriter& operator<<(const long double value) { write((const char*) &value, sizeof(long double)); return *this; }
166 JWriter& operator<<(const JLANG::JObjectID& value) { return (*this) << value.getID(); }
167 JWriter& operator<<(const JLANG::JStatus& value) { return (*this) << value.getStatus<JLANG::JStatus::status_type>(); }
168
169
170 /**
171 * Write object.
172 *
173 * \param object object
174 * \return this writer
175 */
176 inline JWriter& store(const JSerialisable& object)
177 {
178 return object.write(*this);
179 }
180
181
182 /**
183 * Write object.
184 *
185 * \param object object
186 * \return this writer
187 */
188 template<class T>
189 inline JWriter& store(const T& object)
190 {
191 return *this << object;
192 }
193 };
194}
195
196#endif
Interface for binary input.
JReader & operator>>(unsigned long long int &value)
JReader & operator>>(bool &value)
JReader & operator>>(JLANG::JObjectID &value)
JReader & operator>>(JSerialisable &object)
Read serialisable data object.
JReader & operator>>(float &value)
JReader & operator>>(short &value)
JReader & operator>>(unsigned short &value)
JReader & operator>>(int &value)
JReader & operator>>(long int &value)
JReader & load(JSerialisable &object)
Read object.
JReader & operator>>(JLANG::JStatus &value)
JReader & load(T &object)
Read object.
virtual void clear()
Clear status of reader.
JReader & operator>>(double &value)
JReader & operator>>(char &value)
JReader & operator>>(unsigned long int &value)
JReader & operator>>(unsigned char &value)
JReader & operator>>(long double &value)
JReader & operator>>(unsigned int &value)
JReader & operator>>(long long int &value)
Forward declaration of binary output.
virtual ~JSerialisable()
Virtual destructor.
virtual JWriter & write(JWriter &out) const =0
Write to output.
virtual JReader & read(JReader &in)=0
Read from input.
Interface for binary output.
JWriter & operator<<(const double value)
JWriter & operator<<(const float value)
JWriter & operator<<(const bool value)
JWriter & operator<<(const long long int value)
JWriter & operator<<(const unsigned short value)
JWriter & operator<<(const unsigned int value)
JWriter & operator<<(const unsigned long long int value)
JWriter & operator<<(const int value)
JWriter & operator<<(const short value)
JWriter & operator<<(const JLANG::JObjectID &value)
JWriter & operator<<(const JSerialisable &object)
Write serialisable data object.
JWriter & operator<<(const char value)
JWriter & operator<<(const long int value)
JWriter & operator<<(const long double value)
JWriter & operator<<(const unsigned long int value)
JWriter & operator<<(const JLANG::JStatus &value)
JWriter & store(const T &object)
Write object.
JWriter & store(const JSerialisable &object)
Write object.
JWriter & operator<<(const unsigned char value)
Interface for binary input.
Definition JBinaryIO.hh:18
virtual int read(char *buffer, const int length)=0
Read byte array.
Interface for binary output.
Definition JBinaryIO.hh:41
virtual int write(const char *buffer, const int length)=0
Write byte array.
Auxiliary class for object identification.
Definition JObjectID.hh:25
int getID() const
Get identifier.
Definition JObjectID.hh:50
Auxiliary classes and methods for binary I/O.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Interface for status of object.
Auxiliary class for handling status.
Definition JStatus.hh:31
status_type getStatus(const JType< status_type > &type) const
Get status.
Definition JStatus.hh:60