24#include "AstUtil/SharedPtr.hpp"
25#include "AstUtil/ScopedPtr.hpp"
26#include "AstUtil/ReflectAPI.hpp"
27#include "AstUtil/Referenced.hpp"
49template<
typename _Object>
52template<
typename ObjectPtrType,
typename PropertyType>
55typedef AttributeBasic<Object, Property> Attribute;
58#define AST_OBJECT(TYPE) \
59 static Class staticType;\
60 static inline Class* StaticType(){return &staticType;}\
61 Class* getType() const override{return &staticType;} \
62 static void ClassInit(Class* cls);\
65#define AST_PROPERT(NAME) static constexpr const char* _prop_##NAME = #NAME;
68#define AST_PROPERT_NAME(CLASS, NAME) CLASS::_prop_##NAME
69#define aPropertyName(CLASS, NAME) AST_PROPERT_NAME(CLASS, NAME)
71#define _AST_IMPL_OBJECT(TYPE) \
72 Class TYPE::staticType;\
90A_ENUM_CLASS_FLAGS(EObjectFlags)
108 using Referenced::Referenced;
115 static Class staticType;
116 static void ClassInit(
Class* cls);
117 static inline Class* StaticType(){
return &staticType;}
121 virtual Class* getType()
const;
125 virtual std::string getRepresentation()
const;
128 virtual const std::string& getName()
const;
135 const std::string&
name()
const {
return this->getName();}
138 std::string displayName()
const;
143 errc_t showEditDialog();
156 errc_t getAttrBool(
StringView path,
bool& value)
const;
162 errc_t getAttrInt(
StringView path,
int& value)
const;
168 errc_t getAttrDouble(
StringView path,
double& value)
const;
174 errc_t getAttrString(
StringView path, std::string& value)
const;
202 std::string getAttrString(
StringView path)
const;
214 errc_t setAttrBool(
StringView path,
bool value);
220 errc_t setAttrInt(
StringView path,
int value);
226 errc_t setAttrDouble(
StringView path,
double value);
246 const std::string& typeName()
const;
256 ObjectId getID()
const;
261 errc_t setParentScope(
Object* parentScope);
265 Object* getParentScope()
const;
273 bool isOfType(
const Class* type)
const;
283 bool isOfType()
const;
289 template<
typename Func>
290 inline void addDelayedLink(Func &&link);
297 template<
typename Func>
298 inline void addDelayedLinkIfFailed(Func &&link);
306 bool readOnly()
const {
return !!(flags_ & EObjectFlags::eReadOnly);}
307 void setReadOnly(
bool readOnly);
309 bool active()
const {
return !(flags_ & EObjectFlags::eInActive);}
310 void setActive(
bool active);
312 bool isComponent()
const {
return !!(flags_ & EObjectFlags::eComponent);}
313 void setIsComponent(
bool isComponent);
315 bool isEntity()
const {
return !!(flags_ & EObjectFlags::eEntity);}
316 void setIsEntity(
bool isEntity);
319 const char*
tr(
const char* msg)
const;
321 friend class ObjectManager;
323 Object(
const Object& obj)
326 Object& operator=(
const Object&)
332 uint32_t index_{
static_cast<uint32_t
>(
INVALID_ID)};
344 template <
typename U, Class* (U::*)() const>
348 template <
typename U>
349 static yes test(Check<U, &U::getType>*);
356 static constexpr bool value = (
sizeof(test<T>(0)) ==
sizeof(yes));
360template<
typename T,
typename U>
361A_ALWAYS_INLINE T aobject_cast(U* obj)
364 using ObjectType =
typename std::decay<
365 typename std::remove_pointer<
366 typename std::remove_pointer<T>::type
370 "aobject_cast requires the type to has a AST_OBJECT macro");
371 return static_cast<T
>(ObjectType::StaticType()->cast(obj));
376bool Object::isOfType()
const
378 using ObjectType =
typename std::decay<typename std::remove_pointer<T>::type>::type;
380 return isOfType(ObjectType::StaticType());
384T Object::getParent()
const
386 return aobject_cast<T>(getParentScope());
390SharedPtr<T> aMakeShared()
396SharedPtr<T> aMakeShared(Object* parentScope)
404SharedPtr<T> aMakeShared(StringView objectName)
407 obj->setName(objectName);
412SharedPtr<T> aMakeShared(Object* parentScope, StringView typeName)
415 obj->setParentScope(parentScope);
416 obj->setName(typeName);
422T* aNewObject(Object* parentScope=
nullptr)
425 obj->setParentScope(parentScope);
430T* aNewObject(StringView objectName)
433 obj->setName(objectName);
438T* aNewObject(Object* parentScope, StringView objectName)
441 obj->setParentScope(parentScope);
442 obj->setName(objectName);
452AST_DECL_TYPE_ALIAS(Object)
454#include "AstUtil/Attribute.hpp"
455#include "AstUtil/Class.hpp"
456#include "AstUtil/WeakPtr.hpp"
对象基类,继承自该类的对象可以使用运行时类型信息相关功能,实现强弱引用计数、运行时元信息(属性访问、序列化等)等基础功能
定义 Object.hpp:95
const std::string & name() const
获取对象的名称
定义 Object.hpp:135
virtual void setName(StringView name)=0
设置对象的名称
Class * type() const
获取对象类型
定义 Object.hpp:244
EObjectFlags
对象标志位
定义 Object.hpp:81
errc_t aSetParentScope(Object *obj, Object *parentScope)
设置对象的父作用域
定义 RTTIAPI.cpp:211
@ eComponent
组件对象(和eEntity互斥)
@ eEntity
实体对象(和eComponent互斥)
@ INVALID_ID
无效对象ID
定义 Object.hpp:76
A_ALWAYS_INLINE const char * tr(const char *msgid)
获取翻译文本
定义 I18n.hpp:49