interreality.org [VOS]
[Home] [About]
[Screenshots]
[Download]
[News]
[Community]
[Documentation] [Manual]
[Bugs & Requests] [Wiki]

/home/tetron/hack/vos/libs/vos/vos/meta_cast.hh

Go to the documentation of this file.
00001 #ifndef _META_CAST_HH_
00002 #define _META_CAST_HH_
00003 
00004 #include <vos/vos/vobjectbase.hh>
00005 #include <vos/vos/metaobject.hh>
00006 
00007 namespace VOS
00008 {
00009     /** @ingroup libvos
00010         @copydoc VOS::meta_cast(VUtil::vRef<T> v)
00011     */
00012     template<class C> inline VUtil::vRef<C> meta_cast(Vobject* v)
00013     {
00014         if(C* ret = dynamic_cast<C*>(v)) return VUtil::vRef<C>(ret, true);
00015         return v->getVobjectBase()->template queryInterface<C>();
00016     }
00017 
00018     /** @ingroup libvos
00019         @copydoc VOS::meta_cast(VUtil::vRef<T> v)
00020     */
00021     template<class C> inline VUtil::vRef<C> meta_cast(Vobject& v)
00022     {
00023         return meta_cast<C>(&v);
00024     }
00025 
00026     /** @ingroup libvos
00027         A special cast which allows you to retrieve some interface (if
00028         available) on the supplied Vobject.
00029 
00030         @code
00031         vRef<Vobject> vobj = site.createVobject2<Property, World>();
00032         vRef<Property> property = meta_cast<Property>(vobj);
00033         vRef<World> w = meta_cast<World>(property);
00034         @endcode
00035 
00036         @param v the object to be cast
00037         @return a vRef pointing to the new interface, or a null vRef
00038         if the vObject does not support this interface.
00039     */
00040     template<class C, class T> inline VUtil::vRef<C> meta_cast(VUtil::vRef<T> v)
00041     {
00042         return meta_cast<C>(v.get());
00043     }
00044 }
00045 
00046 #endif