OMNeT++ Simulation Library  6.0.3
cMsgPar Class Reference

#include <cmsgpar.h>

Description

Allows a value (string, bool, double, etc) to be attached to a cMessage object.

Note: Before version 3.0, the cPar class was used for both message parameters and module parameters. As of 4.0, cPar only serves as module/channel parameter, and other uses of cPar in existing 3.x code should be either eliminated (see next note), or changed to cMsgPar.

Note2: This is an obsolete class, retained to support legacy code. The preferred way of adding data to cMessages since the 2.3 version is via subclassing, using .msg files and the opp_msgc tool.

cMsgPar supports several data types. Data types are identified by type characters. The current data type is returned by getType().

  • basic types: S string, B bool, L long, D double
  • F math function (MathFuncNoArgs,MathFunc1Args,etc),
  • T a statistic object (subclassed from cStatistic)
  • P pointer to cOwnedObject,
  • M XML element (pointer to a cXMLElement)
Inheritance diagram for cMsgPar:
cOwnedObject cNamedObject cObject

Public Types

typedef void(* VoidDelFunc) (void *)
 
typedef void *(* VoidDupFunc) (void *)
 

Public Member Functions

Constructors, destructor, assignment.
 cMsgPar (const cMsgPar &other)
 
 cMsgPar (const char *name=nullptr)
 
 cMsgPar (const char *name, cMsgPar &other)
 
virtual ~cMsgPar ()
 
cMsgParoperator= (const cMsgPar &otherpar)
 
Redefined cObject member functions
virtual cMsgPardup () const override
 
virtual std::string str () const override
 
virtual void forEachChild (cVisitor *v) override
 
virtual void parsimPack (cCommBuffer *buffer) const override
 
virtual void parsimUnpack (cCommBuffer *buffer) override
 
Setter functions. Note that overloaded assignment operators also exist.
cMsgParsetBoolValue (bool b)
 
cMsgParsetLongValue (long l)
 
cMsgParsetStringValue (const char *s)
 
cMsgParsetDoubleValue (double d)
 
cMsgParsetDoubleValue (cStatistic *res)
 
cMsgParsetDoubleValue (MathFuncNoArg f)
 
cMsgParsetDoubleValue (MathFunc1Arg f, double p1)
 
cMsgParsetDoubleValue (MathFunc2Args f, double p1, double p2)
 
cMsgParsetDoubleValue (MathFunc3Args f, double p1, double p2, double p3)
 
cMsgParsetDoubleValue (MathFunc4Args f, double p1, double p2, double p3, double p4)
 
cMsgParsetPointerValue (void *ptr)
 
cMsgParsetObjectValue (cOwnedObject *obj)
 
cMsgParsetXMLValue (cXMLElement *node)
 
void configPointer (VoidDelFunc delfunc, VoidDupFunc dupfunc, size_t itemsize=0)
 
void setTakeOwnership (bool tk)
 
bool getTakeOwnership () const
 
Getter functions. Note that overloaded conversion operators also exist.
bool boolValue ()
 
long longValue ()
 
const char * stringValue ()
 
double doubleValue ()
 
void * pointerValue ()
 
cOwnedObjectgetObjectValue ()
 
cXMLElementxmlValue ()
 
Type, change flag.
char getType () const
 
bool isNumeric () const
 
bool isConstant () const
 
bool hasChanged ()
 
Utility functions.
void convertToConst ()
 
bool equalsTo (cMsgPar *par)
 
Convert to/from text representation.
virtual bool parse (const char *text, char type='?')
 
Overloaded assignment and conversion operators.
cMsgParoperator= (bool b)
 
cMsgParoperator= (const char *s)
 
cMsgParoperator= (char c)
 
cMsgParoperator= (unsigned char c)
 
cMsgParoperator= (int i)
 
cMsgParoperator= (unsigned int i)
 
cMsgParoperator= (short i)
 
cMsgParoperator= (unsigned short i)
 
cMsgParoperator= (long l)
 
cMsgParoperator= (unsigned long l)
 
cMsgParoperator= (double d)
 
cMsgParoperator= (long double d)
 
cMsgParoperator= (void *ptr)
 
cMsgParoperator= (cOwnedObject *obj)
 
cMsgParoperator= (cXMLElement *node)
 
 operator bool ()
 
 operator const char * ()
 
 operator char ()
 
 operator unsigned char ()
 
 operator int ()
 
 operator unsigned int ()
 
 operator short ()
 
 operator unsigned short ()
 
 operator long ()
 
 operator unsigned long ()
 
 operator double ()
 
 operator long double ()
 
 operator void * ()
 
 operator cOwnedObject * ()
 
 operator cXMLElement * ()
 
