Jpp test-rotations-old
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"
7
8
9/**
10 * \author mdejong
11 */
12
13/**
14 * Auxiliary classes and methods for binary I/O.
15 */
16namespace JIO {}
17namespace JPP { using namespace JIO; }
18
19namespace JIO {
20
24
25 class JReader; //!< Forward declaration of binary input.
26 class JWriter; //!< Forward declaration of binary output.
27
28
29 /**
30 * Interface class for a data structure with binary I/O.
31 */
33 public:
34 /**
35 * Virtual destructor.
36 */
38 {}
39
40
41 /**
42 * Read from input.
43 *
44 * \param in JReader
45 * \return JReader
46 */
47 virtual JReader& read(JReader& in) = 0;
48
49
50 /**
51 * Write to output.
52 *
53 * \param out JWriter
54 * \return JWriter
55 */
56 virtual JWriter& write(JWriter& out) const = 0;
57 };
58
59
60 /**
61 * Interface for binary input.
62 */
63 class JReader :
66 {
67 public:
68 /**
69 * Clear status of reader.
70 */
71 virtual void clear()
72 {}
73
74
75 /**
76 * Read serialisable data object.
77 *
78 * \param object serialisable data object
79 * \return JReader
80 */
82 {
83 return object.read(*this);
84 }
85
86
87 JReader& operator>>(bool& value) { read((char*) &value, sizeof(bool)); return *this; }
88 JReader& operator>>(char& value) { read((char*) &value, sizeof(char)); return *this; }
89 JReader& operator>>(unsigned char& value) { read((char*) &value, sizeof(unsigned char)); return *this; }
90 JReader& operator>>(short& value) { read((char*) &value, sizeof(short)); return *this; }
91 JReader& operator>>(unsigned short& value) { read((char*) &value, sizeof(unsigned short)); return *this; }
92 JReader& operator>>(int& value) { read((char*) &value, sizeof(int)); return *this; }
93 JReader& operator>>(unsigned int& value) { read((char*) &value, sizeof(unsigned int)); return *this; }
94 JReader& operator>>(long int& value) { read((char*) &value, sizeof(long int)); return *this; }
95 JReader& operator>>(unsigned long int& value) { read((char*) &value, sizeof(unsigned long int)); return *this; }
96 JReader& operator>>(long long int& value) { read((char*) &value, sizeof(long long int)); return *this; }
97 JReader& operator>>(unsigned long long int& value) { read((char*) &value, sizeof(unsigned long long int)); return *this; }
98 JReader& operator>>(float& value) { read((char*) &value, sizeof(float)); return *this; }
99 JReader& operator>>(double& value) { read((char*) &value, sizeof(double)); return *this; }
100 JReader& operator>>(long double& value) { read((char*) &value, sizeof(long double)); return *this; }
101 JReader& operator>>(JLANG::JObjectID& value) { return (*this) >> value.getID(); }
102
103
104 /**
105 * Read object.
106 *
107 * \param object object
108 * \return this reader
109 */
110 inline JReader& load(JSerialisable& object)
111 {
112 return object.read(*this);
113 }
114
115
116 /**
117 * Read object.
118 *
119 * \param object object
120 * \return this reader
121 */
122 template<class T>
123 inline JReader& load(T& object)
124 {
125 return *this >> object;
126 }
127 };
128
129
130 /**
131 * Interface for binary output.
132 */
133 class JWriter :
136 {
137 public:
138 /**
139 * Write serialisable data object.
140 *
141 * \param object serialisable data object
142 * \return JWriter
143 */
145 {
146 return object.write(*this);
147 }
148
149
150 JWriter& operator<<(const bool value) { write((const char*) &value, sizeof(bool)); return *this; }
151 JWriter& operator<<(const char value) { write((const char*) &value, sizeof(char)); return *this; }
152 JWriter& operator<<(const unsigned char value) { write((const char*) &value, sizeof(unsigned char)); return *this; }
153 JWriter& operator<<(const short value) { write((const char*) &value, sizeof(short)); return *this; }
154 JWriter& operator<<(const unsigned short value) { write((const char*) &value, sizeof(unsigned short)); return *this; }
155 JWriter& operator<<(const int value) { write((const char*) &value, sizeof(int)); return *this; }
156 JWriter& operator<<(const unsigned int value) { write((const char*) &value, sizeof(unsigned int)); return *this; }
157 JWriter& operator<<(const long int value) { write((const char*) &value, sizeof(long int)); return *this; }
158 JWriter& operator<<(const unsigned long int value) { write((const char*) &value, sizeof(unsigned long int)); return *this; }
159 JWriter& operator<<(const long long int value) { write((const char*) &value, sizeof(long long int)); return *this; }
160 JWriter& operator<<(const unsigned long long int value) { write((const char*) &value, sizeof(unsigned long long int)); return *this; }
161 JWriter& operator<<(const float value) { write((const char*) &value, sizeof(float)); return *this; }
162 JWriter& operator<<(const double value) { write((const char*) &value, sizeof(double)); return *this; }
163 JWriter& operator<<(const long double value) { write((const char*) &value, sizeof(long double)); return *this; }
164 JWriter& operator<<(const JLANG::JObjectID& value) { return (*this) << value.getID(); }
165
166
167 /**
168 * Write object.
169 *
170 * \param object object
171 * \return this writer
172 */
173 inline JWriter& store(const JSerialisable& object)
174 {
175 return object.write(*this);
176 }
177
178
179 /**
180 * Write object.
181 *
182 * \param object object
183 * \return this writer
184 */
185 template<class T>
186 inline JWriter& store(const T& object)
187 {
188 return *this << object;
189 }
190 };
191}
192
193#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 & 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 & 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.