theKernel 10.0 NHI1 - theKernel - theLink - theConfig - theSq3Lite - theCompiler - theBrain - theGuard
c - tcl - py - rb - jv - cc
Loading...
Searching...
No Matches
MkTypeC_C_API

MkTypeS - class known as typ or type is used as class-base for a Managed-Object-Technology (MOT) type … More...

+ Collaboration diagram for MkTypeC_C_API:

Topics

 MkTypeC_Class_C_API
 MkTypeS - define the class …
 
 MkTypeC_TOR_C_API
 MkTypeS - various functions to create, initialize and destroy a type
 
 MkTypeC_Misc_C_API
 MkTypeS - various functions to work on type-data
 
 MkTypeC_Class_Define_C_API
 MkTypeS - low level definition, access and cast …
 
 MkSuperTypeC_Class_Define_C_API
 MkSuperTypeS - low level definition, access and cast …
 

Data Structures

struct  MkTypeS
 MkTypeS - class known as typ or type is used as class-base for a Managed-Object-Technology (MOT) type … More...
 
struct  MkSuperTypeS
 super-class-base, the MkTypeS using the super-macro-syntax for all non specific types … More...
 

Macros

#define MkTYP_R(x)
 cast a known-managed-object into an MkTypeS reference
 
#define MkTYP(x)
 cast a known-managed-object into an MkTypeS pointer
 
#define MkTypeSlotResolve(_tt, fptr, force)
 search and return functionPtr(slot) for the tt-type.
 
#define MkTypeSlotCall(_tt, fptr, ...)
 

Functions

MK_TYP MkTyp (const MK_MNG mng)
 type-check and cast a unknown-managed-object into an MkTypeS pointer or MK_NULL if not possible
 
MK_TYPN MkTypN (const MK_MNGN mng)
 type-check and cast a unknown-managed-object into an MkTypeS pointer or MK_NULL if not possible
 
MK_EXTERN MK_PTR MkTypeSlotResolveP (MK_RT mkrt, MK_TYPN const type, size_t const offset, bool const force)
 hidden function for MkTypeSlotResolve
 

Detailed Description

MkTypeS - class known as typ or type is used as class-base for a Managed-Object-Technology (MOT) type …

In Managed-Object-Technology (MOT) everything is a struct, there is a class-type-struc and a instance-type-struc:

The class-type is derived from the MkTypeS and provide the type-property (static-property) and the type-method (slot).

The instance-type is derived from the MkObjectS and provide the instance-property and the instance-method.

The instance is full defined by min 4 structs and optional multiple base-structs/type(s) :

  1. instance-type -> instance-base(s) -> instance-final (MkObjectS)
  2. class-type -> class-base(s) -> class-final (MkTypeS)
  3. example:
    // instance-type | class-type
    // --------------------------------- | ---------------------------
    // |
    struct MyClassS { | struct MyClassTypeS { // default: MkSuperTypeS
    union { | union {
    // required 'instance-final' | // always MkObjectS, a 'type' is also an 'object' !!
    struct MkObjectS { | struct MkObjectS obj;
    ... (pointer) | // required 'class-final'
    MK_TYP type; -> | struct MkTypeS typ;
    ... | ...
    } obj; | ...
    // optional 'instance-base' | // optional 'class-base'
    struct MyBaseClassS base; | struct MyBaseTypeS base;
    ... | ...
    } super; | } super;
    ... | ...
    } | }
    object header …
    MkTypeS - class known as typ or type is used as class-base for a Managed-Object-Technology (MOT) type...

The following naming-convention exist for the C-API (example: MkBufferC)

name definition
MkSuperTypeS super-class-base, the MkTypeS using the super-macro-syntax for all non specific types
MkBufferS instance-type → This is the main-struct to define an instance
MkBufferST instance-type as MkSuperTypeS-class-type
MkBufferSTT instance-type as MkTypeS-class-type (cast from MkBufferST into MkTypeS)
MkBufferC_T class as MkSuperTypeS-class-type, useable in a class-macro as: class##_T
MkBufferC_TT class as MkTypeS-class-type, useable in a class-macro as: class##_TT
MK_BUF class-shortcut for struct MkBufferS *, all shortcut using the XX_YYY syntax (only for public API)
MK_BUFR class-shortcut for const struct MkBufferS *, all const shortcut using the XX_YYYC syntax (only for public API) …
MkBufferCR reference-shortcut for struct MkBufferS, all shortcut using the XX_YYYR syntax (only for public API)
MkBufferCT_X(instance) cast from an instance into the MkSuperTypeS-class-type
MkBufferCTT_X(instance) cast from an instance into the MkTypeS-class-type
MkBufferCT_TT(typ) cast from an MkTypeS-class-type into an MkSuperTypeS-class-type
MkBufferCT class as MkSuperTypeS-class-type for MkBufferC in the Target-Programming-Language (TPL)
MkBufferCTT class as MkTypeS-class-type for MkBufferC in the Target-Programming-Language (TPL)

