This is an example for a simple class without interface, but override-able methods.
It based on ObjectJc, because the overriding of methods needs this base class.
The
struct in C is defined in the following form:
typedef struct SimpleClass_Test_t
{
union { ObjectJc object; } base;
int32 x1;
} SimpleClass_Test_s;
It contains the base data of
ObjectJc wrapped with the
union,
because the access to the
ObjectJc is written anyway in form
ref.base.object.
The
struct contains the data.
There are two additional defines for all classes in C:
typedef struct SimpleClass_Test_Y_t { ObjectArrayJc head; SimpleClass_Test_s data[50]; } SimpleClass_Test_Y;
extern_C struct ClassJc_t const reflection_SimpleClass_Test_s;
- The first line defines a array structure. It is ready to use always. The number of data is a placeholder.
The structure type is used as a reference anytime. Than the really number of elements in the array
depends from the memory allocation size and it is stored in the head data.
- The second line declares the existence of reflection for the class in C.
Methods are defined as prototypes in headerfile:
METHOD_C struct SimpleClass_Test_t* ctorO_SimpleClass_Test(ObjectJc* othis, ThCxt* _thCxt);
typedef int32 MT_addValue_SimpleClass_Test(SimpleClass_Test_s* ythis, int32 value, ThCxt* _thCxt);
METHOD_C int32 addValue_SimpleClass_Test_F(SimpleClass_Test_s* ythis, int32 value, ThCxt* _thCxt);
METHOD_C int32 addValue_SimpleClass_Test(SimpleClass_Test_s* ythis, int32 value, ThCxt* _thCxt);
- The first line is the constructor definition, auto generated.
- The second line is the method type definition as a so named C-function pointer type.
It is used in the method table.
- The third line declares the final version of the method,
whereas the forth line declares that method definition, which executes a dynamic linked call.
The header file contains at last the method table type definition:
extern const char sign_Mtbl_SimpleClass_Test[]; //marker for methodTable check
typedef struct Mtbl_SimpleClass_Test_t
{ MtblHeadJc head;
MT_addValue_SimpleClass_Test* addValue;
Mtbl_ObjectJc ObjectJc;
} Mtbl_SimpleClass_Test;
See
Docu.D_SuperClassesAndInterfaces.D8_gen_MethodTable().