• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
CDP Studio logo

CDP Studio

The no-code and full-code software development tool for distributed control systems and HMI

  • Doc
  • Why CDP
    • Software developers
    • Automation engineers
    • Managers
  • Products
    • Automation Designer
    • HMI Designer
    • Maritime HMIs
  • Services
  • Use cases
  • Pricing
  • Try CDP

CDP Studio Documentation

  • Framework - CDP Core
  • CDPBuilder
  • 5.0.0

CDPBuilder Class

The CDPBuilder creates CDPObject, CDPComponent, CDPOperator and CDPNode instances. More...

Header: #include <CDPBuilder>
  • List of all members, including inherited members

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 &model)
CDPObject *CreateCDPObject(const std::string &model, const std::string &shortName, CDPComponent *parent, bool callCreate = true)
CDPBaseObject *CreateCDPOperator(const std::string &model, 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 CDPObject, CDPComponent, CDPOperator and CDPNode instances.

This is the CDP factory class. It will create CDPObject, CDPComponent, CDPOperator and CDPNode-derived instances from code-based models defined in the CDP library and in all external libraries linked into the CDP application.

Each user-created library contains a CDPBuilder-derived class that is responsible for creating the CDPObject, CDPComponent, CDPOperator and CDPNode instances defined in the library. This class is called <library-name>Builder, where <library-name> is the name of the library.

The overloaded factory methods are declared in <library-name>Builder.cpp file that can be edited in the code editor.

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 &model)

[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 to false if object->Create() should not be called

Returns pointer to the created object.

[static] CDPBaseObject *CDPBuilder::CreateCDPOperator(const std::string &model, 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 to false 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.

The content of this document is confidential information not to be published without the consent of CDP Technologies AS.

CDP Technologies AS, www.cdpstudio.com

Get started with CDP Studio today

Let us help you take your great ideas and turn them into the products your customer will love.

Try CDP Studio for free
Why CDP Studio?

CDP Technologies AS
Hundsværgata 8,
P.O. Box 144
6001 Ålesund, Norway

Tel: +47 990 80 900
E-mail: info@cdptech.com

Company

About CDP

Contact us

Services

Partners

Blog

Developers

Get started

User manuals

Support

Document download

Release notes

My account

Follow CDP

  • LinkedIn
  • YouTube
  • GitHub

© Copyright 2025 CDP Technologies. Privacy and cookie policy.

Return to top