#include <cmsgpar.h>

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 Member Functions | |
Constructors, destructor, assignment. | |
| cMsgPar (const cMsgPar &other) | |
| cMsgPar (const char *name=NULL) | |
| cMsgPar (const char *name, cMsgPar &other) | |
| virtual | ~cMsgPar () |
| cMsgPar & | operator= (const cMsgPar &otherpar) |
Redefined cObject member functions | |
| virtual cMsgPar * | dup () const |
| virtual std::string | info () const |
| virtual std::string | detailedInfo () const |
| virtual void | forEachChild (cVisitor *v) |
| virtual void | parsimPack (cCommBuffer *buffer) |
| virtual void | parsimUnpack (cCommBuffer *buffer) |
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 std::string | str () const |
| _OPPDEPRECATED std::string | getAsText () const |
| virtual bool | parse (const char *text, char type='?') |
| _OPPDEPRECATED bool | setFromText (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 * () | |
Protected Member Functions | |
Event hooks | |
| virtual void | beforeChange () |
| virtual void | afterChange () |
| cMsgPar::cMsgPar | ( | const cMsgPar & | other | ) |
Copy constructor, creates an exact copy of the argument.
| cMsgPar::cMsgPar | ( | const char * | name = NULL |
) | [explicit] |
Constructor, creates a cMsgPar with the given name and long ('L') as default type.
| cMsgPar::cMsgPar | ( | const char * | name, | |
| cMsgPar & | other | |||
| ) | [explicit] |
Constructor, creates a copy of the second argument with another name.
| virtual cMsgPar::~cMsgPar | ( | ) | [virtual] |
Destructor.
| virtual void cMsgPar::beforeChange | ( | ) | [protected, virtual] |
Called each time before the value of this object changes.
It can be used for tracking parameter changes. This default implementation does nothing.
| virtual void cMsgPar::afterChange | ( | ) | [protected, virtual] |
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.
| virtual cMsgPar* cMsgPar::dup | ( | ) | const [inline, virtual] |
| virtual std::string cMsgPar::info | ( | ) | const [virtual] |
| virtual std::string cMsgPar::detailedInfo | ( | ) | const [virtual] |
| virtual void cMsgPar::forEachChild | ( | cVisitor * | v | ) | [virtual] |
| virtual void cMsgPar::parsimPack | ( | cCommBuffer * | buffer | ) | [virtual] |
Serializes the object into an MPI send buffer.
Used by the simulation kernel for parallel execution. See cObject for more details.
Reimplemented from cOwnedObject.
| virtual void cMsgPar::parsimUnpack | ( | cCommBuffer * | buffer | ) | [virtual] |
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& cMsgPar::setBoolValue | ( | bool | b | ) |
Sets the value to the given bool value.
| cMsgPar& cMsgPar::setLongValue | ( | long | l | ) |
Sets the value to the given long value.
| cMsgPar& cMsgPar::setStringValue | ( | const char * | s | ) |
Sets the value to the given string value.
The cMsgPar will make its own copy of the string. NULL is also accepted and treated as an empty string.
| cMsgPar& cMsgPar::setDoubleValue | ( | double | d | ) |
Sets the value to the given double value.
| cMsgPar& 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& 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& 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& 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& 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& 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& cMsgPar::setPointerValue | ( | void * | ptr | ) |
Sets the value to the given pointer.
The ownership of the block pointer to can be controlled using configPointer().
| cMsgPar& 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& cMsgPar::setXMLValue | ( | cXMLElement * | node | ) |
Sets the value to the given cXMLElement.
| void cMsgPar::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 |
| NULL | NULL | 0 | Pointer is treated as mere pointer - no memory management. Duplication copies the pointer, and deletion does nothing. |
| NULL | NULL | !=0 | Plain memory management. Duplication is done with new char[size]+memcpy(), and deletion is done via delete. |
| NULL 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. |
| void cMsgPar::setTakeOwnership | ( | bool | tk | ) | [inline] |
Sets the flag that determines whether setObjectValue(cOwnedObject *) and setDoubleValue(cStatistic *) should automatically take ownership of the objects.
| bool cMsgPar::getTakeOwnership | ( | ) | const [inline] |
Returns the takeOwnership flag, see getTakeOwnership().
| bool cMsgPar::boolValue | ( | ) |
Returns value as a boolean.
The cMsgPar type must be bool (B) or a numeric type.
| long cMsgPar::longValue | ( | ) |
Returns value as long.
The cMsgPar type must be types long (L), double (D), Boolean (B), function (F), distribution (T).
| const char* cMsgPar::stringValue | ( | ) |
Returns value as const char *.
Only for string (S) type.
| double cMsgPar::doubleValue | ( | ) |
Returns value as double.
The cMsgPar type must be types long (L), double (D), function (F), Boolean (B), distribution (T).
| void* cMsgPar::pointerValue | ( | ) |
Returns value as a void * pointer.
The cMsgPar type must be pointer (P).
| cOwnedObject* cMsgPar::getObjectValue | ( | ) |
Returns value as pointer to cOwnedObject.
The cMsgPar type must be pointer (O).
| cXMLElement* cMsgPar::xmlValue | ( | ) |
Returns value as pointer to cXMLElement.
The cMsgPar type must be XML (M).
| char cMsgPar::getType | ( | ) | const |
Returns type character.
| bool cMsgPar::isNumeric | ( | ) | const |
Returns true if the stored value is of a numeric type.
| bool cMsgPar::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 cMsgPar::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 cMsgPar::convertToConst | ( | ) |
Replaces the object value with its evaluation (a double).
Equivalent to setValue('D', this->doubleValue()).
| bool cMsgPar::equalsTo | ( | cMsgPar * | par | ) |
Compares the stored values.
The two objects must have the same type character and the same value to be equal.
| virtual std::string cMsgPar::str | ( | ) | const [virtual] |
Returns the value in text form.
| _OPPDEPRECATED std::string cMsgPar::getAsText | ( | ) | const [inline] |
DEPRECATED.
Same as str().
| virtual bool cMsgPar::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.
| _OPPDEPRECATED bool cMsgPar::setFromText | ( | const char * | text, | |
| char | type = '?' | |||
| ) | [inline] |
DEPRECATED.
Same as parse().
| cMsgPar& cMsgPar::operator= | ( | bool | b | ) | [inline] |
Equivalent to setBoolValue().
| cMsgPar& cMsgPar::operator= | ( | const char * | s | ) | [inline] |
Equivalent to setStringValue().
| cMsgPar& cMsgPar::operator= | ( | char | c | ) | [inline] |
Converts the argument to long, and calls setLongValue().
| cMsgPar& cMsgPar::operator= | ( | unsigned char | c | ) | [inline] |
Converts the argument to long, and calls setLongValue().
| cMsgPar& cMsgPar::operator= | ( | int | i | ) | [inline] |
Converts the argument to long, and calls setLongValue().
| cMsgPar& cMsgPar::operator= | ( | unsigned int | i | ) | [inline] |
Converts the argument to long, and calls setLongValue().
| cMsgPar& cMsgPar::operator= | ( | short | i | ) | [inline] |
Converts the argument to long, and calls setLongValue().
| cMsgPar& cMsgPar::operator= | ( | unsigned short | i | ) | [inline] |
Converts the argument to long, and calls setLongValue().
| cMsgPar& cMsgPar::operator= | ( | long | l | ) | [inline] |
Equivalent to setLongValue().
| cMsgPar& cMsgPar::operator= | ( | unsigned long | l | ) | [inline] |
Converts the argument to long, and calls setLongValue().
| cMsgPar& cMsgPar::operator= | ( | double | d | ) | [inline] |
Equivalent to setDoubleValue().
| cMsgPar& cMsgPar::operator= | ( | long double | d | ) | [inline] |
Converts the argument to double, and calls setDoubleValue().
| cMsgPar& cMsgPar::operator= | ( | void * | ptr | ) | [inline] |
Equivalent to setPointerValue().
| cMsgPar& cMsgPar::operator= | ( | cOwnedObject * | obj | ) | [inline] |
Equivalent to setObjectValue().
| cMsgPar& cMsgPar::operator= | ( | cXMLElement * | node | ) | [inline] |
Equivalent to setXMLValue().
| cMsgPar::operator bool | ( | ) | [inline] |
Equivalent to boolValue().
| cMsgPar::operator const char * | ( | ) | [inline] |
Equivalent to stringValue().
| cMsgPar::operator char | ( | ) | [inline] |
Calls longValue() and converts the result to char.
| cMsgPar::operator unsigned char | ( | ) | [inline] |
Calls longValue() and converts the result to unsigned char.
| cMsgPar::operator int | ( | ) | [inline] |
Calls longValue() and converts the result to int.
| cMsgPar::operator unsigned int | ( | ) | [inline] |
Calls longValue() and converts the result to unsigned int.
| cMsgPar::operator short | ( | ) | [inline] |
Calls longValue() and converts the result to short.
| cMsgPar::operator unsigned short | ( | ) | [inline] |
Calls longValue() and converts the result to unsigned short.
| cMsgPar::operator long | ( | ) | [inline] |
Equivalent to longValue().
| cMsgPar::operator unsigned long | ( | ) | [inline] |
Calls longValue() and converts the result to unsigned long.
| cMsgPar::operator double | ( | ) | [inline] |
Equivalent to doubleValue().
| cMsgPar::operator long double | ( | ) | [inline] |
Calls doubleValue() and converts the result to long double.
| cMsgPar::operator void * | ( | ) | [inline] |
Equivalent to pointerValue().
| cMsgPar::operator cOwnedObject * | ( | ) | [inline] |
Equivalent to getObjectValue().
| cMsgPar::operator cXMLElement * | ( | ) | [inline] |
Equivalent to xmlValue().
1.5.5