The struct(s) are defined as:

The class-type is able to create the instance.
  • The class-final is a type not able to create an instance but used as base-class for the class-type and the class-base
  • The class-base is a type and is used to initialize the type-properties and type-methods (called slots).
    • slot is a method predefined in the type like constructor.
    • A list of all slots are defined in MkTypeS.
  • Example MkBufferC : class == MkTypeS -> MkSuperTypeS -> MkObjectST -> MkBufferST
The instance-type is able to configure the instance and provide access to the methods and slots.
  • The instance is a link between the instance-type and the class-type
  • Example MkBufferC : instance == MkBufferST + MkBufferS
  • The instance-base is a type and is used to provide the base-instance-properties
    • Example: The base MyBaseStruct add MyBaseStruct-properties
      struct MyBaseStruct {
      union {
      struct MkObjectS obj
      } super;
      // MyBaseStruct-properties
      }
      struct MyInstanceStruct {
      union {
      struct MkObjectS obj
      struct MyBaseStruct bse
      } super;
      // MyInstanceStruct-properties
      }

To use the specific-class-type as argument to a function or as property in a struct the common-class-type of type MkTypeS is used. To cast a specific-class-type into a common-class-type use:

  1. the path: type->super.typ
  2. the shortcut: MkTYP(type)->XYZ (pointer) or MkTYP_R(type).XYZ (reference)

To get the common-class-type from the instance use:

  1. the path: instance->super.obj.type
  2. the shortcut: MkOBJ(instance)->type (pointer) or MkOBJ_R(instance).type (reference)

To get the class-base from the class-type use:

  1. the path: instance->super.obj.type->base
  2. the shortcut: MkOBJ(instance)->type->base (pointer) or MkOBJ_R(instance).type->base (reference)

The predefined class-type is an instance of the default-class-type (MkSuperTypeS) …

_struct MkRuntimeS {
...
struct MkSuperTypeS _MkBufferST;
...
}
The MkRuntimeS provide a per-thread environment for LibMkKernel …
super-class-base, the MkTypeS using the super-macro-syntax for all non specific types …

The properties and slots of the class-type are predefined by the class-base and may be overwritten …

The following relationship between the three different struct exists:

  1. The class-type and the class-base have the super-class MkTypeS and the instance not.
  2. The class-final is a super-class of an class-type.
  3. The class-type has the 3 attributes MkTypeS::objsig, MkTypeS::objmask and MkTypeS::objsize defined, the class-final not.
  4. The instance has access to the class-type using the cast (example MkBufferCT_X(instance))
  5. The class-type has access to the class-base using MkTypeS::base and to the type using MkObjectS::type.

Macro Definition Documentation

◆ MkTYP

#define MkTYP ( x)
Value:
(&MkTYP_R(x))
#define MkTYP_R(x)
cast a known-managed-object into an MkTypeS reference

cast a known-managed-object into an MkTypeS pointer

Definition at line 3763 of file LibMkKernel_mk.h.

◆ MkTYP_R

#define MkTYP_R ( x)
Value:
(*(x)).super.typ

cast a known-managed-object into an MkTypeS reference

Definition at line 3761 of file LibMkKernel_mk.h.

◆ MkTypeSlotCall

#define MkTypeSlotCall ( _tt,
fptr,
... )
Value:
do { \
typeof((_tt)->fptr) slot = MkTypeSlotResolve((_tt),fptr,false); \
if (slot) (*slot)(MK_RT_CALL __VA_ARGS__); \
} while (false)
#define MK_RT_CALL
#define MkTypeSlotResolve(_tt, fptr, force)
search and return functionPtr(slot) for the tt-type.

Definition at line 3869 of file LibMkKernel_mk.h.

3869#define MkTypeSlotCall(_tt,fptr,...) do { \
3870 typeof((_tt)->fptr) slot = MkTypeSlotResolve((_tt),fptr,false); \
3871 if (slot) (*slot)(MK_RT_CALL __VA_ARGS__); \
3872} while (false)

