LuciadCPillar 2026.1.02
Loading...
Searching...
No Matches
luciad::DataType::Builder Class Referencefinal

Builder that allows DataType instances to be created. More...

#include <luciad/datamodels/DataType.h>

Public Member Functions

 Builder (Builder &&other) noexcept
 Move constructor.
 Builder (const Builder &other)
 Copy constructor.
 ~Builder ()
Builder & addAnnotation (std::shared_ptr< DataAnnotation > annotation)
 The annotation to add to the data type under construction.
Builder & addAnnotation (std::shared_ptr< IDataAnnotationFactory > annotationFactory)
 Adds an annotation factory that is invoked when build is called.
Builder & addBooleanProperty (std::string name)
 Adds a scalar property with the given name and DataType::getBooleanType() as its value type.
Builder & addDoubleProperty (std::string name)
 Adds a scalar property with the given name and DataType::getDoubleType() as its value type.
Builder & addFloatProperty (std::string name)
 Adds a scalar property with the given name and DataType::getFloatType() as its value type.
Builder & addGeometryProperty (std::string name, bool mainGeometry)
 Adds a property with the given name and DataType::getGeometryType() as its value type, marking it as this type's main geometry when mainGeometry is true.
Builder & addIntProperty (std::string name)
 Adds a scalar property with the given name and DataType::getIntType() as its value type.
Builder & addLongProperty (std::string name)
 Adds a scalar property with the given name and DataType::getLongType() as its value type.
Builder & addProperty (DataProperty property)
 The property to add to the data type under construction.
Builder & addStringProperty (std::string name)
 Adds a scalar property with the given name and DataType::getStringType() as its value type.
DataType build ()
 Build the data type, including the properties and annotations that were added to this builder.
Builder & name (std::string name)
 The name of the new data type.
Builder & operator= (Builder other) noexcept

Detailed Description

Builder that allows DataType instances to be created.

Typical usage would be create a DataType::Builder using DataType::newBuilder, specifying the data type's name. Then add the necessary DataProperty(s) and finally build() the data type. The following snippet shows how this is done for a simple example data type:

.name("TestDataType")
.addProperty(someProperty)
.addProperty(geometryProperty)
.addAnnotation(IDataAnnotationFactory::create([&](const auto& dataType) {
return std::make_shared<GeometryDataAnnotation>(DataPropertyPath::newBuilder().originType(dataType).property(geometryProperty).build());
}))
.build();

Constructor & Destructor Documentation

◆ Builder() [1/2]

luciad::DataType::Builder::Builder ( const Builder & other)

Copy constructor.

Parameters
otherthe builder to copy.

◆ Builder() [2/2]

luciad::DataType::Builder::Builder ( Builder && other)
noexcept

Move constructor.

Parameters
otherthe builder to move from.

◆ ~Builder()

luciad::DataType::Builder::~Builder ( )

Member Function Documentation

◆ addAnnotation() [1/2]

Builder & luciad::DataType::Builder::addAnnotation ( std::shared_ptr< DataAnnotation > annotation)

The annotation to add to the data type under construction.

Parameters
annotationthe annotation to add to the data type under construction.
Returns
this builder.
Exceptions
luciad::NullArgumentExceptionwhen a nullptr value is passed.

◆ addAnnotation() [2/2]

Builder & luciad::DataType::Builder::addAnnotation ( std::shared_ptr< IDataAnnotationFactory > annotationFactory)

Adds an annotation factory that is invoked when build is called.

The factory is provided with the type that is being built. This can be useful when the created annotation needs access to the type, for instance when the annotation requires a DataPropertyPath.

An example usage is:

class GeometryDataAnnotationFactory final : public IDataAnnotationFactory {
public:
explicit GeometryDataAnnotationFactory(DataProperty property) : _property(std::move(property)) {
}
std::shared_ptr<DataAnnotation> createAnnotation(const DataType& dataType) const override {
auto geometryPropertyPath = DataPropertyPath::newBuilder().originType(dataType).property(_property).build();
return std::make_shared<GeometryDataAnnotation>(std::move(geometryPropertyPath));
}
private:
DataProperty _property;
};
auto geometryProperty = DataProperty::newBuilder().name("geometry").valueType(DataType::getGeometryType()).build();
auto dataType = DataType::newBuilder()
.name("MyType")
.addProperty(geometryProperty)
.addAnnotation(std::make_shared<GeometryDataAnnotationFactory>(geometryProperty))
.build();
Parameters
annotationFactorythe factory object.
Returns
this builder.
Exceptions
luciad::NullArgumentExceptionwhen a nullptr value is passed.

