[Libufo-commits] ufo-0.5/include/ufo/signals uobjectslot.hpp,1.12,1.13
Status: Beta
Brought to you by:
schmidtjf
|
From: Johannes S. <sch...@us...> - 2005-09-30 12:36:46
|
Update of /cvsroot/libufo/ufo-0.5/include/ufo/signals In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4016/include/ufo/signals Modified Files: uobjectslot.hpp Log Message: Fixed compilation on gcc <= 3.2 (be careful with static template members) Index: uobjectslot.hpp =================================================================== RCS file: /cvsroot/libufo/ufo-0.5/include/ufo/signals/uobjectslot.hpp,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** uobjectslot.hpp 15 Sep 2005 10:22:44 -0000 1.12 --- uobjectslot.hpp 30 Sep 2005 12:36:36 -0000 1.13 *************** *** 38,58 **** class UObject; ! ! /** A compile time check whether Base is really a base class of Child ! * This is from GotW #71 resp. from "More exceptional C++" */ ! ! template<class Child, class Base> ! class IsDerivedFrom { ! private: class Yes { char a[1]; }; ! class No { char a[10]; }; ! static Yes Test(Base*); // undefined ! static No Test(...); // undefined public: enum { ! Is = sizeof(Test(static_cast<Child*>(0))) == sizeof(Yes) ? 1 : 0 }; }; --- 38,59 ---- class UObject; ! /** Contains helper functions whether something can be casted to class @p Base. ! * This is in an extra namespace (instead of the template) as gcc < 3.4 ! * has problems with static template instantiation. */ ! namespace internal { class Yes { char a[1]; }; ! class No { char a[5]; }; ! template<class Base> static Yes canCastTo(Base*); ! template<class Base> static No canCastTo(...); ! } + /** This template checks whether @p Child can implicitely be casted to @p Base. */ + template<class Child, class Base> + class ImplicitCast { public: enum { ! Exists = sizeof(internal::canCastTo<Base>(static_cast<Child*>(0))) == sizeof(internal::Yes) ? 1 : 0 }; }; *************** *** 86,91 **** , m_method(method) { ! if (IsDerivedFrom<Obj, UObject>::Is) { ! m_uobject = reinterpret_cast<UObject*>(object); } if (m_uobject) { --- 87,92 ---- , m_method(method) { ! if (ImplicitCast<Obj, UObject>::Exists) { ! m_uobject = static_cast<UObject*>(object); } if (m_uobject) { |