OMNeT++ Simulation Library  5.6.1
cParImpl Class Referenceabstract

#include <cparimpl.h>

Description

Internal class that stores values for cPar objects.

cPar delegates almost all methods to cParImpl. Delegation is used to conserve memory by using shared storage for module parameters that have the same values.

cParImpl is an abstract base class, which supports several data types via subclasses: cIntParImpl, cDoubleParImpl, cBoolParImpl, cStringParImpl, cXMLParImpl.

Inheritance diagram for cParImpl:
cNamedObject cObject cBoolParImpl cDoubleParImpl cIntParImpl cStringParImpl cXMLParImpl

Public Member Functions

Constructors, destructor, assignment.
 cParImpl ()
 
 cParImpl (const cParImpl &other)
 
virtual ~cParImpl ()
 
cParImploperator= (const cParImpl &otherpar)
 
Redefined cObject member functions
virtual cParImpldup () const override
 
virtual void parsimPack (cCommBuffer *buffer) const override
 
virtual void parsimUnpack (cCommBuffer *buffer) override
 
Owner component, type, flags.
virtual Type getType () const =0
 
virtual bool isNumeric () const =0
 
virtual bool isVolatile () const
 
virtual bool isExpression () const
 
virtual bool isShared () const
 
virtual bool containsValue () const
 
virtual bool isSet () const
 
virtual void setIsVolatile (bool f)
 
virtual void setIsShared (bool f)
 
virtual void setIsSet (bool f)
 
virtual const char * getUnit () const
 
virtual void setUnit (const char *s)
 
Setter functions. Note that overloaded assignment operators also exist.
virtual void setBoolValue (bool b)=0
 
virtual void setIntValue (intpar_t l)=0
 
virtual void setDoubleValue (double d)=0
 
virtual void setStringValue (const char *s)=0
 
virtual void setStringValue (const std::string &s)
 
virtual void setXMLValue (cXMLElement *node)=0
 
virtual void setExpression (cExpression *e)=0
 
Getter functions.
virtual bool boolValue (cComponent *context) const =0
 
virtual intpar_t intValue (cComponent *context) const =0
 
virtual double doubleValue (cComponent *context) const =0
 
virtual const char * stringValue (cComponent *context) const =0
 
virtual std::string stdstringValue (cComponent *context) const =0
 
virtual cXMLElementxmlValue (cComponent *context) const =0
 
virtual cExpressiongetExpression () const =0
 
- 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)
 
virtual ~cObject ()
 
virtual const char * getClassName () const
 
bool isName (const char *s) const
 
virtual const char * getFullName () const
 
virtual std::string getFullPath () const
 
const cObjectgetThisPtr () const
 
virtual std::string str () const
 
virtual _OPPDEPRECATED std::string info () const
 
virtual _OPPDEPRECATED std::string detailedInfo () const
 
virtual cObjectgetOwner () const
 
virtual bool isOwnedObject () const
 
virtual void forEachChild (cVisitor *v)
 
cObjectfindObject (const char *name, bool deep=true)
 
void copyNotSupported () const
 

Static Public Member Functions

Statistics.
static long getTotalParImplObjectCount ()
 
static long getLiveParImplObjectCount ()
 
static void resetParImplObjectCounters ()
 

Miscellaneous utility functions.

virtual void convertToConst (cComponent *context)=0
 
virtual bool containsConstSubexpressions () const
 
virtual void evaluateConstSubexpressions (cComponent *context)
 
virtual void parse (const char *text)=0
 
virtual int compare (const cParImpl *other) const
 
virtual void forEachChild (cVisitor *v, cComponent *context)
 
static cParImplcreateWithType (Type type)
 

Additional Inherited Members

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

Constructor & Destructor Documentation

◆ cParImpl() [1/2]

cParImpl ( )
explicit

Constructor.

◆ cParImpl() [2/2]

cParImpl ( const cParImpl other)
inline

Copy constructor.

◆ ~cParImpl()

virtual ~cParImpl ( )
virtual

Destructor.

Member Function Documentation

◆ operator=()

cParImpl& operator= ( const cParImpl otherpar)

Assignment operator.

◆ dup()

virtual cParImpl* dup ( ) const
overridevirtual

Redefined change return type to cParImpl.

Reimplemented from cObject.

Reimplemented in cBoolParImpl, cDoubleParImpl, cStringParImpl, cIntParImpl, and cXMLParImpl.

◆ parsimPack()

virtual void parsimPack ( cCommBuffer buffer) const
overridevirtual

Serializes the object into a buffer.

Reimplemented from cNamedObject.

