2019-07-27 22:44:32 +08:00
|
|
|
|
#pragma once
|
2017-06-02 14:47:24 +08:00
|
|
|
|
#include "../acl_cpp_define.hpp"
|
2014-11-19 00:25:21 +08:00
|
|
|
|
|
|
|
|
|
namespace acl {
|
|
|
|
|
|
2015-06-29 17:33:11 +08:00
|
|
|
|
#if defined(_WIN32) || defined(_WIN64)
|
2014-11-19 00:25:21 +08:00
|
|
|
|
template<typename TDerive, typename TProvider>
|
|
|
|
|
class final_tpl_base
|
|
|
|
|
{
|
|
|
|
|
friend TDerive;
|
|
|
|
|
friend TProvider;
|
|
|
|
|
private:
|
|
|
|
|
final_tpl_base() {}
|
|
|
|
|
~final_tpl_base() {}
|
|
|
|
|
};
|
|
|
|
|
#else
|
|
|
|
|
template <typename T>
|
|
|
|
|
class identity
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
typedef T me;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<typename TDerive, typename TProvider>
|
|
|
|
|
class final_tpl_base
|
|
|
|
|
{
|
|
|
|
|
friend class identity<TDerive>::me;
|
|
|
|
|
friend class identity<TProvider>::me;
|
|
|
|
|
private:
|
|
|
|
|
final_tpl_base() {}
|
|
|
|
|
~final_tpl_base() {}
|
|
|
|
|
};
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/*
|
2019-07-27 22:44:32 +08:00
|
|
|
|
* 提供禁止派生的功能,需要此功能的类可以从final_tpl派生,
|
|
|
|
|
* 并将类名作为模板参数传递
|
2014-11-19 00:25:21 +08:00
|
|
|
|
* @example:
|
|
|
|
|
* class my_final_class : public acl::final_tpl <my_final_class>
|
|
|
|
|
* {
|
|
|
|
|
* public:
|
|
|
|
|
* my_final_class() {}
|
|
|
|
|
* ~my_final_class() {}
|
|
|
|
|
* }
|
2019-07-27 22:44:32 +08:00
|
|
|
|
* 这样就保证了 my_final_class 是不能被继承的
|
2014-11-19 00:25:21 +08:00
|
|
|
|
*/
|
|
|
|
|
template<typename TFinalClass>
|
|
|
|
|
class final_tpl : virtual public final_tpl_base<TFinalClass,
|
|
|
|
|
final_tpl<TFinalClass> >
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
final_tpl() {}
|
|
|
|
|
~final_tpl() {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|