cMsgPar objects store a (string, bool, double, etc) value, and can be attached to cMessage objects. More...
#include <cmsgpar.h>
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 objects store a (string, bool, double, etc) value, and can be attached to cMessage objects.
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().
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.
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.
bool cMsgPar::boolValue | ( | ) |
Returns value as a boolean.
The cMsgPar type must be bool (B) or a numeric type.
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::convertToConst | ( | ) |
Replaces the object value with its evaluation (a double).
Equivalent to setValue('D', this->doubleValue())
.
virtual std::string cMsgPar::detailedInfo | ( | ) | const [virtual] |
double cMsgPar::doubleValue | ( | ) |
Returns value as double.
The cMsgPar type must be types long (L), double (D), function (F), Boolean (B), distribution (T).
virtual cMsgPar* cMsgPar::dup | ( | ) | const [inline, virtual] |
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 void cMsgPar::forEachChild | ( | cVisitor * | v | ) | [virtual] |
_OPPDEPRECATED std::string cMsgPar::getAsText | ( | ) | const [inline] |
DEPRECATED.
Same as str().
cOwnedObject* cMsgPar::getObjectValue | ( | ) |
Returns value as pointer to cOwnedObject.
The cMsgPar type must be pointer (O).
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.
virtual std::string cMsgPar::info | ( | ) | const [virtual] |
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.
long cMsgPar::longValue | ( | ) |
Returns value as long.
The cMsgPar type must be types long (L), double (D), Boolean (B), function (F), distribution (T).
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 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.
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.
void* cMsgPar::pointerValue | ( | ) |
Returns value as a void * pointer.
The cMsgPar type must be pointer (P).
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::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 | ( | 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 | ( | 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 | ( | 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 | ( | 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.
_OPPDEPRECATED bool cMsgPar::setFromText | ( | const char * | text, | |
char | type = '?' | |||
) | [inline] |
DEPRECATED.
Same as parse().
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::setPointerValue | ( | void * | ptr | ) |
Sets the value to the given pointer.
The ownership of the block pointer to can be controlled using configPointer().
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.
const char* cMsgPar::stringValue | ( | ) |
Returns value as const char *.
Only for string (S) type.
cXMLElement* cMsgPar::xmlValue | ( | ) |
Returns value as pointer to cXMLElement.
The cMsgPar type must be XML (M).