Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

geomlib/class.h File Reference

GEOMLIB - Simple object types emulation for C99. More...

Go to the source code of this file.

Data Structures

struct  geom_class
struct  geom_o
 Class geom_o declaration (ancestor of all classes). More...

struct  geom_o_class

Defines

#define GEOM_CLASS_ID_COUNT   0x100
#define GEOM_CLASS(nclass)   ((struct geom_class *)(void *)&GLUEE3(geom_, nclass, _class))
#define GEOM_CLASS_VMT(c, v)   (geom_##c##_class.v)
#define GEOM_CLASS_HEAD(c, p)
#define GEOM_CLASS_DEF(c)
#define GEOM_CLASS_INIT(c)
#define geom_o_VMT
#define geom_o_INIT   .destroy = (void (*)(void *)) &geom_o_destroy,
#define GEOM_INSTANCE_IS_ASSERT(nclass, instance)   GEOM_ASSERT2(instance_is,instance,GEOM_CLASS(nclass))
 Assertion pass for any valid instance pointer, that is descendant of a given class.

#define GEOM_INSTANCE_IS_ASSERTX(nclass, instance)   ((struct geom_##nclass *)GEOM_ASSERTX2(instance_is,instance,GEOM_CLASS(nclass)))
#define GEOM_INSTANCE_VMT(instance, nclass, entry)
 For a given instance returns item in virtual methods table.

#define GEOM_INSTANCE_INIT(instance, nclass)   do{geom_instance_init((instance),GEOM_CLASS(nclass));}while(0)
 Initialize buffer to a given class instance, no constructor is called.

#define GEOM_INSTANCE_ZERO_INIT(instance, nclass)   do{geom_instance_zero_init((instance),GEOM_CLASS(nclass));}while(0)
 Initialize zero buffer to a given class instance, no constructor is called.

#define GEOM_INSTANCE_NEW(nclass)   (geom_instance_new(GEOM_CLASS(nclass)))
 Allocate instance of a given class, no constructor is called.

#define GEOM_INSTANCE_DESTROY(i)   do{geom_instance_destroy(i);}while(0)
 Call virtual destructor and destroy instance.

#define GEOM_INSTANCE_DESTROY2(i, nclass)   do{GEOM_INSTANCE_IS_ASSERT(nclass,i);GLUEE3(geom_,nclass,_destroy)((void *)i);}while(0)
 Direct call to destructor and destroy instance.

#define GEOM_INSTANCE_FREE(i)   do{GEOM_INSTANCE_DESTROY(i);xfree(i);}while(0)
 Call virtual destructor and free instance.

#define GEOM_INSTANCE_FREE2(i, nclass)   do{GEOM_INSTANCE_DESTROY2(i,nclass);xfree(i);}while(0)
 Direct call to destructor and destroy instance.

#define GEOM_INSTANCE_CREATE(instance, nclass, constructor)   do{ GEOM_INSTANCE_INIT(instance,nclass); constructor((void *)(instance)); }while(0)
 Initialize buffer to a given class instance and call constructor with only instance parameter.

#define GEOM_INSTANCE_ZERO_CREATE(instance, nclass, constructor)   do{ GEOM_INSTANCE_ZERO_INIT(instance,nclass); constructor((void *)(instance)); }while(0)
 Initialize zero buffer to a given class instance and call constructor with only instance parameter.

#define GEOM_INSTANCE_CREATE2(instance, nclass, constructor,)   do{ GEOM_INSTANCE_INIT(instance,nclass); constructor((void *)(instance), __VA_ARGS__); }while(0)
 Initialize buffer to a given class instance and call constructor with more parameters.

#define GEOM_INSTANCE_ZERO_CREATE2(instance, nclass, constructor,)   do{ GEOM_INSTANCE_ZERO_INIT(instance,nclass);constructor((void *)(instance), __VA_ARGS__); }while(0)
 Initialize zero buffer to a given class instance and call constructor with more parameters.

#define GEOM_INSTANCE_NEW_CREATE(pinstance, nclass, constructor)   do{ pinstance=GEOM_INSTANCE_NEW(nclass);constructor((void *)(pinstance)); }while(0)
 Allocate instance of a given class and call constructor with only instance parameter.

#define GEOM_INSTANCE_NEW_CREATE2(pinstance, nclass, constructor,)   do{ pinstance=GEOM_INSTANCE_NEW(nclass);constructor((void *)(pinstance), __VA_ARGS__); }while(0)
 Allocate instance of a given class and call constructor with more parameters.

