OMNeT++ Simulation Library
6.0.3
|
This group is a collection of miscellaneous utility functions.
Functions | |
template<class P , class T > | |
P | check_and_cast (T *p) |
Cast a pointer to the given pointer type P, and throw exception if fails. More... | |
template<class P , class T > | |
P | check_and_cast_nullable (T *p) |
A variant of check_and_cast<>() that also allows nullptr as input. More... | |
template<typename ToInt , typename FromInt > | |
ToInt | checked_int_cast (FromInt x, const char *errmsg=nullptr) |
Safe integer cast: it throws an exception if in case of an overflow, i.e. when if the target type cannot represent the value in the source type. The errmsg argument will be used for the error message. More... | |
template<typename ToInt , typename FromInt > | |
ToInt | checked_int_cast (FromInt x, const cObject *context, const char *errmsg=nullptr) |
Safe integer cast: it throws an exception if in case of an overflow, i.e. when if the target type cannot represent the value in the source type. The context and errmsg arguments will be used for the error message. More... | |
template<typename ToInt > | |
ToInt | checked_int_cast (double d, const char *errmsg=nullptr) |
Safe integer cast: it throws an exception if in case of an overflow, i.e. when if the target type cannot represent the value in the source type. The errmsg argument will be used for the error message. More... | |
const SIM_API char * | opp_typename (const std::type_info &t) |
Returns the name of a C++ type, correcting the quirks of various compilers. More... | |
SIM_API int64_t | opp_get_monotonic_clock_nsecs () |
Returns a monotonic time in nanoseconds since some unspecified starting point. This clock is not affected by discontinuous jumps in the system time (e.g. if the system administrator manually changes the clock). Note that the actual resolution (precision) of the clock may be less than nanoseconds. More... | |
SIM_API int64_t | opp_get_monotonic_clock_usecs () |
Returns a monotonic time in microseconds since some unspecified starting point. This clock is not affected by discontinuous jumps in the system time (e.g. if the system administrator manually changes the clock). Note that the actual resolution (precision) of the clock may be less than microseconds. More... | |
P omnetpp::check_and_cast | ( | T * | p | ) |
Cast a pointer to the given pointer type P, and throw exception if fails.
The method calls dynamic_cast<P>(p) where P is a type you supplied; if the result is nullptr (which indicates incompatible types), an exception is thrown.
In the following example, DHCPPacket is a subclass of cMessage, and we want to assert that the message received is actually a DHCPPacket. If not, the simulation stops with an error message as the result of the exception.
cMessage *msg = ...; DHCPPacket *pk = check_and_cast<DHCPPacket *>(msg);
References omnetpp::opp_typename().
P omnetpp::check_and_cast_nullable | ( | T * | p | ) |
A variant of check_and_cast<>() that also allows nullptr as input.
ToInt omnetpp::checked_int_cast | ( | FromInt | x, |
const char * | errmsg = nullptr |
||
) |
Safe integer cast: it throws an exception if in case of an overflow, i.e. when if the target type cannot represent the value in the source type. The errmsg argument will be used for the error message.
ToInt omnetpp::checked_int_cast | ( | FromInt | x, |
const cObject * | context, | ||
const char * | errmsg = nullptr |
||
) |
Safe integer cast: it throws an exception if in case of an overflow, i.e. when if the target type cannot represent the value in the source type. The context and errmsg arguments will be used for the error message.
ToInt omnetpp::checked_int_cast | ( | double | d, |
const char * | errmsg = nullptr |
||
) |
Safe integer cast: it throws an exception if in case of an overflow, i.e. when if the target type cannot represent the value in the source type. The errmsg argument will be used for the error message.
const SIM_API char* omnetpp::opp_typename | ( | const std::type_info & | t | ) |
Returns the name of a C++ type, correcting the quirks of various compilers.
Referenced by cValueArray::asObjectVector(), omnetpp::check_and_cast(), cGenericReadonlyWatch< T >::getClassName(), and cGenericAssignableWatch< T >::getClassName().
SIM_API int64_t omnetpp::opp_get_monotonic_clock_nsecs | ( | ) |
Returns a monotonic time in nanoseconds since some unspecified starting point. This clock is not affected by discontinuous jumps in the system time (e.g. if the system administrator manually changes the clock). Note that the actual resolution (precision) of the clock may be less than nanoseconds.
SIM_API int64_t omnetpp::opp_get_monotonic_clock_usecs | ( | ) |
Returns a monotonic time in microseconds since some unspecified starting point. This clock is not affected by discontinuous jumps in the system time (e.g. if the system administrator manually changes the clock). Note that the actual resolution (precision) of the clock may be less than microseconds.