From b9a62e057c7ac8741e3708f28d23a23e86ad944e Mon Sep 17 00:00:00 2001 From: Sylvain Pion Date: Wed, 16 Dec 2009 16:09:04 +0000 Subject: [PATCH] Add a convenience function for the idiom "if(obj.is())"... --- STL_Extension/doc_tex/STL_Extension_ref/Object.tex | 3 +++ STL_Extension/include/CGAL/Object.h | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/STL_Extension/doc_tex/STL_Extension_ref/Object.tex b/STL_Extension/doc_tex/STL_Extension_ref/Object.tex index 6f188040e90..b2104c8832b 100644 --- a/STL_Extension/doc_tex/STL_Extension_ref/Object.tex +++ b/STL_Extension/doc_tex/STL_Extension_ref/Object.tex @@ -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 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.} diff --git a/STL_Extension/include/CGAL/Object.h b/STL_Extension/include/CGAL/Object.h index ad3ac12bead..c8883e8bfbc 100644 --- a/STL_Extension/include/CGAL/Object.h +++ b/STL_Extension/include/CGAL/Object.h @@ -131,6 +131,12 @@ class Object return empty(); } + template + bool is() const + { + return NULL != dynamic_cast *>(Ptr()); + } + const std::type_info & type() const { return empty() ? typeid(void) : Ptr()->type();