CTL
0.6.1
Computed Tomography Library
|
Base class for all system components. More...
#include <systemcomponent.h>
Public Types | |
enum | { Type = 0 } |
![]() | |
enum | { Type = -1, UserType = 65536 } |
Public Member Functions | |
int | type () const override |
SystemComponent (const QString &name=defaultName()) | |
virtual int | elementalType () const |
virtual QString | info () const |
virtual SystemComponent * | clone () const |
void | fromVariant (const QVariant &variant) override |
QVariant | toVariant () const override |
const QString & | name () const |
void | rename (QString name) |
![]() | |
virtual | ~SerializationInterface ()=default |
Static Public Member Functions | |
static QString | defaultName () |
Static Protected Member Functions | |
static QString | typeInfoString (const std::type_info &type) |
Private Attributes | |
QString | _name |
The component's name. | |
Friends | |
template<class > | |
struct | SerializationHelper::RegisterWithSerializationHelper |
Related Functions | |
(Note that these are not member functions.) | |
std::unique_ptr< ComponentType > | makeComponent (ConstructorArguments &&... arguments) |
std::unique_ptr< SystemComponent > | makeComponentFromJson (const QJsonObject &object, bool fallbackToGenericType) |
Additional Inherited Members | |
![]() | |
SerializationInterface ()=default | |
SerializationInterface (const SerializationInterface &)=default | |
SerializationInterface (SerializationInterface &&)=default | |
SerializationInterface & | operator= (const SerializationInterface &)=default |
SerializationInterface & | operator= (SerializationInterface &&)=default |
Base class for all system components.
This is the base class for all system components. It holds the components' name and defines the interface type(), elementalType() and info() as well as the clone() method. Additionally, the interface to de-/serialize components from/to JSON format are defined by read() and write().
To implement a custom component, create a sub-class of SystemComponent and make sure to register the component in the enumeration using the CTL_TYPE_ID(newIndex) macro. It is required to specify a value for newIndex that is not already in use. Please refer to the table found in type() for a list of values that are already in use. Another easy way to employ a free index is to use values starting from SystemComponent::UserType, as these are reserved for user-defined types.
To enable de-/serialization of objects of the new sub-class, reimplement the toVariant() and fromVariant() methods. These should take care of all newly introduced information of the sub-class. Additionally, call the macro DECLARE_SERIALIZABLE_TYPE(YourNewClassName) within the .cpp file of your new class (substitute "YourNewClassName" with the actual class name). Objects of the new class can then be de-/serialized with any of the serializer classes (see also AbstractSerializer).
It is strongly advised to sub-class one of the specialized abstract component types (instead of sub-classing SystemComponent directly), with respect to the specific purpose of the new class. By concept, the CTL core module is built-up on four different elemental sub-classes:
However, in the rare case that it is desired to extend this selection by a custom elemental component type, SystemComponent can also be sub-classed directly. In this case the DECLARE_ELEMENTAL_TYPE macro should be used to signalize that the class represents an elemental type. This will provide the possibility to query the underlying elemental type of all further sub-classes using their elementalType() method. Note that newly introduced elemental types will not be considered at any stage within the CTL modules without suitable changes/additions to the corresponding routines.
CTL::SystemComponent::SystemComponent | ( | const QString & | name = defaultName() | ) |
Constructs a component with the name name. If no name is passed, it defaults to "Generic system component".
Default move-constructor.
Default copy-constructor.
|
virtual |
Constructs a copy of the object and returns a base class pointer to it.
Reimplemented in CTL::CylindricalDetector, CTL::TubularGantry, CTL::GenericGantry, CTL::GenericDetector, CTL::CarmGantry, CTL::AttenuationFilter, CTL::GenericBeamModifier, CTL::GenericSource, CTL::XrayLaser, CTL::FlatPanelDetector, and CTL::XrayTube.
|
static |
Returns the default name for the component: "Generic system component".
|
inlinevirtual |
Returns the type id of the underlying elemental base class.
By default, there are four different elemental sub-classes:
|
overridevirtual |
Interface to read all member variables from the QVariant variant.
Reimplement this method such that it reads all newly introduced content when sub-classing. A typical reimplementation in sub-classes might look like this:
Reimplemented from CTL::SerializationInterface.
Reimplemented in CTL::TubularGantry, CTL::XrayLaser, and CTL::XrayTube.
|
virtual |
Returns a string that should contain all information about the component.
Reimplemented in CTL::AbstractSource, CTL::AbstractGantry, CTL::AbstractDetector, CTL::AbstractBeamModifier, CTL::CylindricalDetector, CTL::TubularGantry, CTL::GenericGantry, CTL::GenericDetector, CTL::AttenuationFilter, CTL::CarmGantry, CTL::GenericBeamModifier, CTL::GenericSource, CTL::XrayLaser, CTL::FlatPanelDetector, and CTL::XrayTube.
const QString & CTL::SystemComponent::name | ( | ) | const |
Returns the objects name.
void CTL::SystemComponent::rename | ( | QString | name | ) |
Sets the objects name to name.
|
overridevirtual |
Interface to store all member variables in a QVariant.
Stores the object's type-id.
Reimplement this method such that it stores all newly introduced object data when sub-classing. This needs to cover everything that is necessary to fully determine the state of an object. Best practice is to invoke the base class version of this method to take care of all content originating from underlying base classes.
A typical reimplementation in sub-classes might look like this:
Reimplemented from CTL::SerializationInterface.
Reimplemented in CTL::TubularGantry, CTL::XrayLaser, and CTL::XrayTube.
|
inlineoverridevirtual |
Returns the type id of the component.
List of all default types:
Type | Type-ID |
---|---|
SystemComponent::Type | 0 |
AbstractDetector::Type | 100 |
AbstractGantry::Type | 200 |
AbstractSource::Type | 300 |
AbstractBeamModifier::Type | 400 |
GenericDetector::Type | 101 |
GenericGantry::Type | 201 |
GenericSource::Type | 301 |
GenericBeamModifier::Type | 401 |
CylindricalDetector::Type | 110 |
FlatPanelDetector::Type | 120 |
CarmGantry::Type | 210 |
TubularGantry::Type | 220 |
XrayLaser::Type | 310 |
XrayTube::Type | 320 |
Reimplemented from CTL::SerializationInterface.
Reimplemented in CTL::TubularGantry, CTL::XrayLaser, and CTL::XrayTube.
|
staticprotected |
Returns a string that contains the typename of type.
|
related |
Global (free) make function that creates a new SystemComponent from the constructor arguments. The component is returned as a std::unique_ptr<ComponentType>
, whereas ComponentType
is the template argument of this function that needs to be specified.
|
related |
Global (free) make function that parses a QJsonObject and creates a concrete SystemComponent (any subtype) whose Type-ID is registered (with CTL_TYPE_ID). It is also required that this type has been added to the switch-case list inside the implementation of parseComponentFromJson(const QJsonObject&) in the header file "components/jsonparser.h". If the type is not known (not implemented into the switch-case list) and fallbackToGenericType is set to true
, the function tries - by using parseGenericComponentFromJson(const QJsonObject&) - to restore a Generic<Type> (e.g. GenericSource) based of its elemental type id. However in this case all the specific information (member variables) of the unknown type as well as the information of the Generic<Type> cannot be restored, only the information of the elemental Abstract<Type> is recovered. If the parsing of the Json object was not successful, the functions returns a nullptr
.