#include <cpar.h>
Inheritance diagram for cPar:
cPar is used for module parameters, and its instances can also be attached to cMessage objects.
cPar supports several data types. Data types are identified by type characters. The current data type is returned by type().
For all types, an input flag can be set. In this case, the user will be asked to enter the value when the object's value is first used. The prompt string can also be specified for cPar. If no prompt string is given, the object's name will be displayed as prompt text.
NOTE: forEachChild() ignores objects stored here such as cPars in ExprElem structs (type X), cObject pointed to (type P), cStatistic (type T)
Public Member Functions | |
Constructors, destructor, assignment. | |
cPar (const cPar &other) | |
cPar (const char *name=NULL) | |
cPar (const char *name, cPar &other) | |
virtual | ~cPar () |
cPar & | operator= (const cPar &otherpar) |
Redefined cObject member functions | |
virtual cPolymorphic * | dup () const |
virtual std::string | info () const |
virtual void | writeContents (std::ostream &os) |
virtual void | forEachChild (cVisitor *v) |
virtual void | netPack (cCommBuffer *buffer) |
virtual void | netUnpack (cCommBuffer *buffer) |
Setter functions. Note that overloaded assignment operators also exist. | |
cPar & | setBoolValue (bool b) |
cPar & | setLongValue (long l) |
cPar & | setStringValue (const char *s) |
cPar & | setDoubleValue (double d) |
cPar & | setDoubleValue (cStatistic *res) |
cPar & | setDoubleValue (ExprElem *x, int n) |
cPar & | setDoubleValue (cDoubleExpression *expr) |
cPar & | setDoubleValue (MathFuncNoArg f) |
cPar & | setDoubleValue (MathFunc1Arg f, double p1) |
cPar & | setDoubleValue (MathFunc2Args f, double p1, double p2) |
cPar & | setDoubleValue (MathFunc3Args f, double p1, double p2, double p3) |
cPar & | setDoubleValue (MathFunc4Args f, double p1, double p2, double p3, double p4) |
cPar & | setPointerValue (void *ptr) |
cPar & | setObjectValue (cObject *obj) |
cPar & | setXMLValue (cXMLElement *node) |
void | configPointer (VoidDelFunc delfunc, VoidDupFunc dupfunc, size_t itemsize=0) |
void | takeOwnership (bool tk) |
bool | takeOwnership () const |
Getter functions. Note that overloaded conversion operators also exist. | |
bool | boolValue () |
long | longValue () |
const char * | stringValue () |
double | doubleValue () |
void * | pointerValue () |
cObject * | objectValue () |
cXMLElement * | xmlValue () |
Redirection | |
cPar & | setRedirection (cPar *par) |
bool | isRedirected () const |
cPar * | redirection () |
void | cancelRedirection () |
Type, prompt text, input flag, change flag. | |
char | type () const |
bool | isNumeric () const |
bool | isConstant () const |
const char * | prompt () |
void | setPrompt (const char *s) |
void | setInput (bool ip) |
bool | isInput () const |
bool | changed () |
Utility functions. | |
cPar & | read () |
void | convertToConst () |
bool | equalsTo (cPar *par) |
Convert to/from text representation. | |
virtual std::string | getAsText () const |
virtual bool | setFromText (const char *text, char type='?') |
Overloaded assignment and conversion operators. | |
cPar & | operator= (bool b) |
cPar & | operator= (const char *s) |
cPar & | operator= (char c) |
cPar & | operator= (unsigned char c) |
cPar & | operator= (int i) |
cPar & | operator= (unsigned int i) |
cPar & | operator= (short i) |
cPar & | operator= (unsigned short i) |
cPar & | operator= (long l) |
cPar & | operator= (unsigned long l) |
cPar & | operator= (double d) |
cPar & | operator= (long double d) |
cPar & | operator= (void *ptr) |
cPar & | operator= (cObject *obj) |
cPar & | 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 cObject * () | |
operator cXMLElement * () | |
Static Public Member Functions | |
Compare function | |
static int | cmpbyvalue (cObject *one, cObject *other) |
Protected Member Functions | |
Event hooks | |
virtual void | beforeChange () |
virtual void | afterChange () |
Classes | |
struct | ExprElem |
One component in a (reversed Polish) expression in a cPar; see cPar::setDoubleValue(ExprElem *,int). More... |
|
Copy constructor, creates an exact copy of the argument.
|
|
Constructor, creates a cPar with the given name and long ('L') as default type.
|
|
Constructor, creates a copy of the second argument with another name.
|
|
Destructor.
|
|
Called each time after the value of this object changed. It can be used for tracking parameter changes. This default implementation does nothing. Reimplemented in cModulePar. |
|
Called each time before the value of this object changes. It can be used for tracking parameter changes. This default implementation does nothing. |
|
Returns value as a boolean. The cPar type must be bool (B) or a numeric type. |
|
Break the redirection. The new type will be long ('L'). |
|
Returns true if the value has changed since the last changed() call. Side effect: clears the 'changed' flag, so a next call will return false. |
|
Compares two cPars by their value if they are numeric. This function can be used to sort cPar objects in a priority queue. |
|
Configures memory management for the void* pointer ('P') type. Similar to cLinkedList::configPointer().
|
|
Replaces the object value with its evaluation (a double).
Equivalent to |
|
Returns value as double. The cPar type must be types long (L), double (D), function (F), Boolean (B), distribution (T), compiled expression (C) or expression (X). |
|
Creates and returns an exact copy of this object. See cObject for more details. Reimplemented from cObject. Reimplemented in cModulePar. |
|
Compares the stored values. The two objects must have the same type character and the same value to be equal. |
|
Calls v->visit(this) for the contained object, if there's any. See cObject for more details. Reimplemented from cObject. |
|
Returns the value in text format.
|
|
Produces a one-line description of object contents into the buffer passed as argument. See cObject for more details. Reimplemented from cPolymorphic. |
|
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. |
|
Returns true if the parameter is of input type (the input flag is set).
|
|
Returns true if the stored value is of a numeric type.
|
|
Returns true if this object is redirected to another cPar.
|
|
Returns value as long. The cPar type must be types long (L), double (D), Boolean (B), function (F), distribution (T), compiled expression (C) or expression (X). |
|
Serializes the object into a PVM or MPI send buffer. Used by the simulation kernel for parallel execution. See cObject for more details. Reimplemented from cObject. |
|
Deserializes the object from a PVM or MPI receive buffer Used by the simulation kernel for parallel execution. See cObject for more details. Reimplemented from cObject. |
|
Returns value as pointer to cObject. The cPar type must be pointer (O). |
|
Equivalent to boolValue().
|
|
Calls longValue() and converts the result to char.
|
|
Equivalent to objectValue().
|
|
Equivalent to stringValue().
|
|
Equivalent to xmlValue().
|
|
Equivalent to doubleValue().
|
|
Calls longValue() and converts the result to int.
|
|
Equivalent to longValue().
|
|
Calls doubleValue() and converts the result to long double.
|
|
Calls longValue() and converts the result to short.
|
|
Calls longValue() and converts the result to unsigned char.
|
|
Calls longValue() and converts the result to unsigned int.
|
|
Calls longValue() and converts the result to unsigned long.
|
|
Calls longValue() and converts the result to unsigned short.
|
|
Equivalent to pointerValue().
|
|
Equivalent to setXMLValue().
|
|
Equivalent to setObjectValue().
|
|
Equivalent to setPointerValue().
|
|
Converts the argument to double, and calls setDoubleValue().
|
|
Equivalent to setDoubleValue().
|
|
Converts the argument to long, and calls setLongValue().
|
|
Equivalent to setLongValue().
|
|
Converts the argument to long, and calls setLongValue().
|
|
Converts the argument to long, and calls setLongValue().
|
|
Converts the argument to long, and calls setLongValue().
|
|
Converts the argument to long, and calls setLongValue().
|
|
Converts the argument to long, and calls setLongValue().
|
|
Converts the argument to long, and calls setLongValue().
|
|
Equivalent to setStringValue().
|
|
Equivalent to setBoolValue().
|
|
Assignment operator. The name member doesn't get copied; see cObject's operator=() for more details. The behavior with redirected cPar 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. |
|
Returns value as a void * pointer. The cPar type must be pointer (P). |
|
Returns the prompt text or NULL.
|
|
Reads the object value from the ini file or from the user.
|
|
Returns NULL if the cPar's value is not redirected to another cPar; otherwise it returns the pointer of that cPar. This function and isRedirected() are the only ways to determine if an object is redirected or not (type() returns the type of the other cPar: 'D', 'L' etc). |
|
Sets the value to the given bool value.
|
|
Sets the value to the given math function with four arguments. Every time the cPar's value is asked the function will be called with p1, p2, p3 and p4 as an arguments. |
|
Sets the value to the given math function with three arguments. Every time the cPar's value is asked the function will be called with p1, p2 and p3 as an arguments. |
|
Sets the value to the given math function with two arguments. Every time the cPar's value is asked the function will be called with p1 and p2 as an arguments. |
|
Sets the value to the given math function with one argument. Every time the cPar's value is asked the function will be called with p1 as an argument. |
|
Sets the value to the given math function with no arguments. Every time the cPar's value is asked the function will be called. |
|
Sets the value to the given compiled expression, subclassed from cDoubleExpression. Every time the cPar's value is asked, the evaluate() function of cDoubleExpression will be called. The passed object will be deallocated (using operator delete) from the cPar destructor, and also when the cPar object is assigned another value. |
|
Sets the value to the given Reverse Polish expression, specified as an array of ExprElem structs. Every time the cPar's value is asked the expression will be evaluated using a stack machine. The stack machine calculates in doubles. Example: the NED expression (count+1)/2 would be represented in the following way:
cPar::ExprElem *expression = new cPar::ExprElem[5]; expression[0] = &(mod->par("count")); // ptr to module parameter expression[1] = 1; expression[2] = '+'; expression[3] = 2; expression[4] = '/'; param.setDoubleValue(expression,5); |
|
Sets the value to the given distribution. Every time the cPar's value is asked a random number produced by res.random() will be returned. |
|
Sets the value to the given double value.
|
|
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, cPar is updated with the new value and true is returned, otherwise the function returns false. No error message is generated. |
|
Sets (ip=true) or clears (ip=false) the input flag.
|
|
Sets the value to the given long value.
|
|
Sets the value to the given object. Whether cPar will take the ownership of the object depends on the takeOwnership() flag. |
|
Sets the value to the given pointer. The ownership of the block pointer to can be controlled using configPointer().
|
|
Sets the prompt text.
|
|
Creates a redirection to another cPar. A cPar object can be set to stand for a value actually stored in another cPar object. This is called indirect or redirected value. When using redirection, every operation on the value (i.e. reading or changing it) will be actually done to the other cPar object. |
|
Sets the value to the given string value. The cPar will make its own copy of the string. NULL is also accepted and treated as an empty string. |
|
Sets the value to the given cXMLElement.
|
|
Returns value as const char *. Only for string (S) type. |
|
Returns the takeOwnership flag, see takeOwnership().
|
|
Sets the flag that determines whether setObjectValue(cObject *) and setDoubleValue(cStatistic *) should automatically take ownership of the objects.
|
|
Returns type character. If the "real" type is 'I', it returns the type of the object it is redirected to (for example, 'D', 'L', etc.) |
|
Writes textual information about this object to the stream. See cObject for more details. Reimplemented from cObject. |
|
Returns value as pointer to cXMLElement. The cPar type must be XML (M). |