| 1 |
// Example derived class for a serializable inheritance hierarchy |
| 2 |
|
| 3 |
#ifndef GSEXAMPLES_SERIALIZABLEDERIVEDA_HH_ |
| 4 |
#define GSEXAMPLES_SERIALIZABLEDERIVEDA_HH_ |
| 5 |
|
| 6 |
#include "SerializableBase.hh" |
| 7 |
|
| 8 |
class SerializableDerivedA : public SerializableBase |
| 9 |
{ |
| 10 |
public: |
| 11 |
inline SerializableDerivedA(const int i) : SerializableBase(), a_(i) |
| 12 |
{ |
| 13 |
std::cout << "SerializableDerivedA constructor" << std::endl; |
| 14 |
} |
| 15 |
|
| 16 |
inline virtual ~SerializableDerivedA() |
| 17 |
{ |
| 18 |
std::cout << "SerializableDerivedA destructor" << std::endl; |
| 19 |
} |
| 20 |
|
| 21 |
inline int a() const {return a_;} |
| 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 "SerializableDerivedA";} |
| 27 |
static inline unsigned version() {return 1;} |
| 28 |
static SerializableDerivedA* 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 SerializableDerivedA& r = |
| 36 |
static_cast<const SerializableDerivedA&>(otherBase); |
| 37 |
return a_ == r.a_; |
| 38 |
} |
| 39 |
|
| 40 |
private: |
| 41 |
int a_; |
| 42 |
}; |
| 43 |
|
| 44 |
#endif // GSEXAMPLES_SERIALIZABLEDERIVEDA_HH_ |