| 1 |
// |
| 2 |
// Example simple stand-alone class without a default constructor |
| 3 |
// which plays nicely with the "geners" serialization facilities. |
| 4 |
// |
| 5 |
// In comparison with "SimpleSerializable1", the "restore" method |
| 6 |
// has been replaced by the "read" method which creates a new object |
| 7 |
// on the heap. Just as the "restore" method, the "read" method must |
| 8 |
// always succeed. If it is unable to build the object, it must throw |
| 9 |
// an exception which inherits from std::exception. |
| 10 |
// |
| 11 |
|
| 12 |
#ifndef GSEXAMPLES_SIMPLESERIALIZABLE2_HH_ |
| 13 |
#define GSEXAMPLES_SIMPLESERIALIZABLE2_HH_ |
| 14 |
|
| 15 |
#include "geners/ClassId.hh" |
| 16 |
|
| 17 |
class SimpleSerializable2 |
| 18 |
{ |
| 19 |
public: |
| 20 |
inline SimpleSerializable2(const double value) : datum_(value) {} |
| 21 |
|
| 22 |
inline double datum() const {return datum_;} |
| 23 |
|
| 24 |
// Operators which compare objects for equality are very useful |
| 25 |
// for I/O testing |
| 26 |
inline bool operator==(const SimpleSerializable2& r) const |
| 27 |
{return datum_ == r.datum_;} |
| 28 |
inline bool operator!=(const SimpleSerializable2& r) const |
| 29 |
{return !(*this == r);} |
| 30 |
|
| 31 |
// I/O methods needed for writing |
| 32 |
inline gs::ClassId classId() const {return gs::ClassId(*this);} |
| 33 |
bool write(std::ostream& of) const; |
| 34 |
|
| 35 |
// I/O methods needed for reading |
| 36 |
static inline const char* classname() {return "SimpleSerializable2";} |
| 37 |
static inline unsigned version() {return 1;} |
| 38 |
static SimpleSerializable2* read(const gs::ClassId& id, std::istream& in); |
| 39 |
|
| 40 |
private: |
| 41 |
SimpleSerializable2(); |
| 42 |
|
| 43 |
double datum_; |
| 44 |
}; |
| 45 |
|
| 46 |
#endif // GSEXAMPLES_SIMPLESERIALIZABLE2_HH_ |