Runtime type information
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#include <memory.h>
|
||||
#include "malunal/types/object.h"
|
||||
|
||||
|
||||
@@ -12,3 +13,78 @@ const uuid_t UUID_OBJECT_T = {
|
||||
0x6C, 0x9C, 0x3A
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
error_t
|
||||
object_query_interface(
|
||||
object_iptr_t obj,
|
||||
uuid_iptr_t iid,
|
||||
rtti_intf_mptr_t intf
|
||||
) {
|
||||
if (obj == null)
|
||||
return (error_t) {
|
||||
.domain = &ERROR_DOMAIN_OBJECT_T,
|
||||
.code = OBJECT_ERROR_NULL_OBJECT
|
||||
};
|
||||
|
||||
if (intf == null)
|
||||
return (error_t) {
|
||||
.domain = &ERROR_DOMAIN_OBJECT_T,
|
||||
.code = OBJECT_ERROR_NULL_OUTPUT
|
||||
};
|
||||
|
||||
malunal_size_t index;
|
||||
rtti_intf_mptr_t entry;
|
||||
for (index = 0; index < obj->rtti->nIntfs; index++) {
|
||||
entry = &obj->rtti->pIntfs[index];
|
||||
if (uuid_equals(iid, entry->iid)) {
|
||||
intf->iid = entry->iid;
|
||||
intf->vtable = entry->vtable;
|
||||
return NO_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
intf->iid = null;
|
||||
intf->vtable = null;
|
||||
return (error_t) {
|
||||
.domain = &ERROR_DOMAIN_OBJECT_T,
|
||||
.code = OBJECT_ERROR_NOT_MY_INTERFACE
|
||||
};
|
||||
}
|
||||
|
||||
error_t
|
||||
object_query_property(
|
||||
object_iptr_t obj,
|
||||
malunal_cstr_t name,
|
||||
rtti_prop_mptr_t prop
|
||||
) {
|
||||
if (obj == null)
|
||||
return (error_t) {
|
||||
.domain = &ERROR_DOMAIN_OBJECT_T,
|
||||
.code = OBJECT_ERROR_NOT_MY_INTERFACE
|
||||
};
|
||||
|
||||
if (prop == null)
|
||||
return (error_t) {
|
||||
.domain = &ERROR_DOMAIN_OBJECT_T,
|
||||
.code = OBJECT_ERROR_NULL_OUTPUT
|
||||
};
|
||||
|
||||
malunal_size_t index;
|
||||
rtti_prop_mptr_t entry;
|
||||
for (index = 0; index < obj->rtti->nProps; index++) {
|
||||
entry = &obj->rtti->pProps[index];
|
||||
if (strcmp(name, entry->name) == 0) {
|
||||
prop->name = entry->name;
|
||||
prop->rtti = entry->rtti;
|
||||
return NO_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
prop->name = null;
|
||||
prop->rtti = null;
|
||||
return (error_t) {
|
||||
.domain = &ERROR_DOMAIN_OBJECT_T,
|
||||
.code = OBJECT_ERROR_NOT_MY_PROPERTY
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user