OMNeT++ API 6.1
Discrete Event Simulation Library
cParImpl Class Referenceabstract

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, cObjectParImpl, cXMLParImpl.

Inheritance diagram for cParImpl:
[legend]

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 isMutable () const
 
virtual bool isExpression () const
 
virtual bool isShared () const
 
virtual bool containsValue () const
 
virtual bool isSet () const
 
virtual void setIsVolatile (bool f)
 
virtual void setIsMutable (bool f)
 
virtual void setIsShared (bool f)
 
virtual void setIsSet (bool f)
 
virtual const char * getUnit () const
 
virtual void setUnit (const char *s)
 
virtual const char * getBaseDirectory () const
 
virtual void setBaseDirectory (const char *s)
 
virtual void setSourceLocation (const FileLine &loc)
 
virtual void clearSourceLocation ()
 
virtual const FileLinegetSourceLocation () const
 
Setter functions. Note that overloaded assignment operators also exist.
virtual void setBoolValue (bool b)=0
 
virtual void setIntValue (intval_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 setObjectValue (cObject *object)=0
 
virtual void setXMLValue (cXMLElement *node)=0
 
virtual void setExpression (cExpression *e)=0
 
Getter functions.
virtual bool boolValue (cComponent *context) const =0
 
virtual intval_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 cObjectobjectValue (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)=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 cObjectgetThisPtr () const
 
virtual std::string str () const
 
virtual std::ostream & printOn (std::ostream &os) const
 
virtual cObjectgetOwner () const
 
virtual bool isOwnedObject () const
 
virtual bool isSoftOwner () const
 
virtual void forEachChild (cVisitor *v)
 
cObjectfindObject (const char *name, bool deep=true)
 
virtual cClassDescriptorgetDescriptor () const
 
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 void parse (const char *text, FileLine loc)=0
 
virtual int compare (const cParImpl *other) const
 
virtual void forEachChild (cVisitor *v, cComponent *context)
 
virtual void forEachChild (cVisitor *v)
 
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 cObjectParImpl, cStringParImpl, cBoolParImpl, cDoubleParImpl, cIntParImpl, and cXMLParImpl.

◆ parsimPack()

virtual void parsimPack ( cCommBuffer buffer) const
overridevirtual

Redefined to throw a "packing not supported" exception.

Reimplemented from cNamedObject.

◆ parsimUnpack()

virtual void parsimUnpack ( cCommBuffer buffer)
overridevirtual

Redefined to throw a "packing not supported" exception.

Reimplemented from cNamedObject.

◆ getType()

virtual Type getType ( ) const
pure virtual

Returns the parameter type.

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

◆ isNumeric()

virtual bool isNumeric ( ) const
pure virtual

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

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

◆ isVolatile()

virtual bool isVolatile ( ) const
inlinevirtual

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

◆ isMutable()

virtual bool isMutable ( ) const
inlinevirtual

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

◆ 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.

◆ setIsMutable()

virtual void setIsMutable ( bool  f)
inlinevirtual

Sets the isMutable flag.

◆ 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
inlinevirtual

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)
inlinevirtual

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

◆ getBaseDirectory()

virtual const char* getBaseDirectory ( ) const
inlinevirtual

Returns the base directory for interpreting relative path names in the expression.

◆ setBaseDirectory()

virtual void setBaseDirectory ( const char *  s)
inlinevirtual

Sets the base directory for interpreting relative path names in the expression (e.g. in xmldoc()).

◆ setSourceLocation()

virtual void setSourceLocation ( const FileLine loc)
virtual

Sets the value returned by getSourceLocation().

◆ clearSourceLocation()

virtual void clearSourceLocation ( )
virtual

Clears the value returned by getSourceLocation().

◆ getSourceLocation()

virtual const FileLine& getSourceLocation ( ) const
inlinevirtual

Returns the file:line info where this parameter was parsed from. Returns a blank object if no such info is available.

◆ setBoolValue()

virtual void setBoolValue ( bool  b)
pure virtual

Sets the value to the given bool value.

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

◆ setIntValue()

virtual void setIntValue ( intval_t  l)
pure virtual

Sets the value to the given integer value.

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

◆ setDoubleValue()

virtual void setDoubleValue ( double  d)
pure virtual

Sets the value to the given double value.

Implemented in cStringParImpl, cObjectParImpl, cBoolParImpl, cDoubleParImpl, 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 cStringParImpl, cObjectParImpl, cBoolParImpl, cDoubleParImpl, 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().

◆ setObjectValue()

virtual void setObjectValue ( cObject object)
pure virtual

Sets the value to the given object.

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

◆ setXMLValue()

virtual void setXMLValue ( cXMLElement node)
pure virtual

Sets the value to the given cXMLElement.

Implemented in cStringParImpl, cObjectParImpl, cBoolParImpl, cDoubleParImpl, 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 cStringParImpl, cObjectParImpl, cBoolParImpl, cDoubleParImpl, 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 cStringParImpl, cObjectParImpl, cBoolParImpl, cDoubleParImpl, cIntParImpl, and cXMLParImpl.

◆ intValue()

virtual intval_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 cStringParImpl, cObjectParImpl, cBoolParImpl, cDoubleParImpl, 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 cStringParImpl, cObjectParImpl, cBoolParImpl, cDoubleParImpl, 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 cStringParImpl, cObjectParImpl, cBoolParImpl, cDoubleParImpl, 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 cStringParImpl, cObjectParImpl, cBoolParImpl, cDoubleParImpl, cIntParImpl, and cXMLParImpl.

◆ objectValue()

virtual cObject* objectValue ( cComponent context) const
pure virtual

Returns value as pointer to a cObject. The cParImpl type must be OBJECT.

Implemented in cStringParImpl, cObjectParImpl, cBoolParImpl, cDoubleParImpl, 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 cStringParImpl, cObjectParImpl, cBoolParImpl, cDoubleParImpl, cIntParImpl, and cXMLParImpl.

◆ getExpression()

virtual cExpression* getExpression ( ) const
pure virtual

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

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

◆ convertToConst()

virtual void convertToConst ( cComponent context)
pure virtual

If the parameter contains an expression, this method replaces the stored expression with its evaluation. It preserves the stored file/line info, which may or may not be what is intended.

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

◆ parse()

virtual void parse ( const char *  text,
FileLine  loc 
)
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 cStringParImpl, cObjectParImpl, cBoolParImpl, cDoubleParImpl, 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 cStringParImpl, cObjectParImpl, cBoolParImpl, cDoubleParImpl, cIntParImpl, and cXMLParImpl.

◆ forEachChild() [1/2]

virtual void forEachChild ( cVisitor v,
cComponent context 
)
inlinevirtual

Needed for cPar's forEachChild().

Reimplemented in cObjectParImpl, and cXMLParImpl.

◆ 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.)

◆ forEachChild() [2/2]

virtual void forEachChild

Enables traversing the object tree, performing some operation on each object. The operation is encapsulated in the particular subclass of cVisitor.

This method should be redefined in every subclass to call v->visit(obj) for every obj object contained.


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