1 #ifndef __FT_OBJECT_H__
2 #define __FT_OBJECT_H__
9 /**************************************************************
14 * handle to a FreeType Object. See @FT_ObjectRec
16 typedef struct FT_ObjectRec_* FT_Object;
19 /**************************************************************
24 * handle to a constant class handle to a FreeType Object.
26 * Note that a class is itself a @FT_Object and are dynamically
27 * allocated on the heap.
30 * @FT_ClassRec, @FT_Object, @FT_ObjectRec, @FT_Type, @FT_TypeRec
32 typedef const struct FT_ClassRec_* FT_Class;
35 /**************************************************************
40 * handle to a constant structure (of type @FT_TypeRec) used
41 * to describe a given @FT_Class type to the FreeType object
44 typedef const struct FT_TypeRec_* FT_Type;
48 /**************************************************************
50 * @struct: FT_ObjectRec
53 * a structure describing the root fields of all @FT_Object
54 * class instances in FreeType
57 * clazz :: handle to the object's class
58 * ref_count :: object's reference count. Starts at 1
60 typedef struct FT_ObjectRec_
68 /**************************************************************
70 * @macro: FT_OBJECT (x)
73 * a useful macro to type-cast anything to a @FT_Object
74 * handle. No check performed..
76 #define FT_OBJECT(x) ((FT_Object)(x))
79 /**************************************************************
81 * @macro: FT_OBJECT_P (x)
84 * a useful macro to type-cast anything to a pointer to
87 #define FT_OBJECT_P(x) ((FT_Object*)(x))
90 /**************************************************************
92 * @macro: FT_OBJECT__CLASS (obj)
95 * a useful macro to return the class of any object
97 #define FT_OBJECT__CLASS(x) FT_OBJECT(x)->clazz
100 /**************************************************************
102 * @macro: FT_OBJECT__REF_COUNT (obj)
105 * a useful macro to return the reference count of any object
107 #define FT_OBJECT__REF_COUNT(x) FT_OBJECT(x)->ref_count
110 /**************************************************************
112 * @macro: FT_OBJECT__MEMORY (obj)
115 * a useful macro to return a handle to the memory manager
116 * used to allocate a given object
118 #define FT_OBJECT__MEMORY(x) FT_CLASS__MEMORY(FT_OBJECT(x)->clazz)
121 /**************************************************************
123 * @macro: FT_OBJECT__LIBRARY (obj)
126 * a useful macro to return a handle to the library handle
127 * that owns the object
129 #define FT_OBJECT__LIBRARY(x) FT_CLASS__LIBRARY(FT_OBJECT(x)->clazz)
132 /**************************************************************
134 * @functype: FT_Object_InitFunc
137 * a function used to initialize a new object
140 * object :: target object handle
141 * init_data :: optional pointer to initialization data
144 * error code. 0 means success
146 typedef FT_Error (*FT_Object_InitFunc)( FT_Object object,
147 FT_Pointer init_data );
149 /**************************************************************
151 * @functype: FT_Object_DoneFunc
154 * a function used to finalize a given object
157 * object :: handle to target object
159 typedef void (*FT_Object_DoneFunc)( FT_Object object );
162 /**************************************************************
164 * @struct: FT_ClassRec
167 * a structure used to describe a given object class within
171 * object :: root @FT_ObjectRec fields, since each class is
172 * itself an object. (it's an instance of the
173 * "metaclass", a special object of the FreeType
174 * object sub-system.)
176 * magic :: a 32-bit magic number used for decoding
177 * super :: pointer to super class
178 * type :: the @FT_Type descriptor of this class
179 * memory :: the current memory manager handle
180 * library :: the current library handle
181 * info :: an opaque pointer to class-specific information
182 * managed by the FreeType object sub-system
184 * class_done :: the class destructor function
186 * obj_size :: size of class instances in bytes
187 * obj_init :: class instance constructor
188 * obj_done :: class instance destructor
190 typedef struct FT_ClassRec_
200 FT_Object_DoneFunc class_done;
203 FT_Object_InitFunc obj_init;
204 FT_Object_DoneFunc obj_done;
209 /**************************************************************
211 * @macro: FT_CLASS (x)
214 * a useful macro to convert anything to a class handle
217 #define FT_CLASS(x) ((FT_Class)(x))
220 /**************************************************************
222 * @macro: FT_CLASS_P (x)
225 * a useful macro to convert anything to a pointer to a class
226 * handle without checks
228 #define FT_CLASS_P(x) ((FT_Class*)(x))
231 /**************************************************************
233 * @macro: FT_CLASS__MEMORY (clazz)
236 * a useful macro to return the memory manager handle of a
239 #define FT_CLASS__MEMORY(x) FT_CLASS(x)->memory
242 /**************************************************************
244 * @macro: FT_CLASS__LIBRARY (clazz)
247 * a useful macro to return the library handle of a
250 #define FT_CLASS__LIBRARY(x) FT_CLASS(x)->library
254 /**************************************************************
256 * @macro: FT_CLASS__TYPE (clazz)
259 * a useful macro to return the type of a given class
262 #define FT_CLASS__TYPE(x) FT_CLASS(x)->type
265 #define FT_CLASS__INFO(x) FT_CLASS(x)->info
266 #define FT_CLASS__MAGIC(x) FT_CLASS(x)->magic
269 /**************************************************************
271 * @struct: FT_TypeRec
274 * a structure used to describe a given class to the FreeType
278 * name :: class name. only used for debugging
279 * super :: type of super-class. NULL if none
281 * class_size :: size of class structure in bytes
282 * class_init :: class constructor
283 * class_done :: class finalizer
285 * obj_size :: instance size in bytes
286 * obj_init :: instance constructor. can be NULL
287 * obj_done :: instance destructor. can be NULL
290 * if 'obj_init' is NULL, the class will use it's parent
291 * constructor, if any
293 * if 'obj_done' is NULL, the class will use it's parent
296 * the object sub-system allocates a new class, copies
297 * the content of its super-class into the new structure,
298 * _then_ calls 'clazz_init'.
300 * 'class_init' and 'class_done' can be NULL, in which case
301 * the parent's class constructor and destructor wil be used
303 typedef struct FT_TypeRec_
309 FT_Object_InitFunc class_init;
310 FT_Object_DoneFunc class_done;
313 FT_Object_InitFunc obj_init;
314 FT_Object_DoneFunc obj_done;
319 /**************************************************************
321 * @macro: FT_TYPE (x)
324 * a useful macro to convert anything to a class type handle
327 #define FT_TYPE(x) ((FT_Type)(x))
330 /**************************************************************
332 * @function: ft_object_check
335 * checks that a handle points to a valid @FT_Object
338 * obj :: handle/pointer
341 * 1 iff the handle points to a valid object. 0 otherwise
344 ft_object_check( FT_Pointer obj );
347 /**************************************************************
349 * @function: ft_object_is_a
352 * checks that a handle points to a valid @FT_Object that
353 * is an instance of a given class (or of any of its sub-classes)
356 * obj :: handle/pointer
357 * clazz :: class handle to check
360 * 1 iff the handle points to a valid 'clazz' instance. 0
364 ft_object_is_a( FT_Pointer obj,
368 /**************************************************************
370 * @function: ft_object_create
373 * create a new object (class instance)
376 * aobject :: new object handle. NULL in case of error
379 * clazz :: object's class pointer
380 * init_data :: optional pointer to initialization data
383 * error code. 0 means success
386 ft_object_create( FT_Object *aobject,
388 FT_Pointer init_data );
391 /**************************************************************
393 * @function: ft_object_create_from_type
396 * create a new object (class instance) from a @FT_Type
399 * aobject :: new object handle. NULL in case of error
402 * type :: object's type descriptor
403 * init_data :: optional pointer to initialization data
406 * error code. 0 means success
409 * this function is slower than @ft_object_create
411 * this is equivalent to calling @ft_class_from_type followed by
415 ft_object_create_from_type( FT_Object *aobject,
417 FT_Pointer init_data,
418 FT_Library library );
422 /**************************************************************
424 * @macro FT_OBJ_CREATE (object,class,init)
427 * a convenient macro used to create new objects. see
428 * @ft_object_create for details
430 #define FT_OBJ_CREATE( _obj, _clazz, _init ) \
431 ft_object_create( FT_OBJECT_P(&(_obj)), _clazz, _init )
434 /**************************************************************
436 * @macro FT_CREATE (object,class,init)
439 * a convenient macro used to create new objects. It also
440 * sets an _implicit_ local variable named "error" to the error
441 * code returned by the object constructor.
443 #define FT_CREATE( _obj, _clazz, _init ) \
444 FT_SET_ERROR( FT_OBJ_CREATE( _obj, _clazz, _init ) )
446 /**************************************************************
448 * @macro FT_OBJ_CREATE_FROM_TYPE (object,type,init)
451 * a convenient macro used to create new objects. see
452 * @ft_object_create_from_type for details
454 #define FT_OBJ_CREATE_FROM_TYPE( _obj, _type, _init, _lib ) \
455 ft_object_create_from_type( FT_OBJECT_P(&(_obj)), _type, _init, _lib )
458 /**************************************************************
460 * @macro FT_CREATE_FROM_TYPE (object,type,init)
463 * a convenient macro used to create new objects. It also
464 * sets an _implicit_ local variable named "error" to the error
465 * code returned by the object constructor.
467 #define FT_CREATE_FROM_TYPE( _obj, _type, _init, _lib ) \
468 FT_SET_ERROR( FT_OBJ_CREATE_FROM_TYPE( _obj, _type, _init, _lib ) )
473 /**************************************************************
475 * @function: ft_class_from_type
478 * retrieves the class object corresponding to a given type
479 * descriptor. The class is created when needed
482 * aclass :: handle to corresponding class object. NULL in
486 * type :: type descriptor handle
487 * library :: library handle
490 * error code. 0 means success
493 ft_class_from_type( FT_Class *aclass,
495 FT_Library library );
500 #include FT_INTERNAL_HASH_H
502 typedef struct FT_ClassHNodeRec_* FT_ClassHNode;
504 typedef struct FT_ClassHNodeRec_
506 FT_HashNodeRec hnode;
512 typedef struct FT_MetaClassRec_
514 FT_ClassRec clazz; /* the meta-class is a class itself */
515 FT_HashRec type_to_class; /* the type => class hash table */
517 } FT_MetaClassRec, *FT_MetaClass;
520 /* initialize meta class */
522 ft_metaclass_init( FT_MetaClass meta,
523 FT_Library library );
525 /* finalize meta class - destroy all registered class objects */
527 ft_metaclass_done( FT_MetaClass meta );
533 #endif /* __FT_OBJECT_H__ */