Jpp  17.3.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  */
16 namespace JIO {}
17 namespace JPP { using namespace JIO; }
18 
19 namespace JIO {
20 
21  using JLANG::JBinaryInput;
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  */
32  class JSerialisable {
33  public:
34  /**
35  * Virtual destructor.
36  */
37  virtual ~JSerialisable()
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 :
64  public JLANG::JBinaryInput,
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 :
134  public JLANG::JBinaryOutput,
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.
Definition: JBinaryIO.hh:18
JReader & operator>>(short &value)
Interface for binary output.
JWriter & store(const JSerialisable &object)
Write object.
JReader & operator>>(long long int &value)
JReader & operator>>(unsigned int &value)
JReader & operator>>(char &value)
JWriter & operator<<(const JLANG::JObjectID &value)
JWriter & operator<<(const char value)
JWriter & operator<<(const bool value)
JReader & operator>>(float &value)
virtual JWriter & write(JWriter &out) const =0
Write to output.
JWriter & operator<<(const short value)
JWriter & operator<<(const unsigned int value)
virtual int read(char *buffer, const int length)=0
Read byte array.
virtual int write(const char *buffer, const int length)=0
Write byte array.
JReader & operator>>(unsigned long long int &value)
JWriter & operator<<(const unsigned long long int value)
JReader & operator>>(JLANG::JObjectID &value)
JWriter & operator<<(const unsigned short value)
JWriter & operator<<(const long int value)
JReader & operator>>(unsigned char &value)
Forward declaration of binary output.
JReader & load(JSerialisable &object)
Read object.
virtual JReader & read(JReader &in)=0
Read from input.
JWriter & operator<<(const long long int value)
JReader & operator>>(unsigned long int &value)
do set_variable OUTPUT_DIRECTORY $WORKDIR T
int getID() const
Get identifier.
Definition: JObjectID.hh:50
JReader & operator>>(long double &value)
Interface for binary input.
JReader & operator>>(long int &value)
JReader & operator>>(JSerialisable &object)
Read serialisable data object.
JWriter & operator<<(const unsigned long int value)
JWriter & operator<<(const double value)
JReader & operator>>(unsigned short &value)
JWriter & operator<<(const float value)
JReader & operator>>(int &value)
Auxiliary class for object identification.
Definition: JObjectID.hh:22
JReader & load(T &object)
Read object.
Interface for status of object.
JWriter & operator<<(const long double value)
virtual ~JSerialisable()
Virtual destructor.
JWriter & operator<<(const int value)
JWriter & operator<<(const JSerialisable &object)
Write serialisable data object.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
JReader & operator>>(double &value)
virtual void clear()
Clear status of reader.
JReader & operator>>(bool &value)
Interface for binary output.
Definition: JBinaryIO.hh:41
JWriter & operator<<(const unsigned char value)
JWriter & store(const T &object)
Write object.