- Public Member Functions inherited from cOwnedObject
 cOwnedObject ()
 
 cOwnedObject (const char *name, bool namepooling=true)
 
 cOwnedObject (const cOwnedObject &obj)
 
virtual ~cOwnedObject ()
 
cOwnedObjectoperator= (const cOwnedObject &o)
 
virtual cObjectgetOwner () const override
 
virtual bool isOwnedObject () const override
 
- Public Member Functions inherited from cNamedObject
 cNamedObject ()
 
 cNamedObject (const char *name, bool namepooling=true)
 
 cNamedObject (const cNamedObject &obj)
 
virtual ~cNamedObject ()
 
cNamedObjectoperator= (const cNamedObject &o)
 
virtual void setName (const char *s)
 
virtual const char * getName () const override
 
virtual void setNamePooling (bool b)
 
virtual bool getNamePooling ()
 
- Public Member Functions inherited from cObject
 cObject ()
 
 cObject (const cObject &other)=default
 
virtual ~cObject ()
 
virtual const char * getClassName () const
 
bool isName (const char *s) const
 
virtual const char * getFullName () const
 
virtual std::string getFullPath () const
 
virtual std::string getClassAndFullName () const
 
virtual std::string getClassAndFullPath () const
 
const cObjectgetThisPtr () const
 
virtual std::ostream & printOn (std::ostream &os) const
 
virtual bool isSoftOwner () const
 
cObjectfindObject (const char *name, bool deep=true)
 
virtual cClassDescriptorgetDescriptor () const
 
void copyNotSupported () const
 

Protected Member Functions

Event hooks
virtual void beforeChange ()
 
virtual void afterChange ()
 
- Protected Member Functions inherited from cObject
virtual void take (cOwnedObject *obj)
 
virtual void drop (cOwnedObject *obj)
 
void dropAndDelete (cOwnedObject *obj)
 

Additional Inherited Members

- Static Public Member Functions inherited from cOwnedObject
static long getTotalObjectCount ()
 
static long getLiveObjectCount ()
 
static void resetObjectCounters ()
 
static cSoftOwnergetOwningContext ()
 

Member Typedef Documentation

◆ VoidDelFunc

