mirror of https://github.com/CGAL/cgal
Simplify assign in Object.h
This commit is contained in:
parent
2891c22fc7
commit
b575892a16
|
|
@ -76,25 +76,10 @@ class Object
|
||||||
template <class T>
|
template <class T>
|
||||||
bool assign(T &t) const
|
bool assign(T &t) const
|
||||||
{
|
{
|
||||||
if(obj) {
|
const T* res = boost::any_cast<T>(obj.get());
|
||||||
#ifdef CGAL_USE_ANY_BAD_CAST
|
if (!res) return false;
|
||||||
try {
|
t = *res;
|
||||||
t = boost::any_cast<T>(*obj);
|
return true;
|
||||||
return true;
|
|
||||||
} catch(...) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
const T* res = boost::any_cast<T>(&(*obj));
|
|
||||||
if (res){
|
|
||||||
t=*res;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
#endif
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
@ -174,19 +159,13 @@ template <class T>
|
||||||
inline
|
inline
|
||||||
const T * object_cast(const Object * o)
|
const T * object_cast(const Object * o)
|
||||||
{
|
{
|
||||||
if(o->obj)
|
return boost::any_cast<T>((o->obj).get());
|
||||||
return boost::any_cast<T>((o->obj).get());
|
|
||||||
else
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
inline
|
inline
|
||||||
T object_cast(const Object & o)
|
T object_cast(const Object & o)
|
||||||
{
|
{
|
||||||
if(!o.obj)
|
|
||||||
throw Bad_object_cast();
|
|
||||||
|
|
||||||
const T * result = boost::any_cast<T>((o.obj).get());
|
const T * result = boost::any_cast<T>((o.obj).get());
|
||||||
if (!result)
|
if (!result)
|
||||||
throw Bad_object_cast();
|
throw Bad_object_cast();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue