16 #ifndef __OMNETPP_CHECKANDCAST_H 17 #define __OMNETPP_CHECKANDCAST_H 20 #include "simkerneldefs.h" 21 #include "cownedobject.h" 22 #include "cexception.h" 24 #include "csimulation.h" 28 template<
class P,
class T>
29 void check_and_cast_failure(T *p, P ret)
31 const cObject *o =
dynamic_cast<const cObject *
>(p);
33 throw cRuntimeError(
"check_and_cast(): Cannot cast (%s*)%s to type '%s'",
38 throw cRuntimeError(
"check_and_cast(): Cannot cast '%s*' to type '%s'",
60 template<
class P,
class T>
65 P ret =
dynamic_cast<P
>(p);
67 check_and_cast_failure(p, ret);
76 template<
class P,
class T>
81 P ret =
dynamic_cast<P
>(p);
83 check_and_cast_failure(p, ret);
Thrown when the simulation kernel or other components detect a runtime error.
Definition: cexception.h:283
static cSimulation * getActiveSimulation()
Definition: csimulation.h:142
cModule * getContextModule() const
virtual const char * getFullName() const override
Definition: cabstracthistogram.h:21
P check_and_cast(T *p)
Cast a pointer to the given pointer type P, and throw exception if fails.
Definition: checkandcast.h:61
SIM_API const char * opp_typename(const std::type_info &t)
Returns the name of a C++ type, correcting the quirks of various compilers.
P check_and_cast_nullable(T *p)
A variant of check_and_cast<>() that also allows nullptr as input.
Definition: checkandcast.h:77