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().
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 () |
cMsgPar & | operator= (const cMsgPar &otherpar) |
Redefined cObject member functions | |
virtual cMsgPar * | dup () 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. | |
cMsgPar & | setBoolValue (bool b) |
cMsgPar & | setLongValue (long l) |
cMsgPar & | setStringValue (const char *s) |
cMsgPar & | setDoubleValue (double d) |
cMsgPar & | setDoubleValue (cStatistic *res) |
cMsgPar & | setDoubleValue (MathFuncNoArg f) |
cMsgPar & | setDoubleValue (MathFunc1Arg f, double p1) |
cMsgPar & | setDoubleValue (MathFunc2Args f, double p1, double p2) |
cMsgPar & | setDoubleValue (MathFunc3Args f, double p1, double p2, double p3) |
cMsgPar & | setDoubleValue (MathFunc4Args f, double p1, double p2, double p3, double p4) |
cMsgPar & | setPointerValue (void *ptr) |
cMsgPar & | setObjectValue (cOwnedObject *obj) |
cMsgPar & | setXMLValue (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 () |
cOwnedObject * | getObjectValue () |
cXMLElement * | xmlValue () |
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. | |
cMsgPar & | operator= (bool b) |
cMsgPar & | operator= (const char *s) |
cMsgPar & | operator= (char c) |
cMsgPar & | operator= (unsigned char c) |
cMsgPar & | operator= (int i) |
cMsgPar & | operator= (unsigned int i) |
cMsgPar & | operator= (short i) |
cMsgPar & | operator= (unsigned short i) |
cMsgPar & | operator= (long l) |
cMsgPar & | operator= (unsigned long l) |
cMsgPar & | operator= (double d) |
cMsgPar & | operator= (long double d) |
cMsgPar & | operator= (void *ptr) |
cMsgPar & | operator= (cOwnedObject *obj) |
cMsgPar & | operator= (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 () |
cOwnedObject & | operator= (const cOwnedObject &o) |
virtual cObject * | getOwner () 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 () |
cNamedObject & | operator= (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 cObject * | getThisPtr () const |
virtual std::ostream & | printOn (std::ostream &os) const |
virtual bool | isSoftOwner () const |
cObject * | findObject (const char *name, bool deep=true) |
virtual cClassDescriptor * | getDescriptor () 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 cSoftOwner * | getOwningContext () |
typedef void(* VoidDelFunc(void *) |
Prototype for functions to free up a user-defined data structure.
typedef void*(* VoidDupFunc(void *) |
Prototype for functions to duplicate a user-defined data structure.
|
explicit |
Constructor, creates a cMsgPar with the given name and long ('L') as default type.
Constructor, creates a copy of the second argument with another name.
|
virtual |
Destructor.
|
protectedvirtual |
Called each time before the value of this object changes. It can be used for tracking parameter changes. This default implementation does nothing.
|
protectedvirtual |
Called each time after the value of this object changed. It can be used for tracking parameter changes. This default implementation does nothing.
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.
|
inlineoverridevirtual |
|
overridevirtual |
|
overridevirtual |
|
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.
|
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.
cMsgPar& setBoolValue | ( | bool | b | ) |
Sets the value to the given bool value.
cMsgPar& setLongValue | ( | long | l | ) |
Sets the value to the given long value.
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.
cMsgPar& setDoubleValue | ( | double | d | ) |
Sets the value to the given double value.
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.
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.
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.
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.
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.
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.
cMsgPar& setPointerValue | ( | void * | ptr | ) |
Sets the value to the given pointer. The ownership of the block pointer to can be controlled using configPointer().
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.
cMsgPar& setXMLValue | ( | cXMLElement * | node | ) |
Sets the value to the given cXMLElement.
void configPointer | ( | VoidDelFunc | delfunc, |
VoidDupFunc | dupfunc, | ||
size_t | itemsize = 0 |
||
) |
Configures memory management for the void* pointer ('P') type. Similar to cLinkedList::configPointer().
delfunc | dupfunc. | itemsize | behavior |
nullptr | nullptr | 0 | Pointer is treated as mere pointer - no memory management. Duplication copies the pointer, and deletion does nothing. |
nullptr | nullptr | !=0 | Plain 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. | indifferent | Sophisticated 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. |
|
inline |
Sets the flag that determines whether setObjectValue(cOwnedObject *) and setDoubleValue(cStatistic *) should automatically take ownership of the objects.
|
inline |
Returns the takeOwnership flag, see getTakeOwnership().
bool boolValue | ( | ) |
Returns value as a boolean. The cMsgPar type must be bool (B) or a numeric type.
long longValue | ( | ) |
Returns value as long. The cMsgPar type must be types long (L), double (D), Boolean (B), function (F), distribution (T).
const char* stringValue | ( | ) |
Returns value as const char *. Only for string (S) type.
double doubleValue | ( | ) |
Returns value as double. The cMsgPar type must be types long (L), double (D), function (F), Boolean (B), distribution (T).
void* pointerValue | ( | ) |
Returns value as a void * pointer. The cMsgPar type must be pointer (P).
cOwnedObject* getObjectValue | ( | ) |
Returns value as pointer to cOwnedObject. The cMsgPar type must be pointer (O).
cXMLElement* xmlValue | ( | ) |
Returns value as pointer to cXMLElement. The cMsgPar type must be XML (M).
char getType | ( | ) | const |
Returns type character.
bool isNumeric | ( | ) | const |
Returns true if the stored value is of a numeric type.
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.
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.
void convertToConst | ( | ) |
Replaces the object value with its evaluation (a double). Equivalent to setValue('D', this->doubleValue())
.
bool equalsTo | ( | cMsgPar * | par | ) |
Compares the stored values. The two objects must have the same type character and the same value to be equal.
|
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.
|
inline |
Equivalent to setBoolValue().
|
inline |
Equivalent to setStringValue().
|
inline |
Converts the argument to long, and calls setLongValue().
|
inline |
Converts the argument to long, and calls setLongValue().
|
inline |
Converts the argument to long, and calls setLongValue().
|
inline |
Converts the argument to long, and calls setLongValue().
|
inline |
Converts the argument to long, and calls setLongValue().
|
inline |
Converts the argument to long, and calls setLongValue().
|
inline |
Equivalent to setLongValue().
|
inline |
Converts the argument to long, and calls setLongValue().
|
inline |
Equivalent to setDoubleValue().
|
inline |
Converts the argument to double, and calls setDoubleValue().
|
inline |
Equivalent to setPointerValue().
|
inline |
Equivalent to setObjectValue().
|
inline |
Equivalent to setXMLValue().
|
inline |
Equivalent to boolValue().
|
inline |
Equivalent to stringValue().
|
inline |
Calls longValue() and converts the result to char.
|
inline |
Calls longValue() and converts the result to unsigned char.
|
inline |
Calls longValue() and converts the result to int.
|
inline |
Calls longValue() and converts the result to unsigned int.
|
inline |
Calls longValue() and converts the result to short.
|
inline |
Calls longValue() and converts the result to unsigned short.
|
inline |
Equivalent to longValue().
|
inline |
Calls longValue() and converts the result to unsigned long.
|
inline |
Equivalent to doubleValue().
|
inline |
Calls doubleValue() and converts the result to long double.
|
inline |
Equivalent to pointerValue().
|
inline |
Equivalent to getObjectValue().
|
inline |
Equivalent to xmlValue().