OMNeT++ Simulation Library  5.6.1
Utility Classes

Description

This group is a collection of classes and functions that make it easier to write simulation models.

Classes

class  cMatchExpression::Matchable
 Objects to be matched must implement this interface. More...
 
class  cMatchExpression
 Decides whether an object matches an expression. More...
 
class  cMatchableString
 Wrapper to make a string matchable with cMatchExpression. More...
 
class  cPatternMatcher
 Glob-style pattern matching class, adopted to special OMNeT++ requirements. One instance represents a pattern to match. More...
 
class  cStringTokenizer
 String tokenizer class, modelled after strtok(). More...
 
class  cTopology
 Routing support. The cTopology class was designed primarily to support routing in telecommunication or multiprocessor networks. More...
 
class  opp_string
 Lightweight string class, used internally in some parts of OMNeT++. More...
 
class  opp_string_vector
 Lightweight string vector, used internally in some parts of OMNeT++. More...
 
class  opp_string_map
 Lightweight string-to-string map, used internally in some parts of OMNeT++. More...
 

Functions

template<class P , class T >
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 >
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 context 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 argument 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 context argument will be used for the error message. More...
 
int opp_strlen (const char *)
 Same as the standard strlen() function, except that it also accepts nullptr and returns 0 for it. More...
 
char * opp_strdup (const char *)
 Duplicates the string, using new char[]. For nullptr and empty strings it returns nullptr. More...
 
char * opp_strcpy (char *, const char *)
 Same as the standard strcpy() function, except that nullptr as the second argument is treated as an empty string (""). More...
 
int opp_strcmp (const char *, const char *)
 Same as the standard strcmp() function, except that nullptr is treated exactly as an empty string (""). More...
 
SIM_API char * opp_strprettytrunc (char *dest, const char *src, unsigned maxlen)
 Copies src string into dest, and if its length would exceed maxlen, it is truncated with an ellipsis. For example, opp_strprettytrunc(buf, "long-long",6) yields "lon...". More...
 
SIM_API const 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...
 

Function Documentation

◆ check_and_cast()

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().

◆ check_and_cast_nullable()

P omnetpp::check_and_cast_nullable ( T *  p)

A variant of check_and_cast<>() that also allows nullptr as input.

◆ checked_int_cast() [1/3]

◆ checked_int_cast() [2/3]

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 argument will be used for the error message.

◆ checked_int_cast() [3/3]

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 context argument will be used for the error message.

◆ opp_strlen()

int opp_strlen ( const char *  s)
inline

Same as the standard strlen() function, except that it also accepts nullptr and returns 0 for it.

◆ opp_strdup()

char * opp_strdup ( const char *  s)
inline

Duplicates the string, using new char[]. For nullptr and empty strings it returns nullptr.

Referenced by opp_string::operator=(), and opp_string::opp_string().

◆ opp_strcpy()

char * opp_strcpy ( char *  s1,
const char *  s2 
)
inline

Same as the standard strcpy() function, except that nullptr as the second argument is treated as an empty string ("").

◆ opp_strcmp()

int opp_strcmp ( const char *  s1,
const char *  s2 
)
inline

Same as the standard strcmp() function, except that nullptr is treated exactly as an empty string ("").

Referenced by cObject::isName(), opp_string::operator!=(), opp_string::operator<(), and opp_string::operator==().

◆ opp_strprettytrunc()

SIM_API char* omnetpp::opp_strprettytrunc ( char *  dest,
const char *  src,
unsigned  maxlen 
)

Copies src string into dest, and if its length would exceed maxlen, it is truncated with an ellipsis. For example, opp_strprettytrunc(buf, "long-long",6) yields "lon...".

◆ opp_typename()

SIM_API const char* omnetpp::opp_typename ( const std::type_info &  t)

Returns the name of a C++ type, correcting the quirks of various compilers.

Referenced by omnetpp::check_and_cast(), cGenericReadonlyWatch< T >::getClassName(), and cGenericAssignableWatch< T >::getClassName().

◆ opp_get_monotonic_clock_nsecs()

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.

◆ opp_get_monotonic_clock_usecs()

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.