Add a convenience function for the idiom "if(obj.is<Point>())"...

This commit is contained in:
Sylvain Pion 2009-12-16 16:09:04 +00:00
parent 6cf035c3ad
commit b9a62e057c
2 changed files with 9 additions and 0 deletions

View File

@ -40,6 +40,9 @@ Objects of type \ccRefName\ are normally created using the global function
\ccMethod{bool empty();}{returns true, if \ccVar\ does not
contain an object.}
\ccMethod{template<class T> bool is();}
{returns true, iff \ccVar\ contains an object of type \ccc{T}.}
\ccMethod{const std::type_info & type() const;}
{returns the type information of the contained type,
or \ccc{typeid(void)} if empty.}

View File

@ -131,6 +131,12 @@ class Object
return empty();
}
template <class T>
bool is() const
{
return NULL != dynamic_cast<const Wrapper<T> *>(Ptr());
}
const std::type_info & type() const
{
return empty() ? typeid(void) : Ptr()->type();