24#include "AstUtil/SharedPtr.hpp"
25#include "AstUtil/ScopedPtr.hpp"
26#include "AstUtil/WeakPtr.hpp"
27#include "AstUtil/ReflectAPI.hpp"
50template<
typename ObjectPtrType,
typename PropertyType>
53typedef AttributeBasic<WeakPtr<Object>, Property> Attribute;
56#define AST_OBJECT(TYPE) \
57 static Class staticType;\
58 static inline Class* getStaticType(){return &staticType;}\
59 Class* getType() const override{return &staticType;} \
60 static void ClassInit(Class* cls);\
63#define AST_PROPERT(NAME) static constexpr const char* _prop_##NAME = #NAME;
66#define AST_PROPERT_NAME(CLASS, NAME) CLASS::_prop_##NAME
67#define aPropertyName(CLASS, NAME) AST_PROPERT_NAME(CLASS, NAME)
69#define _AST_IMPL_OBJECT(TYPE) \
70 Class TYPE::staticType;\
90 static Class staticType;
91 static inline Class* getStaticType(){
return &staticType;}
95 virtual Class* getType()
const;
99 virtual const std::string& getName()
const;
106 errc_t openEditDialog();
119 errc_t getAttrBool(
StringView path,
bool& value)
const;
125 errc_t getAttrInt(
StringView path,
int& value)
const;
131 errc_t getAttrDouble(
StringView path,
double& value)
const;
137 errc_t getAttrString(
StringView path, std::string& value)
const;
158 std::string getAttrString(
StringView path)
const;
164 errc_t setAttrBool(
StringView path,
bool value);
170 errc_t setAttrInt(
StringView path,
int value);
176 errc_t setAttrDouble(
StringView path,
double value);
197 uint32_t getID()
const;
202 errc_t setParentScope(
Object* parentScope);
206 Object* getParentScope()
const;
218 bool isDestructed()
const{
return refcnt_ ==
static_cast<uint32_t
>(-1);}
224 assert(refcnt_ == 0);
232 return ++weakrefcnt_;
239 if (weakrefcnt_ == 1) {
240 operator delete(
this);
244 return --weakrefcnt_;
278 this->refcnt_ =
static_cast<uint32_t
>(-1);
283 friend class ObjectManager;
285 Object(
const Object& obj)
289 Object& operator=(
const Object& obj)
296 std::atomic<uint32_t> refcnt_{0};
297 std::atomic<uint32_t> weakrefcnt_{1};
298 uint32_t index_{
static_cast<uint32_t
>(
INVALID_ID)};
309AST_DECL_TYPE_ALIAS(Object)
311#include "AstUtil/Attribute.hpp"
312#include "AstUtil/Class.hpp"
对象的特定属性
定义 Attribute.hpp:42
对象基类,继承自该类的对象可以使用运行时类型信息相关功能,实现强弱引用计数、运行时元信息(属性访问、序列化等)等基础功能
定义 Object.hpp:81
uint32_t weakRefCount() const
获取弱引用计数
定义 Object.hpp:214
uint32_t incRef()
增加强引用计数
定义 Object.hpp:250
uint32_t incWeakRef()
增加弱引用计数
定义 Object.hpp:230
bool isDestructed() const
判断对象是否被析构
定义 Object.hpp:218
uint32_t decWeakRef()
减少弱引用计数
定义 Object.hpp:237
uint32_t refCount() const
获取强引用计数
定义 Object.hpp:210
uint32_t decRef()
减少强引用计数
定义 Object.hpp:257
void destruct()
析构对象,仅当强引用计数为0时才会被调用
定义 Object.hpp:222
Class * type() const
获取对象类型
定义 Object.hpp:187
uint32_t decRefNoDelete()
减少强引用计数,不删除对象
定义 Object.hpp:268
@ INVALID_ID
无效对象ID
定义 Object.hpp:74