◆ addBooleanProperty()

Builder & luciad::DataType::Builder::addBooleanProperty ( std::string name)

Adds a scalar property with the given name and DataType::getBooleanType() as its value type.

Use addProperty() for anything more specific.

Parameters
namethe name of the property.
Returns
this builder.
Since
2026.1

◆ addDoubleProperty()

Builder & luciad::DataType::Builder::addDoubleProperty ( std::string name)

Adds a scalar property with the given name and DataType::getDoubleType() as its value type.

Use addProperty() for anything more specific.

Parameters
namethe name of the property.
Returns
this builder.
Since
2026.1

◆ addFloatProperty()

Builder & luciad::DataType::Builder::addFloatProperty ( std::string name)

Adds a scalar property with the given name and DataType::getFloatType() as its value type.

Use addProperty() for anything more specific.

Parameters
namethe name of the property.
Returns
this builder.
Since
2026.1

◆ addGeometryProperty()

Builder & luciad::DataType::Builder::addGeometryProperty ( std::string name,
bool mainGeometry )

Adds a property with the given name and DataType::getGeometryType() as its value type, marking it as this type's main geometry when mainGeometry is true.

If the data type has a single geometry, always pass true. A type needs a main geometry for Feature::findGeometry() and for the default painters to know which property holds the shape to draw. Only a type with several geometry properties needs false, for the ones that are not its main geometry.

For the main geometry, a GeometryDataAnnotation for the property is wired internally, so there is no need to create that annotation through an IDataAnnotationFactory.

A data type has at most one main geometry. Calling this again with true throws an exception, and build() additionally rejects a type of which the second GeometryDataAnnotation came from addAnnotation() rather than from here.

The annotated case is shorthand for adding the property and then attaching its GeometryDataAnnotation through an IDataAnnotationFactory, shown below:

auto geometryProperty = DataProperty::newBuilder().name("geometry").valueType(DataType::getGeometryType()).build();
auto dataType = DataType::newBuilder()
.name("MyType")
.addProperty(geometryProperty)
.addAnnotation(std::make_shared<GeometryDataAnnotationFactory>(geometryProperty))
.build();
Parameters
namethe name of the geometry property.
mainGeometrywhether the property is this type's main geometry, annotated with a GeometryDataAnnotation. Pass true unless the data type has more than one geometry property.
Returns
this builder.
Exceptions
LogicExceptionif this data type already has a main geometry and mainGeometry is true.
Since
2026.1

◆ addIntProperty()

Builder & luciad::DataType::Builder::addIntProperty ( std::string name)

Adds a scalar property with the given name and DataType::getIntType() as its value type.

Use addProperty() for anything more specific.

Parameters
namethe name of the property.
Returns
this builder.
Since
2026.1

◆ addLongProperty()

Builder & luciad::DataType::Builder::addLongProperty ( std::string name)

Adds a scalar property with the given name and DataType::getLongType() as its value type.

Use addProperty() for anything more specific.

Parameters
namethe name of the property.
Returns
this builder.
Since
2026.1

◆ addProperty()

Builder & luciad::DataType::Builder::addProperty ( DataProperty property)

The property to add to the data type under construction.

Parameters
propertythe property to add to the data type under construction.
Returns
this builder.

◆ addStringProperty()

Builder & luciad::DataType::Builder::addStringProperty ( std::string name)

Adds a scalar property with the given name and DataType::getStringType() as its value type.

Use addProperty() for anything more specific.

Parameters
namethe name of the property.
Returns
this builder.
Since
2026.1

◆ build()

DataType luciad::DataType::Builder::build ( )

Build the data type, including the properties and annotations that were added to this builder.

After calling this function, this builder should no longer be used.

Exceptions
luciad::LogicExceptionIf not all mandatory parameters are set, or if the data type ends up with more than one GeometryDataAnnotation. A data type has at most one main geometry.
Returns
the data type.

◆ name()

Builder & luciad::DataType::Builder::name ( std::string name)

The name of the new data type.

Calling this function is mandatory.

Parameters
namename of the new data type.
Returns
this builder.

◆ operator=()

Builder & luciad::DataType::Builder::operator= ( Builder other)
noexcept