CTL  0.6.1
Computed Tomography Library
Classes
serializationinterface.h File Reference
#include "io/serializationhelper.h"
#include <QVariant>
Include dependency graph for serializationinterface.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  CTL::SerializationInterface
 Specify an interface for de-/serialization from/to QVariants. More...
 

Macros

#define CTL_TYPE_ID(newIndex)
 

Macro Definition Documentation

◆ CTL_TYPE_ID

#define CTL_TYPE_ID (   newIndex)
Value:
public: \
enum { Type = (newIndex) }; \
int type() const override { return Type; } \
\
private: \
template<class> \
friend struct ::CTL::SerializationHelper::RegisterWithSerializationHelper;

This macro should be used in classes with SerializationInterface as base class. It adds a class to the type enumeration with the index newIndex and it overrides the function int type() const so that it returns the newIndex.

Moreover, the SerializationHelper::RegisterWithSerializationHelper class is declared as a friend class. This allows access to a possible private default constructor of the class using this macro.

The usage of the macro should be in a class definition as follows:

class MySerializableClass : public SerializationInterface
{
public:
void fromVariant(const QVariant& variant) override;
QVariant toVariant() const override;
// ...
};

or further subclasses can be typed like

class MySerializableSubClass : public MySerializableClass
{
// possible variant conversions
// ...
};

Additionally, the type may be registered to the SerializationHelper by using the macro DECLARE_SERIALIZABLE_TYPE(className_woNamespace). This is not necessary, however, it enables the SerializationHelper to mangage the deserialization of classes with the following types as base class:

  • AbstractDataModel
  • AbstractDataModel2D
  • AbstractPrepareStep
  • AbstractProjector
  • SystemComponent
  • miscellaneous, i.e. none of the above, only SerializationInterface.

Note that newIndex within one of the top four categories has to be unique for each class that uses this macro. It is not necessary for the newIndex to be unique with respect to the other categories.

The SerializationHelper is used by implementations (subclasses) of AbstractSerializer. For instance, you can create an object of the 3rd category from a JSON file with

auto mySystemComponent = JsonSerializer().deserializeComponent("path/to/mySystemComponent.json").
See also
DECLARE_SERIALIZABLE_TYPE(className_woNamespace)