CTL  0.6.1
Computed Tomography Library
Public Types | Public Member Functions | Static Public Member Functions | Static Protected Member Functions | Private Attributes | Friends | List of all members
CTL::SystemComponent Class Reference

Base class for all system components. More...

#include <systemcomponent.h>

Inheritance diagram for CTL::SystemComponent:
Inheritance graph
[legend]
Collaboration diagram for CTL::SystemComponent:
Collaboration graph
[legend]

Public Types

enum  { Type = 0 }
 
- Public Types inherited from CTL::SerializationInterface
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 SystemComponentclone () const
 
void fromVariant (const QVariant &variant) override
 
QVariant toVariant () const override
 
const QString & name () const
 
void rename (QString name)
 
- Public Member Functions inherited from CTL::SerializationInterface
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< SystemComponentmakeComponentFromJson (const QJsonObject &object, bool fallbackToGenericType)
 

Additional Inherited Members

- Protected Member Functions inherited from CTL::SerializationInterface
 SerializationInterface ()=default
 
 SerializationInterface (const SerializationInterface &)=default
 
 SerializationInterface (SerializationInterface &&)=default
 
SerializationInterfaceoperator= (const SerializationInterface &)=default
 
SerializationInterfaceoperator= (SerializationInterface &&)=default
 

Detailed Description

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.

See also
elementalType()

Constructor & Destructor Documentation

◆ SystemComponent()

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.

Member Function Documentation

◆ clone()

SystemComponent * CTL::SystemComponent::clone ( ) const
virtual

◆ defaultName()

QString CTL::SystemComponent::defaultName ( )
static

Returns the default name for the component: "Generic system component".

◆ elementalType()

int CTL::SystemComponent::elementalType ( ) const
inlinevirtual

Returns the type id of the underlying elemental base class.

By default, there are four different elemental sub-classes:

◆ fromVariant()

void CTL::SystemComponent::fromVariant ( const QVariant &  variant)
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:

DirectBaseClass::fromVariant(variant);
// assuming our class has a member "double _myMemberVariable"
_myMemberVariable = variant.toMap().value("my member variable").toDouble();

Reimplemented from CTL::SerializationInterface.

Reimplemented in CTL::TubularGantry, CTL::XrayLaser, and CTL::XrayTube.

◆ info()

QString CTL::SystemComponent::info ( ) const
virtual

◆ name()

const QString & CTL::SystemComponent::name ( ) const

Returns the objects name.

◆ rename()

void CTL::SystemComponent::rename ( QString  name)

Sets the objects name to name.

◆ toVariant()

QVariant CTL::SystemComponent::toVariant ( ) const
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:

QVariantMap ret = DirectBaseClass::toVariant().toMap();
ret.insert("my member variable", _myMemberVariable);
return ret;

Reimplemented from CTL::SerializationInterface.

Reimplemented in CTL::TubularGantry, CTL::XrayLaser, and CTL::XrayTube.

◆ type()

int CTL::SystemComponent::type ( ) const
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.

◆ typeInfoString()

QString CTL::SystemComponent::typeInfoString ( const std::type_info &  type)
staticprotected

Returns a string that contains the typename of type.

Friends And Related Function Documentation

◆ makeComponent()

std::unique_ptr< ComponentType > makeComponent ( ConstructorArguments &&...  arguments)
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.

◆ makeComponentFromJson()

std::unique_ptr< SystemComponent > makeComponentFromJson ( const QJsonObject &  object,
bool  fallbackToGenericType 
)
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.


The documentation for this class was generated from the following files: