29 lines
798 B
C++
29 lines
798 B
C++
#pragma once
|
|
#include <QDebug>
|
|
namespace renderive {
|
|
template <typename T>
|
|
class Singleton_Widget {
|
|
public:
|
|
static T* instance() {
|
|
if (!instance_value) {
|
|
qInfo() << "error Singleton_Widget 未创建" << instance_value;
|
|
}
|
|
return instance_value;
|
|
}
|
|
Singleton_Widget() {
|
|
if (instance_value) {
|
|
qInfo() << "error Singleton_Widget 重复创建" << instance_value;
|
|
}
|
|
instance_value = static_cast<T*>(this);
|
|
}
|
|
virtual ~Singleton_Widget() = default;
|
|
explicit Singleton_Widget(T&&) = delete;
|
|
Singleton_Widget(const T&) = delete;
|
|
void operator=(const T&) = delete;
|
|
protected:
|
|
static T* instance_value;
|
|
};
|
|
template <typename T>
|
|
T* Singleton_Widget<T>::instance_value = nullptr;
|
|
} // namespace renderive
|