| 1 |
// |
| 2 |
// Example template class without default constructor and without |
| 3 |
// serialization facilities. It does provide access to all members |
| 4 |
// that need serialization. In order for us to serialize this template, |
| 5 |
// the types upon which this template is parameterized must themselves |
| 6 |
// be serializable (and, of course, copy-constructible). |
| 7 |
// |
| 8 |
|
| 9 |
#ifndef GSEXAMPLES_EXTERNALTEMPLATE_HH_ |
| 10 |
#define GSEXAMPLES_EXTERNALTEMPLATE_HH_ |
| 11 |
|
| 12 |
template<class A, class B> |
| 13 |
class ExternalTemplate |
| 14 |
{ |
| 15 |
public: |
| 16 |
inline ExternalTemplate(const A& a, const B& b) : a_(a), b_(b) {} |
| 17 |
|
| 18 |
inline const A& getA() const {return a_;} |
| 19 |
inline const B& getB() const {return b_;} |
| 20 |
|
| 21 |
// The comparison operator is here for convenience. |
| 22 |
// It helps to check that the serialization was correctly |
| 23 |
// performed but its existence is not strictly necessary |
| 24 |
// to serialize/deserialize such a template. Naturally, |
| 25 |
// this operator restricts possible A and B classes to |
| 26 |
// those types for which "operator==" is defined. |
| 27 |
// |
| 28 |
inline bool operator==(const ExternalTemplate& r) const |
| 29 |
{return a_ == r.a_ && b_ == r.b_;} |
| 30 |
inline bool operator!=(const ExternalTemplate& r) const |
| 31 |
{return !(*this == r);} |
| 32 |
|
| 33 |
private: |
| 34 |
A a_; |
| 35 |
B b_; |
| 36 |
}; |
| 37 |
|
| 38 |
// |
| 39 |
// Example template class about which we will assume that its |
| 40 |
// serialized representation does not need to depend on the |
| 41 |
// template parameter |
| 42 |
// |
| 43 |
template<class A> |
| 44 |
class ExternalTemplate2 |
| 45 |
{ |
| 46 |
public: |
| 47 |
inline ExternalTemplate2(const int b) : a_(), b_(b) {} |
| 48 |
|
| 49 |
inline const A& getA() const {return a_;} |
| 50 |
inline int getInt() const {return b_;} |
| 51 |
|
| 52 |
// We presume that the value of a_ does not |
| 53 |
// affect the "interesting" state of this class. |
| 54 |
// |
| 55 |
inline bool operator==(const ExternalTemplate2& r) const |
| 56 |
{return b_ == r.b_;} |
| 57 |
inline bool operator!=(const ExternalTemplate2& r) const |
| 58 |
{return !(*this == r);} |
| 59 |
|
| 60 |
private: |
| 61 |
A a_; |
| 62 |
int b_; |
| 63 |
}; |
| 64 |
|
| 65 |
#endif // GSEXAMPLES_MYTEMPLATE_HH_ |