cParImpl Class Reference¶

API: cParImpl Class Reference
API
cParImpl Class Referenceabstract
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 cPar *targetPar) const =0
virtual intval_t intValue (cComponent *context, const cPar *targetPar) const =0
virtual double doubleValue (cComponent *context, const cPar *targetPar) const =0
virtual const char * stringValue (cComponent *context, const cPar *targetPar) const =0
virtual std::string stdstringValue (cComponent *context, const cPar *targetPar) const =0
virtual cObjectobjectValue (cComponent *context, const cPar *targetPar) const =0
virtual cXMLElementxmlValue (cComponent *context, const cPar *targetPar) 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
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, const cPar *targetPar)=0
virtual std::string unparse () const =0
virtual void parse (const char *text, FileLine loc, const cPar *targetPar)=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)

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.

Constructor & Destructor Documentation

◆ cParImpl() [1/2]

◆ cParImpl() [2/2]

cParImpl ( const cParImpl & other)
inline

Copy constructor.

References cNamedObject::cNamedObject(), and cParImpl().

◆ ~cParImpl()

virtual ~cParImpl ( )
virtual

Destructor.

Member Function Documentation

◆ operator=()

cParImpl & operator= ( const cParImpl & otherpar)

Assignment operator.

References cParImpl().

◆ dup()

virtual cParImpl * dup ( ) const
overridevirtual

Redefined change return type to cParImpl.

Reimplemented from cObject.

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

References cParImpl().

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

◆ isNumeric()

virtual bool isNumeric ( ) const
pure virtual

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

Implemented in cBoolParImpl, cDoubleParImpl, cIntParImpl, cObjectParImpl, cStringParImpl, 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, const cPar *targetPar) 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 cBoolParImpl, cDoubleParImpl, cIntParImpl, cObjectParImpl, cStringParImpl, and cXMLParImpl.

◆ setIntValue()

virtual void setIntValue ( intval_t l)
pure virtual

Sets the value to the given integer value.

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

◆ setDoubleValue()

virtual void setDoubleValue ( double d)
pure virtual

Sets the value to the given double value.

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

◆ setStringValue() [2/2]

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

Sets the value to the given string value.

References setStringValue().

Referenced by setStringValue().

◆ setObjectValue()

virtual void setObjectValue ( cObject * object)
pure virtual

Sets the value to the given object.

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

References cObject::cObject().

◆ setXMLValue()

virtual void setXMLValue ( cXMLElement * node)
pure virtual

Sets the value to the given cXMLElement.

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

◆ boolValue()

virtual bool boolValue ( cComponent * context,
const cPar * targetPar ) const
pure virtual

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

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

◆ intValue()

virtual intval_t intValue ( cComponent * context,
const cPar * targetPar ) 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, cIntParImpl, cObjectParImpl, cStringParImpl, and cXMLParImpl.

◆ doubleValue()

virtual double doubleValue ( cComponent * context,
const cPar * targetPar ) 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, cIntParImpl, cObjectParImpl, cStringParImpl, and cXMLParImpl.

◆ stringValue()

virtual const char * stringValue ( cComponent * context,
const cPar * targetPar ) 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, cIntParImpl, cObjectParImpl, cStringParImpl, and cXMLParImpl.

◆ stdstringValue()

virtual std::string stdstringValue ( cComponent * context,
const cPar * targetPar ) const
pure virtual

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

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

◆ objectValue()

virtual cObject * objectValue ( cComponent * context,
const cPar * targetPar ) const
pure virtual

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

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

References cObject::cObject().

◆ xmlValue()

virtual cXMLElement * xmlValue ( cComponent * context,
const cPar * targetPar ) const
pure virtual

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

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

◆ getExpression()

virtual cExpression * getExpression ( ) const
pure virtual

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

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

◆ convertToConst()

virtual void convertToConst ( cComponent * context,
const cPar * targetPar )
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 cBoolParImpl, cDoubleParImpl, cIntParImpl, cObjectParImpl, cStringParImpl, and cXMLParImpl.

◆ unparse()

virtual std::string unparse ( ) const
pure virtual

Returns the value in text form. As opposed to str(), unparse() returns a complete representation accepted by parse().

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

◆ parse()

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

◆ createWithType()

cParImpl * createWithType ( Type type)
static

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

References cParImpl().

◆ 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, cIntParImpl, cObjectParImpl, cStringParImpl, and cXMLParImpl.

References cParImpl().

◆ forEachChild() [1/2]

virtual void forEachChild ( cVisitor * v,
cComponent * context )
inlinevirtual

Needed for cPar's forEachChild().

Reimplemented in cObjectParImpl, and cXMLParImpl.

◆ getTotalParImplObjectCount()

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

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

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 ( cVisitor * v)
virtual

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.

Reimplemented from cObject.