Reimplemented in cBoolParImpl, cDoubleParImpl, cStringParImpl, cIntParImpl, and cXMLParImpl.

◆ parsimUnpack()

virtual void parsimUnpack ( cCommBuffer buffer)
overridevirtual

Deserializes the object from a buffer.

Reimplemented from cNamedObject.

Reimplemented in cBoolParImpl, cDoubleParImpl, cStringParImpl, cIntParImpl, and cXMLParImpl.

◆ getType()

virtual Type getType ( ) const
pure virtual

Returns the parameter type.

Implemented in cBoolParImpl, cDoubleParImpl, cStringParImpl, cIntParImpl, and cXMLParImpl.

◆ isNumeric()

virtual bool isNumeric ( ) const
pure virtual

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

Implemented in cBoolParImpl, cDoubleParImpl, cStringParImpl, cIntParImpl, and cXMLParImpl.

◆ isVolatile()

virtual bool isVolatile ( ) const
inlinevirtual

Returns true if this parameter is marked in the NED file as "volatile".

◆ isExpression()

virtual bool isExpression ( ) const
inlinevirtual

Returns false if the stored value is a constant, and true if it is an expression. (It is not examined whether the expression yields a constant value.)

◆ isShared()

virtual bool isShared ( ) const
inlinevirtual

Used by cPar only: Returns true if this object is shared among multiple cPars.

◆ containsValue()

virtual bool containsValue ( ) const
inlinevirtual

Returns true if the parameter contains a value. Note that isSet() may still return true or false.

◆ isSet()

virtual bool isSet ( ) const
inlinevirtual

Used by cPar only: Returns true if the parameter value is set, false otherwise (i.e. if the object contains no value or the current value is just a default).

◆ setIsVolatile()

virtual void setIsVolatile ( bool  f)
inlinevirtual

Sets the isVolatile flag. NOTE: It may be necessary to invoke convertToConst(cComponent *context) as well.

◆ setIsShared()

virtual void setIsShared ( bool  f)
inlinevirtual

Sets the isShared flag.

◆ setIsSet()

virtual void setIsSet ( bool  f)
inlinevirtual

Sets the isSet flag.

◆ getUnit()

virtual const char* getUnit ( ) const
virtual

Returns the parameter's unit ("s", "mW", "Hz", "bps", etc), as declared in the @unit property of the parameter in NED. Unit is only meaningful with numeric parameters.

◆ setUnit()

virtual void setUnit ( const char *  s)
virtual

Initialize the parameter's unit (normally from the @unit property).

◆ setBoolValue()

virtual void setBoolValue ( bool  b)
pure virtual

Sets the value to the given bool value.

Implemented in cBoolParImpl, cDoubleParImpl, cStringParImpl, cIntParImpl, and cXMLParImpl.

◆ setIntValue()

virtual void setIntValue ( intpar_t  l)
pure virtual

Sets the value to the given integer value.

Implemented in cBoolParImpl, cDoubleParImpl, cStringParImpl, cIntParImpl, and cXMLParImpl.

◆ setDoubleValue()

virtual void setDoubleValue ( double  d)
pure virtual

Sets the value to the given double value.

Implemented in cBoolParImpl, cDoubleParImpl, cStringParImpl, cIntParImpl, and cXMLParImpl.

◆ setStringValue() [1/2]

virtual void setStringValue ( const char *  s)
pure virtual

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

Implemented in cBoolParImpl, cDoubleParImpl, cStringParImpl, cIntParImpl, and cXMLParImpl.

◆ setStringValue() [2/2]

virtual void setStringValue ( const std::string &  s)
inlinevirtual

Sets the value to the given string value.

References cParImpl::setStringValue().

Referenced by cParImpl::setStringValue().

◆ setXMLValue()

virtual void setXMLValue ( cXMLElement node)
pure virtual

Sets the value to the given cXMLElement.

Implemented in cBoolParImpl, cDoubleParImpl, cStringParImpl, cIntParImpl, and cXMLParImpl.

◆ setExpression()

virtual void setExpression ( cExpression e)
pure virtual

Sets the value to the given expression. This object will assume the responsibility to delete the expression object.

Note: if the parameter is marked as non-volatile (isVolatile()==false), one should not set an expression as value. This is not enforced by cParImpl though.

Implemented in cBoolParImpl, cDoubleParImpl, cStringParImpl, cIntParImpl, and cXMLParImpl.

◆ boolValue()

virtual bool boolValue ( cComponent context) const
pure virtual

Returns value as a boolean. The cParImpl type must be BOOL.

