| 1 |
// Example derived class for a serializable inheritance hierarchy |
| 2 |
|
| 3 |
#ifndef GSEXAMPLES_SERIALIZABLEDERIVEDB_HH_ |
| 4 |
#define GSEXAMPLES_SERIALIZABLEDERIVEDB_HH_ |
| 5 |
|
| 6 |
#include "SerializableBase.hh" |
| 7 |
|
| 8 |
class SerializableDerivedB : public SerializableBase |
| 9 |
{ |
| 10 |
public: |
| 11 |
inline SerializableDerivedB(const double d) : SerializableBase(), b_(d) |
| 12 |
{ |
| 13 |
std::cout << "SerializableDerivedB constructor" << std::endl; |
| 14 |
} |
| 15 |
|
| 16 |
inline virtual ~SerializableDerivedB() |
| 17 |
{ |
| 18 |
std::cout << "SerializableDerivedB destructor" << std::endl; |
| 19 |
} |
| 20 |
|
| 21 |
inline double b() const {return b_;} |
| 22 |
|
| 23 |
virtual inline gs::ClassId classId() const {return gs::ClassId(*this);} |
| 24 |
virtual bool write(std::ostream& of) const; |
| 25 |
|
| 26 |
static inline const char* classname() {return "SerializableDerivedB";} |
| 27 |
static inline unsigned version() {return 1;} |
| 28 |
static SerializableDerivedB* read(const gs::ClassId& id, std::istream& in); |
| 29 |
|
| 30 |
protected: |
| 31 |
virtual bool isEqual(const SerializableBase& otherBase) const |
| 32 |
{ |
| 33 |
// Note the use of static_cast rather than dynamic_cast below. |
| 34 |
// static_cast works faster and it is guaranteed to succeed here. |
| 35 |
const SerializableDerivedB& r = |
| 36 |
static_cast<const SerializableDerivedB&>(otherBase); |
| 37 |
return b_ == r.b_; |
| 38 |
} |
| 39 |
|
| 40 |
private: |
| 41 |
double b_; |
| 42 |
}; |
| 43 |
|
| 44 |
#endif // GSEXAMPLES_SERIALIZABLEDERIVEDB_HH_ |