Utility Functions¶
|
API
|
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. | |
| template<class P, class T> | |
| P | check_and_cast_nullable (T *p) |
| A variant of check_and_cast<>() that also allows nullptr as input. | |
| 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. | |
| 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. | |
| 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. | |
| SIM_API const char * | opp_typename (const std::type_info &t) |
| Returns the name of a C++ type, correcting the quirks of various compilers. | |
| 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. | |
| 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. | |
Description
This group is a collection of miscellaneous utility functions.
Function Documentation
◆ check_and_cast()
| P 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.
References opp_typename().
◆ check_and_cast_nullable()
| P check_and_cast_nullable | ( | T * | p | ) |
A variant of check_and_cast<>() that also allows nullptr as input.
◆ checked_int_cast() [1/3]
| 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.
Referenced by cPar::operator char(), cValue::operator char(), cPar::operator int(), cValue::operator int(), cPar::operator long(), cValue::operator long(), cPar::operator long long(), cValue::operator long long(), cPar::operator short(), cValue::operator short(), cPar::operator unsigned char(), cValue::operator unsigned char(), cPar::operator unsigned int(), cValue::operator unsigned int(), cPar::operator unsigned long(), cValue::operator unsigned long(), cPar::operator unsigned long long(), cValue::operator unsigned long long(), cPar::operator unsigned short(), cValue::operator unsigned short(), cPar::operator=(), cPar::operator=(), cPar::operator=(), cValue::operator=(), cValue::operator=(), and cValue::operator=().
◆ checked_int_cast() [2/3]
| 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.
◆ checked_int_cast() [3/3]
| 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.
◆ opp_typename()
| SIM_API const char * opp_typename | ( | const std::type_info & | t | ) |
Returns the name of a C++ type, correcting the quirks of various compilers.
Referenced by cValueArray::asObjectVector(), check_and_cast(), cEnum::getNameForValue(), and cEnum::resolveName().
◆ opp_get_monotonic_clock_nsecs()
| 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.
◆ opp_get_monotonic_clock_usecs()
| 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.
Generated on for API by