Debian Codegraph @

tests/SerializableDerivedB.hh

raw
1 // Example derived class for a serializable inheritance hierarchy
2
3 #ifndef GSTEST_SERIALIZABLEDERIVEDB_HH_
4 #define GSTEST_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 inline virtual ~SerializableDerivedB() {}
14
15 inline double b() const {return b_;}
16
17 virtual inline gs::ClassId classId() const {return gs::ClassId(*this);}
18 virtual bool write(std::ostream& of) const;
19
20 static inline const char* classname() {return "SerializableDerivedB";}
21 static inline unsigned version() {return 1;}
22 static SerializableDerivedB* read(const gs::ClassId& id, std::istream& in);
23
24 protected:
25 virtual bool isEqual(const SerializableBase& otherBase) const
26 {
27 // Note the use of static_cast rather than dynamic_cast below.
28 // static_cast works faster and it is guaranteed to succeed here.
29 const SerializableDerivedB& r =
30 static_cast<const SerializableDerivedB&>(otherBase);
31 return b_ == r.b_;
32 }
33
34 private:
35 double b_;
36 };
37
38 #endif // GSTEST_SERIALIZABLEDERIVEDB_HH_