CDPBuilder Class
The CDPBuilder creates CDP object and component instances. More...
Header: | #include <CDPSystem/Application/CDPBuilder.h> |
Public Functions
CDPBuilder(const std::string &libName, const std::string &timeStamp, const std::string &revision = REVISION_STRING) | |
virtual | ~CDPBuilder() |
Static Public Members
CDP::StudioAPI::CDPNode * | CreateCDPNode(const std::string &modelName) |
CDPObject * | CreateCDPObject(const std::string &model, const std::string &shortName, CDPComponent *parent, bool callCreate = true) |
CDPBaseObject * | CreateCDPOperator(const std::string &modelName, const std::string type, const CDPPropertyBase *inputProperty) |
CDPComponent * | CreateComponent(const std::string &model, const std::string &fullName, bool callCreate = true) |
CDPComponent * | CreateComponent(const char *xml, const char *parentName = 0, bool callCreate = true) |
CDPComponent * | CreateComponent(XMLElementEx *componentElement, const char *parentName = 0, bool callCreate = true) |
void | DeleteDynamicAllocatedComponents() |
void | GenerateSuspendedAndDiskAlarm(XMLElementEx *componentElement, XMLParser &parser) |
std::string | GetLibrariesInfo() |
void | NotifyDeleted(CDP::StudioAPI::CDPNode *object) |
Protected Functions
virtual CDP::StudioAPI::CDPNode * | CreateNewCDPNode(const std::string &type) |
virtual CDPBaseObject * | CreateNewCDPOperator(const std::string &modelName, const std::string &type, const CDPPropertyBase *inputProperty) |
virtual CDPComponent * | CreateNewComponent(const std::string &type) |
virtual CDPObject * | CreateNewObject(const std::string &type) |
virtual std::string | GetLibraryInfo() const |
void | RegisterFeature(const std::string &feature) |
Detailed Description
The CDPBuilder creates CDP object and component instances.
This is the CDP factory class. It will create CDPObject and CDPComponent derived instances from models defined in the CDP library and in all external libraries linked into the CDP application.
Member Function Documentation
CDPBuilder::CDPBuilder(const std::string &libName, const std::string &timeStamp, const std::string &revision = REVISION_STRING)
Default constructs an instance of CDPBuilder.
[virtual]
CDPBuilder::~CDPBuilder()
Destructs the instance.
[static]
CDP::StudioAPI::CDPNode *CDPBuilder::CreateCDPNode(const std::string &modelName)
[static]
CDPObject *CDPBuilder::CreateCDPObject(const std::string &model, const std::string &shortName, CDPComponent *parent, bool callCreate = true)
Create CDPObject derived instance. Allocated object is automatically deleted on exit.
Throws a CDPException if component could not be created because
- Not enough available free memory
- An object with the same name already exists
- The specified model name was not found
- The parent component pointer does not point to a CDPCompoenent derived object
Note: The model name for signals is typically
"Signal<double>"
Arguments:
- model - model name of object to create
- shortName - shortname of object to create. Parent's name will be prepended to create the fullName
- parent - pointer to parent CDPComponent
- callCreate - default
true
, set tofalse
if object->Create() should not be called
Returns pointer to the created object.
[static]
CDPBaseObject *CDPBuilder::CreateCDPOperator(const std::string &modelName, const std::string type, const CDPPropertyBase *inputProperty)
Create a CDPOperator by querying all the libraries in the application. If the operator is not found, this function throws a CDPException. If the operator is found, it is allocated and put into the list of dynamically allocated objects so that it is automatically deleted on exit.
[static]
CDPComponent *CDPBuilder::CreateComponent(const std::string &model, const std::string &fullName, bool callCreate = true)
Creates CDPComponent derived component instance if it does not exist. Allocated object is automatically deleted on exit.
This function will use all registered libraries to attempt to create a component of the specified model. This is done by calling each library's CreateNewComponent() function.
Throws a CDPException if component could not be created because of
- Not enough available free memory
- A component with the same name already exists
- The specified model name was not found
- model - model name of component to create.
- fullName - full CDP name of component to create (including parent name
- callCreate - default
true
, set tofalse
if component->Create() should not be called
Returns pointer to the created component.
[static]
CDPComponent *CDPBuilder::CreateComponent(const char *xml, const char *parentName = 0, bool callCreate = true)
Instantiate and create component from .xml definition. Allocated object is automatically deleted on exit.
Opens .xml file if attribute src="fileName" present.
[static]
CDPComponent *CDPBuilder::CreateComponent(XMLElementEx *componentElement, const char *parentName = 0, bool callCreate = true)
Instantiate and create component from xml element
[virtual protected]
CDP::StudioAPI::CDPNode *CDPBuilder::CreateNewCDPNode(const std::string &type)
[virtual protected]
CDPBaseObject *CDPBuilder::CreateNewCDPOperator(const std::string &modelName, const std::string &type, const CDPPropertyBase *inputProperty)
Override this method in to create new CDPOperator types. The modelName is the (unique) name of the operator (for instance "Scaling"), the type is the Type of the operator (double, int, bool, etc) and the inputProperty is the property to send to the CDPOperator constructor.
[virtual protected]
CDPComponent *CDPBuilder::CreateNewComponent(const std::string &type)
Override this method in the derived class to instantiate components defined in the library. Parameter type is the model name of the component to create.
Typical implementation
CDPComponent* MyLibBuilder::CreateNewComponent(const std::string& type) { CDPComponent* pComponent=nullptr; if (type=="MyCustomModel1") pComponent = new MyCustomModel1; else if ( type=="MyCustomModel2" ) pComponent = new MyCustomModel2; return pComponent; }
Returns pointer to created component, or nullptr
if none created.
[virtual protected]
CDPObject *CDPBuilder::CreateNewObject(const std::string &type)
Override this method in the derived lib builder class to instantiate CDPObject derived models defined in the library. Parameter type is the model name of the component to create.
Note: The model name for signals is typically
"Signal<double>"
Typical implementation:
CDPObject* CDPBuilder::CreateNewObject(const std::string& type) { CDPObject* pObject=nullptr; if ( type=="MyAlarm" ) pObject = new MyAlarm; else if ( type=="MySignal<double>" ) pObject = new MySignal<double>; else if ( type=="MySignal<int>" ) pObject = new MySignal<int>; return pObject; }
Returns pointer to created object, or nullptr
if none created.
[static]
void CDPBuilder::DeleteDynamicAllocatedComponents()
Deletes all components and objects dynamically allocated by CDPBuilder.
[static]
void CDPBuilder::GenerateSuspendedAndDiskAlarm(XMLElementEx *componentElement, XMLParser &parser)
Call when parsing object XML file fails. Prints the error message and sets SuspendedAlarm and DiskAlarm. Finally clears parser lastErrorMessage.
[static]
std::string CDPBuilder::GetLibrariesInfo()
Returns the library name and the build date of each CDPBuilder separated by newline characters.
[virtual protected]
std::string CDPBuilder::GetLibraryInfo() const
Returns the library name and the build date of CDPBuilder.
[static]
void CDPBuilder::NotifyDeleted(CDP::StudioAPI::CDPNode *object)
Notifies that object is already deleted, so CDPBuilder will not try to delete it second time.
[protected]
void CDPBuilder::RegisterFeature(const std::string &feature)
Registers a feature which requires acquiring a license to use it.
Call this from your library builder class to disallow using the library without license.
Get started with CDP Studio today
Let us help you take your great ideas and turn them into the products your customer will love.