CDPParameter Class
The CDPParameter class is used for persistent values (parameters) that seldom change. More...
Header: | #include <CDPParameter/CDPParameter.h> |
Inherits: | CDPObject |
Inherited By: |
Public Functions
CDPParameter() | |
virtual | ~CDPParameter() |
virtual void | ConnectTo(const char *pzRemotePropertyName) |
virtual void | Disconnect() |
virtual const char * | GetRouting() const |
virtual CDPPropertyBase::RoutingStatus_e | GetRoutingStatus() const |
double | PreviousValue() const |
void | Save() |
virtual void | SetValue(double newValue) |
std::string | Unit() |
double | Value() const |
operator double() const | |
CDPParameter & | operator=(int newValue) |
CDPParameter & | operator=(float newValue) |
CDPParameter & | operator=(double newValue) |
CDPParameter & | operator=(const CDPParameter &p) |
CDPParameter & | operator=(const CDPPropertyBase &p) |
Reimplemented Public Functions
virtual void | Configure(const char *xml) override |
virtual void | Configure(XMLElementEx *pParameterElement) override |
virtual void | Create(const char *name, CDPComponent *pParent) override |
virtual void | Destroy() override |
virtual CDP::StudioAPI::CDPValueType | GetNodeValueType() const override |
virtual CDP::StudioAPI::CDPVariantValue | GetVariantValue() const override |
virtual void | SetProperty(std::string propertyName, std::string propertyValue) override |
virtual void | SetPropertyHandler(CDPPropertyBase *pProp) override |
virtual void | SetVariantValue(const CDP::StudioAPI::CDPVariantValue &value) override |
virtual bool | ValidatePropertyHandler(CDP::StudioAPI::CDPVariantValue &newValue, CDPPropertyBase *property) override |
- 37 public functions inherited from CDPObject
- 46 public functions inherited from CDPBaseObject
- 26 public functions inherited from CDP::StudioAPI::CDPNode
- 22 public functions inherited from CDP::StudioAPI::ICDPNode
Additional Inherited Members
- 6 static public members inherited from CDPObject
- 1 static public member inherited from CDPBaseObject
- 13 protected functions inherited from CDPObject
- 1 protected function inherited from CDP::StudioAPI::CDPNode
- 7 protected variables inherited from CDPObject
- 9 protected variables inherited from CDPBaseObject
- 1 static protected member inherited from CDPObject
Detailed Description
The CDPParameter class is used for persistent values (parameters) that seldom change.
CDPParmeters are typically set by a service-engineer on system commisioning, or occasionally, from code. Whenever something in a CDPParameter changes, it is automatically saved to the configuration file (typically the parent Component file).
The CDPParameter reads its value from the configuration on startup, effectively restoring the value that was last set.
Note: If you use CDPParameters for values that change frequently, be aware that each change to the CDPParameter causes a full rewrite of the configuration file of the CDPComponent that the CDPParameter is a member of.
To use a CDPParameter from code, go into your model in Configure mode (or Code mode) and add a CDPParameter to your model. Now the parameter can be used as a normal C++ variable (double).
It is possible to set a Minimum and Maximum value that a parameter can have; this limit is enforced whenever the value is written.
To test if CDPParameter Mode is less than 1:
if (Mode<1) HandleMode0AndBelow();
To assign a value to Mode:
Mode = 1.0;
To get the previous value of Mode:
double prev = Mode.PreviousValue();
To get the time last changed and compare it with now-time:
double parameterTime = CDPTime::ConvertGivenTimeToDouble(Mode.GetProperty("TimeLastChanged").c_str(),true,CDP_UNIX_No_Ms); if((CDPTime::GlobalClock()-parameterTime)<2.0) ParameterWasModifiedLessThanTwoSecondsAgo();
CDPParameters can route their property Value from other CDPProperties in the system. The Routing is typically set in the configuration, but can also be set using SetRouting(). Note that the Routing is the path to a CDPProperty, and that even when a parameter is routed, the min/max limiting is still in effect.
if(condition1()) Mode.SetProperty("Routing",m_strAlternateRouting); else Mode.SetProperty("Routing",""); // no routing
Note: Any change of Routing, Value, Unit, Description, etc. will cause the CDPParameter parent CDPComponent file to be saved.
Properties
Property name | Description |
Unit | Parameter value unit, such as 'kg', 'm', 'm/s'. |
Value | Parameter value. |
Min | Minimum value limit. |
Max | Maximum value limit. |
PreviousValue | Value before last change. |
TimeLastChanged | Time when parameter was last changed, format 'day DD mon YYYY HH_MM_SS', as 'Sat 31 Jun 2004 23:10:00'. |
Routing | Routing of the parameter. |
Member Function Documentation
CDPParameter::CDPParameter()
Constructs a CDPParameter.
[virtual]
CDPParameter::~CDPParameter()
Destructs the instance.
[override virtual]
void CDPParameter::Configure(const char *xml)
Reimplemented from CDPObject::Configure().
Reads parameter value from .xml buffer. Called from owner (parent) Configure(...).
[override virtual]
void CDPParameter::Configure(XMLElementEx *pParameterElement)
Reimplemented from CDPObject::Configure().
Reads the parameter configuration and sets up the configured Min and Max limits for the parameter
If Min and Max are equal, Minimum and maximum limits are not enforced.
[virtual]
void CDPParameter::ConnectTo(const char *pzRemotePropertyName)
Connects the value property to get values from a remote property
[override virtual]
void CDPParameter::Create(const char *name, CDPComponent *pParent)
Reimplemented from CDPObject::Create().
Creates parameter instance.
[override virtual]
void CDPParameter::Destroy()
Reimplemented from CDPBaseObject::Destroy().
Does pre-destructor stuff, like signaling to other objects that the component is about to die.
This method should reverse what whas done in Create().
[virtual]
void CDPParameter::Disconnect()
Disconnects the value property
[override virtual]
CDP::StudioAPI::CDPValueType CDPParameter::GetNodeValueType() const
Reimplemented from ICDPNode::GetNodeValueType().
Returns the value type of the node.
[virtual]
const char *CDPParameter::GetRouting() const
Returns the current routing of the value property
[virtual]
CDPPropertyBase::RoutingStatus_e CDPParameter::GetRoutingStatus() const
Returns the routing status of the value property
[override virtual]
CDP::StudioAPI::CDPVariantValue CDPParameter::GetVariantValue() const
Reimplemented from ICDPNode::GetVariantValue().
Returns the variant value.
double CDPParameter::PreviousValue() const
Returns the previous value.
void CDPParameter::Save()
Saves parameter value by doing a blocking call to the parent component to make it save the file.
Note: This function can potentially block for several seconds.
[override virtual]
void CDPParameter::SetProperty(std::string propertyName, std::string propertyValue)
Reimplemented from CDPBaseObject::SetProperty().
Sets a property of the object.
Called by MessageSetProperty after property name and value has been figured out.
[override virtual]
void CDPParameter::SetPropertyHandler(CDPPropertyBase *pProp)
Reimplemented from CDPObject::SetPropertyHandler().
This is called whenever one of the following properties changes: value, routing, minLimit, maxLimit.
[virtual]
void CDPParameter::SetValue(double newValue)
Sets new value.
Preferrably use the assignment operators below when setting value. Override this method to add custom functinality when parameter is changed.
[override virtual]
void CDPParameter::SetVariantValue(const CDP::StudioAPI::CDPVariantValue &value)
Reimplemented from CDPNode::SetVariantValue().
Sets new value to the parameter.
std::string CDPParameter::Unit()
Returns the unit of the parameter.
[override virtual]
bool CDPParameter::ValidatePropertyHandler(CDP::StudioAPI::CDPVariantValue &newValue, CDPPropertyBase *property)
Reimplemented from CDPObject::ValidatePropertyHandler().
Makes sure that the newValue does not go outside the value limits set by Min and Max.
double CDPParameter::Value() const
Returns the value of the property.
CDPParameter::operator double() const
Returns the current value of the parameter
CDPParameter &CDPParameter::operator=(int newValue)
Assigns new value to parameter and sets save flag if value is changed.
CDPParameter &CDPParameter::operator=(float newValue)
Assigns new value to parameter and sets save flag if value is changed.
CDPParameter &CDPParameter::operator=(double newValue)
Assigns new value to parameter and sets save flag if value is changed.
CDPParameter &CDPParameter::operator=(const CDPParameter &p)
Assigns new value to parameter and sets save flag if value is changed.
CDPParameter &CDPParameter::operator=(const CDPPropertyBase &p)
Get started with CDP Studio today
Let us help you take your great ideas and turn them into the products your customer will love.