remove macros use in objects mofule
This commit is contained in:
parent
0fb9326c08
commit
7927226484
31 changed files with 362 additions and 386 deletions
|
|
@ -23,43 +23,27 @@ define base type
|
|||
define struct members
|
||||
implement construct, destruct and copy methods */
|
||||
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define NDO_CAST(cast_type, ptr) ((cast_type*)ndo_cast(ptr, &cast_type::TypeData))
|
||||
#define NDO_CAST_ASSERT(cast_type, ptr) {assert(ndo_cast(ptr, &cast_type::TypeData))}
|
||||
#else
|
||||
#define NDO_CAST_ASSERT(cast_type, ptr) {assert(ndo_cast(ptr, &cast_type::TypeData))}
|
||||
#define NDO_CAST(cast_type, ptr) ((cast_type*)ndo_cast(ptr, &cast_type::TypeData))
|
||||
#endif
|
||||
|
||||
#define NDO_CASTV(cast_type, ptr, var_name) cast_type* var_name = NDO_CAST(cast_type, ptr); var_name
|
||||
|
||||
#define NDO_MEMH_FROM_NDO(ndo_ptr) (((ObjectMemHead*)ndo_ptr) - 1)
|
||||
#define NDO_FROM_MEMH(ndo_ptr) ((Object*)(ndo_ptr + 1))
|
||||
|
||||
namespace tp::obj {
|
||||
|
||||
extern ModuleManifest gModuleObjects;
|
||||
|
||||
extern struct objects_api* NDO;
|
||||
|
||||
struct ObjectMemHead {
|
||||
ObjectMemHead* up;
|
||||
ObjectMemHead* down;
|
||||
struct Object {
|
||||
Object* up;
|
||||
Object* down;
|
||||
alni flags;
|
||||
alni refc;
|
||||
};
|
||||
|
||||
struct Object {
|
||||
const struct ObjectType* type;
|
||||
};
|
||||
|
||||
typedef void (*object_from_int)(Object* self, alni in);
|
||||
typedef void (*object_from_float)(Object* self, alnf in);
|
||||
typedef void (*object_from_string)(Object* self, const std::string& in);
|
||||
typedef std::string(*object_to_string)(Object* self);
|
||||
typedef alni(*object_to_int)(Object* self);
|
||||
typedef alnf(*object_to_float)(Object* self);
|
||||
typedef std::string (*object_to_string)(Object* self);
|
||||
typedef alni (*object_to_int)(Object* self);
|
||||
typedef alnf (*object_to_float)(Object* self);
|
||||
|
||||
struct ObjectTypeConversions {
|
||||
object_from_int from_int;
|
||||
|
|
@ -86,14 +70,14 @@ namespace tp::obj {
|
|||
typedef void (*object_destructor)(Object* self);
|
||||
typedef void (*object_copy)(Object* self, const Object* target);
|
||||
|
||||
typedef alni(*object_save_size)(Object* self);
|
||||
typedef alni (*object_save_size)(Object* self);
|
||||
typedef void (*object_save)(Object*, ArchiverOut&);
|
||||
typedef void (*object_load)(ArchiverIn&, Object*);
|
||||
|
||||
typedef bool (*object_compare)(Object*, Object*);
|
||||
|
||||
typedef Buffer<Object*> (*object_debug_all_childs_retrival)(Object*);
|
||||
typedef alni (*object_allocated_size)(Object*); // default value = type->size - sizeof(ObjectType*)
|
||||
typedef alni (*object_allocated_size)(Object*); // default value = type->size - sizeof(ObjectType*)
|
||||
typedef alni (*object_allocated_size_recursive)(Object*); // default value = object_allocated_size
|
||||
|
||||
struct ObjectType {
|
||||
|
|
@ -117,13 +101,12 @@ namespace tp::obj {
|
|||
TypeMethods type_methods;
|
||||
};
|
||||
|
||||
|
||||
#define SAVE_LOAD_MAX_CALLBACK_SLOTS 100
|
||||
typedef void (pre_save_callback)(void* self, ArchiverOut&);
|
||||
typedef void (pre_load_callback)(void* self, ArchiverIn&);
|
||||
typedef void (post_save_callback)(void* self, ArchiverOut&);
|
||||
typedef void (post_load_callback)(void* self, ArchiverIn&);
|
||||
typedef alni (slcb_size_callback)(void* self, ArchiverOut&);
|
||||
#define SAVE_LOAD_MAX_CALLBACK_SLOTS 100
|
||||
typedef void(pre_save_callback)(void* self, ArchiverOut&);
|
||||
typedef void(pre_load_callback)(void* self, ArchiverIn&);
|
||||
typedef void(post_save_callback)(void* self, ArchiverOut&);
|
||||
typedef void(post_load_callback)(void* self, ArchiverIn&);
|
||||
typedef alni(slcb_size_callback)(void* self, ArchiverOut&);
|
||||
|
||||
struct save_load_callbacks {
|
||||
void* self;
|
||||
|
|
@ -134,7 +117,6 @@ namespace tp::obj {
|
|||
post_load_callback* post_load;
|
||||
};
|
||||
|
||||
|
||||
struct objects_api {
|
||||
|
||||
Map<std::string, const ObjectType*> types;
|
||||
|
|
@ -162,12 +144,13 @@ namespace tp::obj {
|
|||
|
||||
void destroy(Object* in) const;
|
||||
|
||||
static void increaseReferenceCount(Object* in);
|
||||
static halni getReferenceCount(Object* in);
|
||||
private:
|
||||
static void setReferenceCount(Object* in, halni count);
|
||||
public:
|
||||
static inline void increaseReferenceCount(Object* in) { in->refc++; }
|
||||
static inline alni getReferenceCount(Object* in) { return in->refc; }
|
||||
|
||||
private:
|
||||
static inline void setReferenceCount(Object* in, halni count) { in->refc = count; }
|
||||
|
||||
public:
|
||||
save_load_callbacks* sl_callbacks[SAVE_LOAD_MAX_CALLBACK_SLOTS]{};
|
||||
alni sl_callbacks_load_idx = 0;
|
||||
|
||||
|
|
@ -184,16 +167,26 @@ namespace tp::obj {
|
|||
Object* load(const std::string& path);
|
||||
alni save(ArchiverOut&, Object*);
|
||||
Object* load(ArchiverIn&, alni file_adress);
|
||||
|
||||
template <typename Type>
|
||||
static Type* cast(const Object* in) {
|
||||
const ObjectType* typeIter = in->type;
|
||||
while (typeIter) {
|
||||
if (typeIter == &Type::TypeData) {
|
||||
return (Type*) in;
|
||||
}
|
||||
typeIter = typeIter->base;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
void logTypeData(const ObjectType* type);
|
||||
void assertNoLeaks();
|
||||
ualni getObjCount();
|
||||
|
||||
Object* ndo_cast(const Object* in, const ObjectType* to_type);
|
||||
|
||||
template <typename Type>
|
||||
Type* create() {
|
||||
return (Type*)NDO->create(Type::TypeData.name);
|
||||
return (Type*) NDO->create(Type::TypeData.name);
|
||||
}
|
||||
}
|
||||
|
|
@ -10,12 +10,9 @@ namespace tp::obj {
|
|||
|
||||
class OperandStack {
|
||||
|
||||
enum : alni {
|
||||
MAX_STACK_SIZE = 512
|
||||
};
|
||||
enum : alni { MAX_STACK_SIZE = 512 };
|
||||
|
||||
public:
|
||||
|
||||
Operand* mBuff;
|
||||
ualni mIdx;
|
||||
|
||||
|
|
@ -28,7 +25,7 @@ namespace tp::obj {
|
|||
template <typename ObjectType>
|
||||
ObjectType* getOperand() {
|
||||
auto operand = getOperand();
|
||||
auto ret = NDO_CAST(ObjectType, operand);
|
||||
auto ret = objects_api::cast<ObjectType>(operand);
|
||||
ASSERT(ret && "Operand Has Invalid Object Type");
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ namespace tp::obj {
|
|||
void addMember(Object* obj, const std::string& id);
|
||||
void createMember(const std::string& type, const std::string& id);
|
||||
|
||||
template<typename Type>
|
||||
template <typename Type>
|
||||
Type* createMember(const std::string& id) {
|
||||
auto out = NDO->create(Type::TypeData.name);
|
||||
addMember(out, id);
|
||||
|
|
@ -27,19 +27,19 @@ namespace tp::obj {
|
|||
return (Type*) out;
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
template <typename Type>
|
||||
Type* getMember(const std::string& id) {
|
||||
auto idx = members->presents(id);
|
||||
if (bool(idx)) {
|
||||
return ((Type*)ndo_cast(members->getSlotVal(idx), &Type::TypeData));
|
||||
return objects_api::cast<Type>(members->getSlotVal(idx));
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
template <typename Type>
|
||||
Type* getMemberAssert(const std::string& id) {
|
||||
auto out = getMember<Type>(id);
|
||||
assert(out && "invalid member access");
|
||||
ASSERT(out && "invalid member access")
|
||||
return out;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ namespace tp::obj {
|
|||
static ObjectType TypeData;
|
||||
static ObjectTypeAriphmetics TypeAriphm;
|
||||
|
||||
static void constructor(Object* self);
|
||||
static void constructor(ColorObject* self);
|
||||
static void copy(ColorObject* self, const ColorObject* in);
|
||||
|
||||
static void from_int(ColorObject* self, alni in);
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ namespace tp::obj {
|
|||
|
||||
struct DictObject : Object {
|
||||
static ObjectType TypeData;
|
||||
static void copy(Object* self, const Object* in);
|
||||
static void destructor(Object* self);
|
||||
static void constructor(Object* self);
|
||||
static void copy(DictObject* self, const DictObject* in);
|
||||
static void destructor(DictObject* self);
|
||||
static void constructor(DictObject* self);
|
||||
|
||||
static alni save_size(DictObject* self);
|
||||
static void save(DictObject* self, ArchiverOut& file_self);
|
||||
|
|
|
|||
|
|
@ -11,15 +11,15 @@ namespace tp::obj {
|
|||
static ObjectType TypeData;
|
||||
static ObjectTypeAriphmetics TypeAriphm;
|
||||
|
||||
static void constructor(Object* self);
|
||||
static void constructor(IntObject* self);
|
||||
static void copy(IntObject* self, const IntObject* in);
|
||||
static IntObject* create(alni in);
|
||||
|
||||
static void from_int(Object* self, alni in);
|
||||
static void from_float(Object* self, alnf in);
|
||||
static void from_string(Object* self, const std::string& in);
|
||||
static std::string to_string(Object* self);
|
||||
static alni to_int(Object* self);
|
||||
static alnf to_float(Object* self);
|
||||
static void from_int(IntObject* self, alni in);
|
||||
static void from_float(IntObject* self, alnf in);
|
||||
static void from_string(IntObject* self, const std::string& in);
|
||||
static std::string to_string(IntObject* self);
|
||||
static alni to_int(IntObject* self);
|
||||
static alnf to_float(IntObject* self);
|
||||
};
|
||||
}
|
||||
|
|
@ -7,9 +7,10 @@ namespace tp::obj {
|
|||
|
||||
struct LinkObject : Object {
|
||||
static ObjectType TypeData;
|
||||
static void constructor(Object* self);
|
||||
|
||||
static void constructor(LinkObject* self);
|
||||
static void destructor(LinkObject* self);
|
||||
static void copy(Object* self, const Object* in);
|
||||
static void copy(LinkObject* self, const LinkObject* in);
|
||||
static LinkObject* create(Object* in);
|
||||
|
||||
static alni save_size(LinkObject* self);
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@ namespace tp::obj {
|
|||
|
||||
struct ListObject : Object {
|
||||
static ObjectType TypeData;
|
||||
static void constructor(Object* self);
|
||||
static void copy(Object* self, const Object* in);
|
||||
static void destructor(Object* self);
|
||||
static void constructor(ListObject* self);
|
||||
static void copy(ListObject* self, const ListObject* in);
|
||||
static void destructor(ListObject* self);
|
||||
|
||||
static alni allocated_size_recursive(ListObject* self);
|
||||
static alni allocated_size(ListObject* self);
|
||||
|
|
|
|||
|
|
@ -9,9 +9,10 @@ namespace tp::obj {
|
|||
std::string val;
|
||||
|
||||
static ObjectType TypeData;
|
||||
static void constructor(Object* self);
|
||||
static void constructor(StringObject* self);
|
||||
static void destructor(StringObject* self);
|
||||
static void copy(Object* self, const Object* in);
|
||||
static void copy(StringObject* self, const StringObject* in);
|
||||
|
||||
static StringObject* create(const std::string& in);
|
||||
|
||||
static void from_int(StringObject* self, alni in);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue