CTL  0.6.1
Computed Tomography Library
systemcomponent.h
Go to the documentation of this file.
1 #ifndef CTL_SYSTEMCOMPONENT_H
2 #define CTL_SYSTEMCOMPONENT_H
3 
5 #include <QJsonObject>
6 #include <QString>
7 #include <memory>
8 
9 namespace CTL {
54 {
56 
57 public:
58  // ctors etc.
59  SystemComponent(const QString& name = defaultName());
60 
61  // virtual methods
62  virtual int elementalType() const;
63  virtual QString info() const;
64  virtual SystemComponent* clone() const;
65 
66  void fromVariant(const QVariant& variant) override; // de-serialization
67  QVariant toVariant() const override; // serialization
68 
69  // getter methods
70  const QString& name() const;
71 
72  // setter methods
73  void rename(QString name);
74 
75  // static methods
76  static QString defaultName();
77 
78 protected:
79  // methods
80  static QString typeInfoString(const std::type_info& type);
81 
82 private:
83  QString _name;
84 };
85 
86 // factory function `makeComponent`
87 template <typename ComponentType, typename... ConstructorArguments>
88 auto makeComponent(ConstructorArguments&&... arguments) ->
89  typename std::enable_if<std::is_convertible<ComponentType*, SystemComponent*>::value,
90  std::unique_ptr<ComponentType>>::type
91 {
92  return std::unique_ptr<ComponentType>(
93  new ComponentType(std::forward<ConstructorArguments>(arguments)...));
94 }
95 
96 // factory function 'makeComponentFromJson'
97 std::unique_ptr<SystemComponent> makeComponentFromJson(const QJsonObject& object,
98  bool fallbackToGenericType = false);
99 
135 inline int SystemComponent::elementalType() const { return Type; }
136 
137 } // namespace CTL
138 
140 
148 #define DECLARE_ELEMENTAL_TYPE \
149 public: \
150  int elementalType() const final { return Type; } \
151  \
152 private:
153 
182 
184 #endif // CTL_SYSTEMCOMPONENT_H
std::unique_ptr< SystemComponent > makeComponentFromJson(const QJsonObject &object, bool fallbackToGenericType)
void rename(QString name)
Definition: systemcomponent.cpp:47
std::unique_ptr< ComponentType > makeComponent(ConstructorArguments &&... arguments)
Definition: systemcomponent.h:88
static QString typeInfoString(const std::type_info &type)
Definition: systemcomponent.cpp:52
virtual QString info() const
Definition: systemcomponent.cpp:29
const QString & name() const
Definition: systemcomponent.cpp:42
QVariant toVariant() const override
Definition: systemcomponent.cpp:64
Specify an interface for de-/serialization from/to QVariants.
Definition: serializationinterface.h:17
QString _name
The component's name.
Definition: systemcomponent.h:83
Base class for all system components.
Definition: systemcomponent.h:53
static QString defaultName()
Definition: systemcomponent.cpp:19
#define CTL_TYPE_ID(newIndex)
Definition: serializationinterface.h:189
virtual SystemComponent * clone() const
Definition: systemcomponent.cpp:37
void fromVariant(const QVariant &variant) override
Definition: systemcomponent.cpp:58
int type() const override
Definition: systemcomponent.h:55
virtual int elementalType() const
Definition: systemcomponent.h:135