Implemented in cBoolParImpl, cDoubleParImpl, cStringParImpl, cIntParImpl, and cXMLParImpl.

◆ intValue()

virtual intpar_t intValue ( cComponent context) const
pure virtual

Returns value as an integer. The cParImpl type must be INT. Note: Implicit conversion from DOUBLE is intentionally missing.

Implemented in cBoolParImpl, cDoubleParImpl, cStringParImpl, cIntParImpl, and cXMLParImpl.

◆ doubleValue()

virtual double doubleValue ( cComponent context) const
pure virtual

Returns value as a double. The cParImpl type must be DOUBLE. Note: Implicit conversion from INT is intentionally missing.

Implemented in cBoolParImpl, cDoubleParImpl, cStringParImpl, cIntParImpl, and cXMLParImpl.

◆ stringValue()

virtual const char* stringValue ( cComponent context) const
pure virtual

Returns value as const char *. The cParImpl type must be STRING. This method may only be invoked when the parameter's value is a string constant and not the result of expression evaluation, otherwise an error is thrown. This practically means this method cannot be used on parameters declared as "volatile string" in NED; they can only be accessed using stdstringValue().

Implemented in cBoolParImpl, cDoubleParImpl, cStringParImpl, cIntParImpl, and cXMLParImpl.

◆ stdstringValue()

virtual std::string stdstringValue ( cComponent context) const
pure virtual

Returns value as string. The cParImpl type must be STRING.

Implemented in cBoolParImpl, cDoubleParImpl, cStringParImpl, cIntParImpl, and cXMLParImpl.

◆ xmlValue()

virtual cXMLElement* xmlValue ( cComponent context) const
pure virtual

Returns value as pointer to cXMLElement. The cParImpl type must be XML.

Implemented in cBoolParImpl, cDoubleParImpl, cStringParImpl, cIntParImpl, and cXMLParImpl.

◆ getExpression()

virtual cExpression* getExpression ( ) const
pure virtual

Returns pointer to the expression stored by the object, or nullptr.

Implemented in cBoolParImpl, cDoubleParImpl, cStringParImpl, cIntParImpl, and cXMLParImpl.

◆ convertToConst()

virtual void convertToConst ( cComponent context)
pure virtual

Replaces for non-const values, replaces the stored expression with its evaluation.

Implemented in cBoolParImpl, cDoubleParImpl, cStringParImpl, cIntParImpl, and cXMLParImpl.

◆ containsConstSubexpressions()

virtual bool containsConstSubexpressions ( ) const
virtual

Returns true if this expression contains const subexpressions.

◆ evaluateConstSubexpressions()

virtual void evaluateConstSubexpressions ( cComponent context)
virtual

Evaluates const subexpressions, and replaces them with their values. See cDynamicExpression::Elem::CONSTSUBEXPR.

◆ parse()

virtual void parse ( const char *  text)
pure virtual

Convert the value from string, and store the result. If the text cannot be parsed, an exception is thrown, which can be caught as std::runtime_error& if necessary.

Implemented in cBoolParImpl, cDoubleParImpl, cStringParImpl, cIntParImpl, and cXMLParImpl.

◆ createWithType()

static cParImpl* createWithType ( Type  type)
static

Factory method: creates a parameter object representing the given type.

◆ compare()

virtual int compare ( const cParImpl other) const
virtual

Compares two cParImpls, including name, type, flags, stored value or expression. Makes it possible to use cParImpl as a key in std::map or std::set.

Reimplemented in cBoolParImpl, cDoubleParImpl, cStringParImpl, cIntParImpl, and cXMLParImpl.

◆ forEachChild()

virtual void forEachChild ( cVisitor v,
cComponent context 
)
inlinevirtual

Needed for cPar's forEachChild().

Reimplemented in cXMLParImpl.

References cObject::forEachChild().

◆ getTotalParImplObjectCount()

static long getTotalParImplObjectCount ( )
inlinestatic

Returns the total number of objects created since the start of the program (or since the last reset). The counter is incremented by cOwnedObject constructor. Counter is signed to make it easier to detect if it overflows during very long simulation runs. May be useful for profiling or debugging memory leaks.

◆ getLiveParImplObjectCount()

static long getLiveParImplObjectCount ( )
inlinestatic

Returns the number of objects that currently exist in the program. The counter is incremented by cOwnedObject constructor and decremented by the destructor. May be useful for profiling or debugging memory leaks.

◆ resetParImplObjectCounters()

static void resetParImplObjectCounters ( )
inlinestatic

Reset counters used by getTotalObjectCount() and getLiveObjectCount(). (Note that getLiveObjectCount() may go negative after a reset call.)


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