16 #ifndef __OMNETPP_SIMUTIL_H
17 #define __OMNETPP_SIMUTIL_H
22 #include <type_traits>
23 #include "simkerneldefs.h"
37 SIM_API
void intCastError(
const std::string& num,
const char *errmsg=
nullptr);
38 SIM_API
void intCastError(
const std::string& num,
const cObject *context,
const char *errmsg=
nullptr);
45 template<
typename ToInt,
typename FromInt>
48 static_assert(std::is_integral<ToInt>::value && std::is_integral<FromInt>::value,
"checked_int_cast expects integers");
50 if ((x<0) != (res<0) || x-res != 0)
51 omnetpp::intCastError(std::to_string(x), errmsg);
60 template<
typename ToInt,
typename FromInt>
63 static_assert(std::is_integral<ToInt>::value && std::is_integral<FromInt>::value,
"checked_int_cast expects integers");
65 if ((x<0) != (res<0) || x-res != 0)
66 omnetpp::intCastError(std::to_string(x), context, errmsg);
75 template<
typename ToInt>
78 static_assert(std::is_integral<ToInt>::value,
"checked_int_cast expects integer template argument");
80 if ((
double)res != std::trunc(d))
81 omnetpp::intCastError(std::to_string(d), errmsg);
88 SIM_API
const char *
opp_typename(
const std::type_info& t);