Abstract interface (function table) to adapt a concrete user type to a container which needs comparing nodes and nodes and keys.
This program is free software. You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
© 2012 Jörg Seebohn
Header file Typeadapt-Comparator.
Implementation file Typeadapt-Comparator impl.
typedef struct typeadapt_comparator_it typeadapt_comparator_it
Export typeadapt_comparator_it into global namespace.
test | |
unittest_ds_typeadapt_comparator | Test typeadapt_comparator_it functionality. |
int unittest_ds_typeadapt_comparator( void )
Test typeadapt_comparator_it functionality.
struct typeadapt_comparator_it
Declares interface for comparing two objects and key with object. If you change this interface do not forget to adapt typeadapt_comparator_EMBED and genericcast_typeadaptcomparator.
cmp_key_object | Compares key with an object. |
cmp_object | Compares two objects. |
lifetime | |
typeadapt_comparator_FREE | Static initializer. |
typeadapt_comparator_INIT | Static initializer. |
query | |
call-service | |
callcmpkeyobj_typeadaptcomparator | Calls function typeadapt_comparator_it.cmp_key_object. |
callcmpobj_typeadaptcomparator | Calls function typeadapt_comparator_it.cmp_object. |
generic | |
genericcast_typeadaptcomparator | Casts parameter adpcmp into pointer to typeadapt_comparator_it. |
typeadapt_comparator_DECLARE | Declares a derived interface from generic typeadapt_comparator_it. |
typeadapt_comparator_EMBED | Declares a derived interface from generic typeadapt_comparator_it. |
#define typeadapt_comparator_FREE { 0, 0 }
Static initializer. Sets all functions pointers of typeadapt_comparator_it to 0.
#define typeadapt_comparator_INIT( cmpkeyobj_f, cmpobj_f ) { cmpkeyobj_f, cmpobj_f }
Static initializer. Sets all function pointers to the provided values.
cmpkeyobj_f | Function pointer to function comparing key with object. See typeadapt_comparator_it.cmp_key_object. |
cmpobj_f | Function pointer to function comparing object with object. See typeadapt_comparator_it.cmp_object. |
int callcmpkeyobj_typeadaptcomparator( typeadapt_comparator_it * adpcmp, struct typeadapt_t * typeadp, const void * key, const struct typeadapt_object_t * robject )
Calls function typeadapt_comparator_it.cmp_key_object. The first parameter is of type typeadapt_comparator_it the others are the same as in typeadapt_comparator_it.cmp_key_object. This function is implemented as macro and supports types derived from typeadapt_comparator_it - see use of typeadapt_comparator_DECLARE.
int callcmpobj_typeadaptcomparator( typeadapt_comparator_it * adpcmp, struct typeadapt_t * typeadp, const struct typeadapt_object_t * lobject, const struct typeadapt_object_t * robject )
Calls function typeadapt_comparator_it.cmp_object. The first parameter is of type typeadapt_comparator_it the others are the same as in typeadapt_comparator_it.cmp_object. This function is implemented as macro and supports types derived from typeadapt_comparator_it - see use of typeadapt_comparator_DECLARE.
typeadapt_comparator_it * genericcast_typeadaptcomparator( void * adpcmp, TYPENAME typeadapter_t, TYPENAME object_t, TYPENAME key_t ) ;
Casts parameter adpcmp into pointer to typeadapt_comparator_it. The parameter adpcmp has to be of type “pointer to declared_it” where declared_it is the name used as first parameter in typeadapt_comparator_DECLARE. The second and third parameter must be the same as in typeadapt_comparator_DECLARE.
#define typeadapt_comparator_DECLARE( declared_it, typeadapter_t, object_t, key_t ) static inline void compiletimeassert##declared_it(void) { static_assert(sizeof(key_t)==sizeof(void*), "compatible with cmp_key_object") ; } typedef struct declared_it declared_it ; struct declared_it { typeadapt_comparator_EMBED(typeadapter_t, object_t, key_t) ; }
Declares a derived interface from generic typeadapt_comparator_it. It is structural compatible with typeadapt_comparator_it. See typeadapt_comparator_it for a list of contained functions.
declared_it | The name of the structure which is declared as the interface. The name should have the suffix “_it”. |
typeadapter_t | The adapter type which implements all interface functions. The first parameter in every function is a pointer to this type. |
object_t | The object type that typeadapt_comparator_it supports. |
key_t | The key type that typeadapt_comparator_it supports. Must be of size sizeof(void*). |
#define typeadapt_comparator_EMBED( typeadapter_t, object_t, key_t ) int (* cmp_key_object) (typeadapter_t * typeadp, const key_t lkey, const object_t * robject) ; int (* cmp_object) (typeadapter_t * typeadp, const object_t * lobject, const object_t * robject)
Declares a derived interface from generic typeadapt_comparator_it. It is structural compatible with typeadapt_comparator_it. See typeadapt_comparator_it for a list of contained functions.
typeadapter_t | The adapter type which implements all interface functions. The first parameter in every function is a pointer to this type. |
object_t | The object type that typeadapt_comparator_it supports. |
key_t | The key type that typeadapt_comparator_it supports. Must be of size sizeof(void*). |
#define genericcast_typeadaptcomparator( adpcmp, typeadapter_t, object_t, key_t ) ( __extension__ ({ static_assert( offsetof(typeadapt_comparator_it, cmp_key_object) == offsetof(typeof(*(adpcmp)), cmp_key_object) && offsetof(typeadapt_comparator_it, cmp_object) == offsetof(typeof(*(adpcmp)), cmp_object), "ensure same structure") ; if (0) { int _err = (adpcmp)->cmp_key_object((typeadapter_t*)0, (const key_t)0, (const object_t*)0) ; _err += (adpcmp)->cmp_object((typeadapter_t*)0, (const object_t*)0, (const object_t*)0) ; (void) _err ; } (typeadapt_comparator_it*) (adpcmp) ; }))
Implements typeadapt_comparator_it.genericcast_typeadaptcomparator.
Export typeadapt_comparator_it into global namespace.
typedef struct typeadapt_comparator_it typeadapt_comparator_it
Declares interface for comparing two objects and key with object.
struct typeadapt_comparator_it
Test typeadapt_comparator_it functionality.
int unittest_ds_typeadapt_comparator( void )
Compares key with an object.
int ( * cmp_key_object ) (struct typeadapt_t * typeadp, const void * lkey, const struct typeadapt_object_t * robject)
Compares two objects.
int ( * cmp_object ) (struct typeadapt_t * typeadp, const struct typeadapt_object_t * lobject, const struct typeadapt_object_t * robject)
Static initializer.
#define typeadapt_comparator_FREE { 0, 0 }
Static initializer.
#define typeadapt_comparator_INIT( cmpkeyobj_f, cmpobj_f ) { cmpkeyobj_f, cmpobj_f }
Calls function typeadapt_comparator_it.cmp_key_object.
int callcmpkeyobj_typeadaptcomparator( typeadapt_comparator_it * adpcmp, struct typeadapt_t * typeadp, const void * key, const struct typeadapt_object_t * robject )
Calls function typeadapt_comparator_it.cmp_object.
int callcmpobj_typeadaptcomparator( typeadapt_comparator_it * adpcmp, struct typeadapt_t * typeadp, const struct typeadapt_object_t * lobject, const struct typeadapt_object_t * robject )
Casts parameter adpcmp into pointer to typeadapt_comparator_it.
typeadapt_comparator_it * genericcast_typeadaptcomparator( void * adpcmp, TYPENAME typeadapter_t, TYPENAME object_t, TYPENAME key_t ) ;
Declares a derived interface from generic typeadapt_comparator_it.
#define typeadapt_comparator_DECLARE( declared_it, typeadapter_t, object_t, key_t ) static inline void compiletimeassert##declared_it(void) { static_assert(sizeof(key_t)==sizeof(void*), "compatible with cmp_key_object") ; } typedef struct declared_it declared_it ; struct declared_it { typeadapt_comparator_EMBED(typeadapter_t, object_t, key_t) ; }
Declares a derived interface from generic typeadapt_comparator_it.
#define typeadapt_comparator_EMBED( typeadapter_t, object_t, key_t ) int (* cmp_key_object) (typeadapter_t * typeadp, const key_t lkey, const object_t * robject) ; int (* cmp_object) (typeadapter_t * typeadp, const object_t * lobject, const object_t * robject)
Implements typeadapt_comparator_it.genericcast_typeadaptcomparator.
#define genericcast_typeadaptcomparator( adpcmp, typeadapter_t, object_t, key_t ) ( __extension__ ({ static_assert( offsetof(typeadapt_comparator_it, cmp_key_object) == offsetof(typeof(*(adpcmp)), cmp_key_object) && offsetof(typeadapt_comparator_it, cmp_object) == offsetof(typeof(*(adpcmp)), cmp_object), "ensure same structure") ; if (0) { int _err = (adpcmp)->cmp_key_object((typeadapter_t*)0, (const key_t)0, (const object_t*)0) ; _err += (adpcmp)->cmp_object((typeadapter_t*)0, (const object_t*)0, (const object_t*)0) ; (void) _err ; } (typeadapt_comparator_it*) (adpcmp) ; }))