42 lines
1.6 KiB
C++
42 lines
1.6 KiB
C++
#pragma once
|
|
|
|
#include "XNCore_global.h"
|
|
#include <memory>
|
|
|
|
namespace XNSim {
|
|
template <typename T>
|
|
using XN_ENABLE_SHARED_FROM_THIS = std::enable_shared_from_this<T>;
|
|
|
|
// 静态指针类型转换辅助函数
|
|
template <class ToType, class FromType>
|
|
FORCEINLINE ToType XNStaticCastHelper(const FromType &from) {
|
|
return std::static_pointer_cast<typename ToType::element_type>(from);
|
|
}
|
|
|
|
// 动态指针类型转换辅助函数
|
|
template <class ToType, class FromType>
|
|
FORCEINLINE ToType XNCastHelper(const FromType &from) {
|
|
return std::dynamic_pointer_cast<typename ToType::element_type>(from);
|
|
}
|
|
|
|
} // namespace XNSim
|
|
|
|
// 静态类型转换宏
|
|
#define XN_CAST(from, to) XNStaticCastHelper<to>(from)
|
|
|
|
// 获取当前对象的智能指针
|
|
#define XN_THISPTR std::static_pointer_cast<ThisType>(shared_from_this())
|
|
|
|
// 类智能指针声明宏
|
|
#define XNCLASS_PTR_DECLARE(a) \
|
|
using a##Ptr = std::shared_ptr<class a>; \
|
|
using a##WPtr = std::weak_ptr<class a>; \
|
|
using a##UPtr = std::unique_ptr<class a>; \
|
|
using a##ConsPtr = std::shared_ptr<const class a>;
|
|
|
|
// 结构体智能指针声明宏
|
|
#define XNSTRUCT_PTR_DECLARE(a) \
|
|
using a##Ptr = std::shared_ptr<struct a>; \
|
|
using a##WPtr = std::weak_ptr<struct a>; \
|
|
using a##UPtr = std::unique_ptr<struct a>; \
|
|
using a##ConsPtr = std::shared_ptr<const struct a>; |