Jpp 21.0.0-rc.1
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 template<class T>
103 JReader& operator>>(JLANG::JObjectID<T>& value) { return (*this) >> value.getID(); }
105
106
107 /**
108 * Read object.
109 *
110 * \param object object
111 * \return this reader
112 */
113 inline JReader& load(JSerialisable& object)
114 {
115 return object.read(*this);
116 }
117
118
119 /**
120 * Read object.
121 *
122 * \param object object
123 * \return this reader
124 */
125 template<class T>
126 inline JReader& load(T& object)
127 {
128 return *this >> object;
129 }
130 };
131
132
133 /**
134 * Interface for binary output.
135 */
136 class JWriter :
139 {
140 public:
141 /**
142 * Write serialisable data object.
143 *
144 * \param object serialisable data object
145 * \return JWriter
146 */
148 {
149 return object.write(*this);
150 }
151
152
153 JWriter& operator<<(const bool value) { write((const char*) &value, sizeof(bool)); return *this; }
154 JWriter& operator<<(const char value) { write((const char*) &value, sizeof(char)); return *this; }
155 JWriter& operator<<(const unsigned char value) { write((const char*) &value, sizeof(unsigned char)); return *this; }
156 JWriter& operator<<(const short value) { write((const char*) &value, sizeof(short)); return *this; }
157 JWriter& operator<<(const unsigned short value) { write((const char*) &value, sizeof(unsigned short)); return *this; }
158 JWriter& operator<<(const int value) { write((const char*) &value, sizeof(int)); return *this; }
159 JWriter& operator<<(const unsigned int value) { write((const char*) &value, sizeof(unsigned int)); return *this; }
160 JWriter& operator<<(const long int value) { write((const char*) &value, sizeof(long int)); return *this; }
161 JWriter& operator<<(const unsigned long int value) { write((const char*) &value, sizeof(unsigned long int)); return *this; }
162 JWriter& operator<<(const long long int value) { write((const char*) &value, sizeof(long long int)); return *this; }
163 JWriter& operator<<(const unsigned long long int value) { write((const char*) &value, sizeof(unsigned long long int)); return *this; }
164 JWriter& operator<<(const float value) { write((const char*) &value, sizeof(float)); return *this; }
165 JWriter& operator<<(const double value) { write((const char*) &value, sizeof(double)); return *this; }
166 JWriter& operator<<(const long double value) { write((const char*) &value, sizeof(long double)); return *this; }
167 template<class T>
168 JWriter& operator<<(const JLANG::JObjectID<T>& value) { return (*this) << value.getID(); }
169 JWriter& operator<<(const JLANG::JStatus& value) { return (*this) << value.getStatus<JLANG::JStatus::status_type>(); }
170
171
172 /**
173 * Write object.
174 *
175 * \param object object
176 * \return this writer
177 */
178 inline JWriter& store(const JSerialisable& object)
179 {
180 return object.write(*this);
181 }
182
183
184 /**
185 * Write object.
186 *
187 * \param object object
188 * \return this writer
189 */
190 template<class T>
191 inline JWriter& store(const T& object)
192 {
193 return *this << object;
194 }
195 };
196}
197
198#endif
Interface for binary input.
JReader & operator>>(unsigned long long int &value)
JReader & operator>>(bool &value)
JReader & operator>>(JSerialisable &object)
Read serialisable data object.
JReader & operator>>(JLANG::JObjectID< T > &value)
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 JSerialisable &object)
Write serialisable data object.
JWriter & operator<<(const JLANG::JObjectID< T > &value)
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 base class for object identification.
Definition JObjectID.hh:38
int getID() const
Get identifier.
Definition JObjectID.hh:63
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