Debian Codegraph @

tests/SerializableDerivedA.hh

raw
1 // Example derived class for a serializable inheritance hierarchy
2
3 #ifndef GSTEST_SERIALIZABLEDERIVEDA_HH_
4 #define GSTEST_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 inline virtual ~SerializableDerivedA() {}
14
15 inline int a() const {return a_;}
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 "SerializableDerivedA";}
21 static inline unsigned version() {return 1;}
22 static SerializableDerivedA* 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 SerializableDerivedA& r =
30 static_cast<const SerializableDerivedA&>(otherBase);
31 return a_ == r.a_;
32 }
33
34 private:
35 int a_;
36 };
37
38 #endif // GSTEST_SERIALIZABLEDERIVEDA_HH_