#define GEOM_INSTANCE_FLAGS(instance)   (((struct geom_o *)(instance))->flags)
#define GEOM_INSTANCE_FLAGS2(instance)   (((struct geom_o *)(instance))->flags2)

Functions

const struct geom_class * geom_class_assert (GEOM_ASSERT_DEF, const struct geom_class *pclass)
const void * geom_instance_assert (GEOM_ASSERT_DEF, const void *instance)
const void * geom_instance_is_assert (GEOM_ASSERT_DEF, const void *instance, const struct geom_class *pclass)
geom_class * geom_instance_class (void *instance)
 Returns class pointer to a given instance.

void * geom_instance_init (void *instance, struct geom_class *pclass)
 Initialize buffer to a given class instance.

void * geom_instance_zero_init (void *instance, struct geom_class *pclass)
 Initialize zero buffer to a given class instance.

void * geom_instance_new (struct geom_class *pclass)
 Allocate and initialize.

void geom_instance_destroy (void *instance)
 Call virtual destructor.

void geom_o_create (const struct geom_o UNUSED *o)
 Empty constructor.

void geom_o_destroy (const struct geom_o UNUSED *o)
 Empty destructor.

uns geom_instance_size (const void *instance)
 Return size of a given instance structure in bytes.

char * geom_instance_class_name (const void *instance)
 Return instance class name.

int geom_instance_is (const void *instance, const struct geom_class *pclass)

Variables

uns geom_class_count
geom_class * geom_class_table [GEOM_CLASS_ID_COUNT]
geom_o_class geom_o_class


Detailed Description

GEOMLIB - Simple object types emulation for C99.

Copyright (c) 2004-2005 The VRR Team <vrr@ucw.cz> This program is distributed under GNU General Public License, see COPYING.


Define Documentation

#define GEOM_CLASS_DEF  ) 
 

Value:

struct geom_##c##_class geom_##c##_class = { \
        .instance_size = sizeof(struct geom_##c), \
        .class_name = #c, \
        geom_##c##_INIT }

#define GEOM_CLASS_HEAD c,
 ) 
 

Value:

static inline struct geom_class *geom_##c##_parent(void) { return GEOM_CLASS(p); } \
        extern struct geom_##c##_class {geom_##c##_VMT} geom_##c##_class

#define GEOM_CLASS_INIT  ) 
 

Value:

do { geom_class_count++; GEOM_BASSERT(geom_class_count < GEOM_CLASS_ID_COUNT); \
        geom_class_table[geom_class_count] = GEOM_CLASS(c); \
        GEOM_CLASS(c)->class_id = geom_class_count; \
        GEOM_CLASS(c)->class_parent = geom_##c##_parent(); } while(0)

#define GEOM_INSTANCE_DESTROY2 i,
nclass   )     do{GEOM_INSTANCE_IS_ASSERT(nclass,i);GLUEE3(geom_,nclass,_destroy)((void *)i);}while(0)
 

Direct call to destructor and destroy instance.

Can be a little faster than GEOM_INSTANCE_DESTROY.

#define GEOM_INSTANCE_FREE2 i,
nclass   )     do{GEOM_INSTANCE_DESTROY2(i,nclass);xfree(i);}while(0)
 

Direct call to destructor and destroy instance.

Can be a little faster than GEOM_INSTANCE_FREE.

#define GEOM_INSTANCE_VMT instance,
nclass,
entry   ) 
 

Value:

(((struct geom_##nclass##_class *) \
                geom_class_table[((struct geom_o *)GEOM_ASSERTX2(instance_is,instance,GEOM_CLASS(nclass)))->class_id])->entry)
For a given instance returns item in virtual methods table.

Instance must be descendant of given class.

#define geom_o_VMT
 

Value:

u8 class_id; \
        uns instance_size; \
        char *class_name; \
        struct geom_class *class_parent; \
        void (*destroy)(void *);


Function Documentation

void* geom_instance_init void *  instance,
struct geom_class *  pclass
[inline, static]
 

Initialize buffer to a given class instance.

No constructor is called.

void* geom_instance_new struct geom_class *  pclass  )  [inline, static]
 

Allocate and initialize.

No constructor is called.

void* geom_instance_zero_init void *  instance,
struct geom_class *  pclass
[inline, static]
 

Initialize zero buffer to a given class instance.

No constructor is called..


Generated on Tue Dec 9 16:30:09 2008 for Vrr by doxygen 1.3.5