You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.3 KiB
55 lines
1.3 KiB
1 year ago
|
|
||
|
#ifndef CSCI_BASE_CONTROLLER_H
|
||
|
#define CSCI_BASE_CONTROLLER_H
|
||
|
|
||
|
#include "controller.h"
|
||
|
#include "../../handler/controller_handler.h"
|
||
|
|
||
|
template<typename T>
|
||
|
class BaseController : public Controller {
|
||
|
|
||
|
private:
|
||
|
class Allocator{
|
||
|
public:
|
||
|
Allocator() {
|
||
|
registerClass<T>();
|
||
|
}
|
||
|
|
||
|
[[nodiscard]] const QString &className() const {
|
||
|
static QString class_name = ControllerHandler::getClassname(typeid(T).name());
|
||
|
return class_name;
|
||
|
}
|
||
|
|
||
|
template<typename D>
|
||
|
typename std::enable_if<std::is_default_constructible<D>::value,
|
||
|
void>::type
|
||
|
registerClass() {
|
||
|
ControllerHandler::registerCtl(className(), []() -> BaseController * { return new T(); });
|
||
|
}
|
||
|
|
||
|
template<typename D>
|
||
|
typename std::enable_if<!std::is_default_constructible<D>::value,
|
||
|
void>::type
|
||
|
registerClass() {
|
||
|
}
|
||
|
};
|
||
|
|
||
|
public:
|
||
|
const QString className() const override {
|
||
|
return allocator.className();
|
||
|
}
|
||
|
|
||
|
private:
|
||
|
static Allocator allocator;
|
||
|
|
||
|
public:
|
||
|
static QString getClassName() {
|
||
|
return allocator.className();
|
||
|
}
|
||
|
};
|
||
|
|
||
|
template<typename T>
|
||
|
typename BaseController<T>::Allocator BaseController<T>::allocator;
|
||
|
|
||
|
#endif //CSCI_BASE_CONTROLLER_H
|