29 #ifndef DATATOOLS_CASTER_UTILS_H 30 #define DATATOOLS_CASTER_UTILS_H 46 template<
typename From,
typename ToBase>
49 virtual ToBase *
cast(From *) = 0;
55 template <
typename From,
typename ToBase,
typename ToDaughter>
60 virtual ToDaughter *
cast(From * ptr_) {
61 return reinterpret_cast<ToDaughter*>(ptr_);
67 template<
class Base,
class Derived>
70 const Base * pb = &b_;
71 const Derived * dummy = dynamic_cast<const Derived *>(pb);
81 #define DATATOOLS_CASTER_DECLARATION(From,ToBase,ToDaughter,CasterId,CasterGetter) \ 83 static std::unique_ptr<datatools::caster<From,ToBase,ToDaughter> > CasterId; \ 85 virtual datatools::i_caster<From,ToBase>* CasterGetter() const; \ 89 #define DATATOOLS_CASTER_IMPLEMENTATION(From,ToBase,ToDaughter,CasterId,CasterGetter) \ 90 std::unique_ptr<datatools::caster<From,ToBase,ToDaughter> > ToDaughter::CasterId; \ 91 datatools::i_caster<From,ToBase>* ToDaughter::CasterGetter() const { \ 92 if (ToDaughter::CasterId.get() == 0) { \ 93 ToDaughter::CasterId.reset(new datatools::caster<From,ToBase,ToDaughter>); \ 95 return ToDaughter::CasterId.get(); \ 99 #endif // DATATOOLS_CASTER_UTILS_H