typedef void(* VoidDelFunc(void *)

Prototype for functions to free up a user-defined data structure.

◆ VoidDupFunc

typedef void*(* VoidDupFunc(void *)

Prototype for functions to duplicate a user-defined data structure.

Constructor & Destructor Documentation

◆ cMsgPar() [1/3]

cMsgPar ( const cMsgPar other)

Copy constructor, creates an exact copy of the argument.

◆ cMsgPar() [2/3]

cMsgPar ( const char *  name = nullptr)
explicit

Constructor, creates a cMsgPar with the given name and long ('L') as default type.

◆ cMsgPar() [3/3]

cMsgPar ( const char *  name,
cMsgPar other 
)
explicit

Constructor, creates a copy of the second argument with another name.

◆ ~cMsgPar()

virtual ~cMsgPar ( )
virtual

Destructor.

Member Function Documentation

◆ beforeChange()

virtual void beforeChange ( )
protectedvirtual

Called each time before the value of this object changes. It can be used for tracking parameter changes. This default implementation does nothing.

◆ afterChange()

virtual void afterChange ( )
protectedvirtual

Called each time after the value of this object changed. It can be used for tracking parameter changes. This default implementation does nothing.

◆ operator=() [1/16]

cMsgPar& operator= ( const cMsgPar otherpar)

Assignment operator. The name member is not copied; see cOwnedObject's operator=() for more details.

The behavior with redirected cMsgPar objects is the following. This function copies the contents of the other object (whether it is redirected or not) into this object, or, if this object is redirected, into the object this object refers to. This means that if you want to overwrite this very object (and not the one it points to), you have to use cancelRedirection() first.

◆ dup()

virtual cMsgPar* dup ( ) const
inlineoverridevirtual

Creates and returns an exact copy of this object. See cObject for more details.

Reimplemented from cObject.

◆ str()

virtual std::string str ( ) const
overridevirtual

Returns the value in text form. See cObject for more details.

Reimplemented from cObject.

◆ forEachChild()

virtual void forEachChild ( cVisitor v)
overridevirtual

Calls v->visit(this) for the contained object, if there is any. See cObject for more details.

Reimplemented from cObject.

◆ parsimPack()

virtual void parsimPack ( cCommBuffer buffer) const
overridevirtual

Serializes the object into an MPI send buffer. Used by the simulation kernel for parallel execution. See cObject for more details.

Reimplemented from cOwnedObject.

◆ parsimUnpack()

virtual void parsimUnpack ( cCommBuffer buffer)
overridevirtual

Deserializes the object from an MPI receive buffer Used by the simulation kernel for parallel execution. See cObject for more details.

Reimplemented from cOwnedObject.

◆ setBoolValue()

cMsgPar& setBoolValue ( bool  b)

Sets the value to the given bool value.

◆ setLongValue()

cMsgPar& setLongValue ( long  l)

Sets the value to the given long value.

◆ setStringValue()

cMsgPar& setStringValue ( const char *  s)

Sets the value to the given string value. The cMsgPar will make its own copy of the string. nullptr is also accepted and treated as an empty string.

◆ setDoubleValue() [1/7]

cMsgPar& setDoubleValue ( double  d)

Sets the value to the given double value.

◆ setDoubleValue() [2/7]

cMsgPar& setDoubleValue ( cStatistic res)

Sets the value to the given distribution. Every time the cMsgPar's value is asked a random number produced by res.random() will be returned.

◆ setDoubleValue() [3/7]

cMsgPar& setDoubleValue ( MathFuncNoArg  f)

Sets the value to the given math function with no arguments. Every time the cMsgPar's value is asked the function will be called.

◆ setDoubleValue() [4/7]

cMsgPar& setDoubleValue ( MathFunc1Arg  f,
double  p1 
)

Sets the value to the given math function with one argument. Every time the cMsgPar's value is asked the function will be called with p1 as an argument.

◆ setDoubleValue() [5/7]

cMsgPar& setDoubleValue ( MathFunc2Args  f,
double  p1,
double  p2 
)

Sets the value to the given math function with two arguments. Every time the cMsgPar's value is asked the function will be called with p1 and p2 as an arguments.

◆ setDoubleValue() [6/7]

cMsgPar& setDoubleValue ( MathFunc3Args  f,
double  p1,
double  p2,
double  p3 
)

Sets the value to the given math function with three arguments. Every time the cMsgPar's value is asked the function will be called with p1, p2 and p3 as an arguments.

◆ setDoubleValue() [7/7]

cMsgPar& setDoubleValue ( MathFunc4Args  f,
double  p1,
double  p2,
double  p3,
double  p4 
)

Sets the value to the given math function with four arguments. Every time the cMsgPar's value is asked the function will be called with p1, p2, p3 and p4 as an arguments.

◆ setPointerValue()

cMsgPar& setPointerValue ( void *  ptr)

Sets the value to the given pointer. The ownership of the block pointer to can be controlled using configPointer().

See also
configPointer

◆ setObjectValue()

cMsgPar& setObjectValue ( cOwnedObject obj)

Sets the value to the given object. Whether cMsgPar will take the ownership of the object depends on the getTakeOwnership() flag.

◆ setXMLValue()

cMsgPar& setXMLValue ( cXMLElement node)

Sets the value to the given cXMLElement.

◆ configPointer()

void configPointer ( VoidDelFunc  delfunc,
VoidDupFunc  dupfunc,
size_t  itemsize = 0 
)

Configures memory management for the void* pointer ('P') type. Similar to cLinkedList::configPointer().

delfuncdupfunc.itemsizebehavior
nullptrnullptr0Pointer is treated as mere pointer - no memory management. Duplication copies the pointer, and deletion does nothing.
nullptrnullptr!=0Plain memory management. Duplication is done with new char[size]+memcpy(), and deletion is done via delete.
nullptr or user's delete func.user's dupfunc.indifferentSophisticated memory management. Duplication is done by calling the user-supplied duplication function, which should do the allocation and the appropriate copying. Deletion is done by calling the user-supplied delete function, or the delete operator if it is not supplied.

◆ setTakeOwnership()

void setTakeOwnership ( bool  tk)
inline

Sets the flag that determines whether setObjectValue(cOwnedObject *) and setDoubleValue(cStatistic *) should automatically take ownership of the objects.

◆ getTakeOwnership()

bool getTakeOwnership ( ) const
inline

Returns the takeOwnership flag, see getTakeOwnership().

◆ boolValue()

bool boolValue ( )

Returns value as a boolean. The cMsgPar type must be bool (B) or a numeric type.

◆ longValue()

long longValue ( )

Returns value as long. The cMsgPar type must be types long (L), double (D), Boolean (B), function (F), distribution (T).

◆ stringValue()

const char* stringValue ( )

Returns value as const char *. Only for string (S) type.

◆ doubleValue()

double doubleValue ( )

Returns value as double. The cMsgPar type must be types long (L), double (D), function (F), Boolean (B), distribution (T).

◆ pointerValue()

void* pointerValue ( )

Returns value as a void * pointer. The cMsgPar type must be pointer (P).

◆ getObjectValue()

cOwnedObject* getObjectValue ( )

Returns value as pointer to cOwnedObject. The cMsgPar type must be pointer (O).

◆ xmlValue()

cXMLElement* xmlValue ( )

Returns value as pointer to cXMLElement. The cMsgPar type must be XML (M).

◆ getType()

char getType ( ) const

Returns type character.

◆ isNumeric()

bool isNumeric ( ) const

Returns true if the stored value is of a numeric type.

◆ isConstant()

bool isConstant ( ) const

Returns true if the value is constant. It returns true if the type is 'L', 'D', 'B', or 'S', that is, the object stores a long, double, boolean or string constant.

◆ hasChanged()

bool hasChanged ( )

Returns true if the value has changed since the last hasChanged() call. Side effect: clears the 'changed' flag, so a next call will return false.

◆ convertToConst()

void convertToConst ( )

Replaces the object value with its evaluation (a double). Equivalent to setValue('D', this->doubleValue()).

◆ equalsTo()

bool equalsTo ( cMsgPar par)

Compares the stored values. The two objects must have the same type character and the same value to be equal.

◆ parse()

virtual bool parse ( const char *  text,
char  type = '?' 
)
virtual

This function tries to interpret the argument text as a type typed value (L=long, S=string, etc). type=='?' (the default) means that the type is to be auto-selected. On success, cMsgPar is updated with the new value and true is returned, otherwise the function returns false. No error message is generated.

◆ operator=() [2/16]

cMsgPar& operator= ( bool  b)
inline

Equivalent to setBoolValue().

◆ operator=() [3/16]

cMsgPar& operator= ( const char *  s)
inline

Equivalent to setStringValue().

◆ operator=() [4/16]

cMsgPar& operator= ( char  c)
inline

Converts the argument to long, and calls setLongValue().

◆ operator=() [5/16]

cMsgPar& operator= ( unsigned char  c)
inline

Converts the argument to long, and calls setLongValue().

◆ operator=() [6/16]

cMsgPar& operator= ( int  i)
inline

Converts the argument to long, and calls setLongValue().

◆ operator=() [7/16]

cMsgPar& operator= ( unsigned int  i)
inline

Converts the argument to long, and calls setLongValue().

◆ operator=() [8/16]

cMsgPar& operator= ( short  i)
inline

Converts the argument to long, and calls setLongValue().

◆ operator=() [9/16]

cMsgPar& operator= ( unsigned short  i)
inline

Converts the argument to long, and calls setLongValue().

◆ operator=() [10/16]

cMsgPar& operator= ( long  l)
inline

Equivalent to setLongValue().

◆ operator=() [11/16]

cMsgPar& operator= ( unsigned long  l)
inline

Converts the argument to long, and calls setLongValue().

◆ operator=() [12/16]

cMsgPar& operator= ( double  d)
inline

Equivalent to setDoubleValue().

◆ operator=() [13/16]

cMsgPar& operator= ( long double  d)
inline

Converts the argument to double, and calls setDoubleValue().

◆ operator=() [14/16]

cMsgPar& operator= ( void *  ptr)
inline

Equivalent to setPointerValue().

◆ operator=() [15/16]

cMsgPar& operator= ( cOwnedObject obj)
inline

Equivalent to setObjectValue().

◆ operator=() [16/16]

cMsgPar& operator= ( cXMLElement node)
inline

Equivalent to setXMLValue().

◆ operator bool()

operator bool ( )
inline

Equivalent to boolValue().

◆ operator const char *()

operator const char * ( )
inline

Equivalent to stringValue().

◆ operator char()

operator char ( )
inline

Calls longValue() and converts the result to char.

◆ operator unsigned char()

operator unsigned char ( )
inline

Calls longValue() and converts the result to unsigned char.

◆ operator int()

operator int ( )
inline

Calls longValue() and converts the result to int.

◆ operator unsigned int()

operator unsigned int ( )
inline

Calls longValue() and converts the result to unsigned int.

◆ operator short()

operator short ( )
inline

Calls longValue() and converts the result to short.

◆ operator unsigned short()

operator unsigned short ( )
inline

Calls longValue() and converts the result to unsigned short.

◆ operator long()

operator long ( )
inline

Equivalent to longValue().

◆ operator unsigned long()

operator unsigned long ( )
inline

Calls longValue() and converts the result to unsigned long.

◆ operator double()

operator double ( )
inline

Equivalent to doubleValue().

◆ operator long double()

operator long double ( )
inline

Calls doubleValue() and converts the result to long double.

◆ operator void *()

operator void * ( )
inline

Equivalent to pointerValue().

◆ operator cOwnedObject *()

operator cOwnedObject * ( )
inline

Equivalent to getObjectValue().

◆ operator cXMLElement *()

operator cXMLElement * ( )
inline

Equivalent to xmlValue().


The documentation for this class was generated from the following file: