Macros for the creation/deletion and casting of objects of all types as well as some miscellaneous macros to get the base object, base class and reference count of objects.
S_NEW | Create a new object of the given object type. |
S_NEW_FROM_NAME | Create a new object of the given object type name. |
S_DELETE | Delete an object. |
S_FORCE_DELETE | Force deletion of an object. |
S_CAST_SAFE | Safe cast the given object to the given type. |
S_CAST_UNSAFE | Unsafe cast the given object to the given type. |
S_CAST | Cast the given object to the given type. |
S_OBJECT_CALL | Call the given function method of the given SObject. |
S_OBJECT_METH_VALID | Test if the given function method of the given SObject can be called. |
S_OBJECT | Return the given object as a base object. |
S_OBJECT_REF | Get the given object’s reference count. |
S_OBJECT_CLS | Get the given object’s base class. |
S_OBJECTCLASS | Get the given class’s base class. |
S_FIND_CLASS | Get the given object type class. |
Create a new object of the given object type.
Also initializes the object members and inherited members. For example:
SMapList *myMapList = S_NEW(SMapList, error);
Parameters: |
|
---|---|
Return: | Pointer to the newly created object (of type OBJTYPE*). |
See also: |
Create a new object of the given object type name.
Also initializes the object members and inherited members. For example:
SMapList *myMapList = (SMapList*)S_NEW("SMapList", error);
Parameters: |
|
---|---|
Return: | Pointer to the newly created object (of type SObject*). |
See also: |
Delete an object.
The delete macro works in two stages, first a call is made to the dispose method of SObjectClass, then if the object is no longer referenced, a call is made to the destroy method of SObjectClass. The given object pointer, SELF, is set to NULL, regardless of whether the object was deleted or not.
This allows full control over the reference counting of an object. For most normal objects the dispose method of SObjectClass would look like the SString dispose function in engine/src/base/objsystem/primitives.c:
static void DisposeString(void *obj, s_erc *error)
{
S_CLR_ERR(error);
SObjectDecRef(S_OBJECT(obj));
}
Parameters: |
---|
Force deletion of an object.
The object is deleted, with a call to the destroy method of SObjectClass to free up the object resources, regardless of whether it is referenced or not. The pointer to the object will point to NULL after this operation.
Parameters: | |
---|---|
See also: |
Safe cast the given object to the given type.
Parameters: |
|
---|---|
Return: | Pointer to Object casted to OBJTYPE, or NULL on error. |
Unsafe cast the given object to the given type.
This cast is unsafe (but faster than S_CAST_SAFE), and should only be used when you are sure of the object types.
Parameters: |
|
---|---|
Return: | Pointer to Object casted to OBJTYPE. |
Cast the given object to the given type.
This cast reverts to either S_CAST_SAFE or S_CAST_UNSAFE, depending on the build time definition of SPCT_DO_SAFE_CAST.
Parameters: |
|
---|---|
Return: | Pointer to Object casted to OBJTYPE. |
See also SPCT_DO_SAFE_CAST
Call the given function method of the given SObject.
Parameters: |
|
---|---|
Note: | This casting is not safety checked. Example usage: S_OBJECT_CALL(self, func)(param1, param2, ..., paramN);
|
Test if the given function method of the given SObject can be called.
Parameters: |
|
---|---|
Return: | |
Note: | This casting is not safety checked. |
Return the given object as a base object.
Parameters: |
|
---|---|
Return: | Given object as SObject* type. |
Note: | This casting is not safety checked. |
Get the given object’s reference count.
Parameters: |
|
---|---|
Return: | Constant uint32 reference count of the given object. |
Note: | This casting is not safety checked. |
Get the given object’s base class.
Parameters: |
|
---|---|
Return: | Pointer to the SObjectClass class of the given object. |
Note: | This casting is not safety checked. |
Get the given class’s base class.
Parameters: |
|
---|---|
Return: | Pointer to the SObjectClass class of the given class. |
Note: | This casting is not safety checked. |
Get the given object type class.
Parameters: |
|
---|---|
Return: | Pointer to the class of object type (of type OBJTYPECLASS*). |