◆ MkTypeSlotResolve

#define MkTypeSlotResolve ( _tt,
fptr,
force )
Value:
({ \
MK_TYP tt = (_tt) ; /* _tt my be long */ \
tt == NULL ? NULL : /* type not valid */ \
!force && tt->fptr == (MK_PTR) 0x1 ? NULL : /* already resolved, NOT found */ \
tt->fptr > (typeof(tt->fptr)) 0x1 ? tt->fptr : /* already resolved, NOT NULL, found */ \
tt == MkTypeSTT ? NULL : /* already at the ROOT of the type */ \
(typeof(tt->fptr)) MkTypeSlotResolveP(MK_RT_CALL tt, offsetof(struct MkTypeS, fptr), force); \
}) \
MK_PTRB * MK_PTR
generic pointer data-type
MK_EXTERN MK_PTR MkTypeSlotResolveP(MK_RT mkrt, MK_TYPN const type, size_t const offset, bool const force)
hidden function for MkTypeSlotResolve
#define MkTypeSTT
instance-type as MkTypeS-class-type

search and return functionPtr(slot) for the tt-type.

The search start with tt-type and end with MkTypeS, the root of all types. With force=false the search is done only once and not-found is marked with 0x1. To be sure your functionPtr(slot) will be found add the slot very-early into the library boot. A good place will be at the Setup (constructor) or at the RuntimeInit.

Returns
the functionPtr(slot) or MK_NULL if not found
Parameters
[in]_ttthe start of the search, use MkTYP(mng) as input
[in]fptrthe attribute of tt to search for, use man offsetof for more info
[in]forceuse/notuse the 0x1 hint. If a new functionPtr(slot) was added the force=true will find it.
Attention
, this is a macro, only use arguments without overhead.

Definition at line 3860 of file LibMkKernel_mk.h.

3860#define MkTypeSlotResolve(_tt,fptr,force) ({ \
3861 MK_TYP tt = (_tt) ; /* _tt my be long */ \
3862 tt == NULL ? NULL : /* type not valid */ \
3863 !force && tt->fptr == (MK_PTR) 0x1 ? NULL : /* already resolved, NOT found */ \
3864 tt->fptr > (typeof(tt->fptr)) 0x1 ? tt->fptr : /* already resolved, NOT NULL, found */ \
3865 tt == MkTypeSTT ? NULL : /* already at the ROOT of the type */ \
3866 (typeof(tt->fptr)) MkTypeSlotResolveP(MK_RT_CALL tt, offsetof(struct MkTypeS, fptr), force); \
3867}) \
3868

Function Documentation

◆ MkTyp()

MK_TYP MkTyp ( const MK_MNG mng)
inline

type-check and cast a unknown-managed-object into an MkTypeS pointer or MK_NULL if not possible

Definition at line 3740 of file LibMkKernel_mk.h.

3740 {
3741 if (!MkObjCheck(mng)) return NULL;
3742 MK_OBJ obj = (MK_OBJ) mng;
3743 if (MkTypCheck(obj)) return (MK_TYP)obj;
3744 MK_TYP typ = obj->type;
3745 if (MkTypCheck(typ)) return typ;
3746 return NULL;
3747}
struct MkObjectS * MK_OBJ
class-shortcut for struct MkObjectS *, all shortcut using the XX_YYY syntax (only for public API) …
bool MkObjCheck(MK_MNGN mng)
check MkObjectS -> MkObjectS::signature …
bool MkTypCheck(MK_MNGN mng)
check MkTypeS -> MkObjectS::signature …
MK_TYP type
link to the object type

◆ MkTypeSlotResolveP()

MK_EXTERN MK_PTR MkTypeSlotResolveP ( MK_RT mkrt,
MK_TYPN const type,
size_t const offset,
bool const force )

hidden function for MkTypeSlotResolve

◆ MkTypN()

MK_TYPN MkTypN ( const MK_MNGN mng)
inline

type-check and cast a unknown-managed-object into an MkTypeS pointer or MK_NULL if not possible

Definition at line 3751 of file LibMkKernel_mk.h.

3751 {
3752 if (!MkObjCheck(mng)) return NULL;
3753 MK_OBJ obj = (MK_OBJ) mng;
3754 if (MkTypCheck(obj)) return (MK_TYPN)obj;
3755 MK_TYPN typ = obj->type;
3756 if (MkTypCheck(typ)) return typ;
3757 return NULL;
3758}