Typeadapt-GetKey

Abstract interface (function table) to adapt a concrete user type to a container which needs to get the key from a node as binary string.

Summary
Typeadapt-GetKeyAbstract interface (function table) to adapt a concrete user type to a container which needs to get the key from a node as binary string.
CopyrightThis program is free software.
Files
C-kern/api/ds/typeadapt/getkey.hHeader file Typeadapt-GetKey.
C-kern/ds/typeadapt/getkey.cImplementation file Typeadapt-GetKey impl.
Types
struct typeadapt_binarykey_tExport typeadapt_binarykey_t into global namespace.
struct typeadapt_getkey_itExport typeadapt_getkey_it into global namespace.
Functions
test
unittest_ds_typeadapt_getkeyTest typeadapt_getkey_it functionality.
typeadapt_binarykey_tDescribes byte aligned binary data used as key.
addrStart address of binary data of key.
sizeSize in bytes of binary data addr points to.
lifetime
typeadapt_binarykey_FREEStatic initializer.
typeadapt_binarykey_INITInits typeadapt_binarykey_t with size in bytes in start (lowest) memory address.
generic
genericcast_typeadaptbinarykeyCasts parameter conststr into pointer to typeadapt_binarykey_t.
typeadapt_getkey_itDeclares interface for getting a description of a binary key of the object.
getbinarykeyReturns in typeadapt_binarykey_t the description of a binary key.
lifetime
typeadapt_getkey_FREEStatic initializer.
typeadapt_getkey_INITStatic initializer.
query
call-service
callgetbinarykey_typeadaptgetkeyCalls function typeadapt_getkey_it.getbinarykey.
generic
genericcast_typeadaptgetkeyCasts parameter adpgetkey into pointer to typeadapt_getkey_it.
typeadapt_getkey_DECLAREDeclares a derived interface from generic typeadapt_getkey_it.
typeadapt_getkey_EMBEDDeclares a derived interface from generic typeadapt_getkey_it.
inline implementation
Macros
genericcast_typeadaptbinarykeyImplements typeadapt_binarykey_t.genericcast_typeadaptbinarykey.
genericcast_typeadaptgetkeyImplements typeadapt_getkey_it.genericcast_typeadaptgetkey.
Functions
callgetbinarykey_typeadaptgetkeyImplements typeadapt_getkey_it.callgetbinarykey_typeadaptgetkey.

Copyright

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.

Author

© 2012 Jörg Seebohn

Files

C-kern/api/ds/typeadapt/getkey.h

Header file Typeadapt-GetKey.

C-kern/ds/typeadapt/getkey.c

Implementation file Typeadapt-GetKey impl.

Types

struct typeadapt_binarykey_t

typedef struct typeadapt_binarykey_t typeadapt_binarykey_t

Export typeadapt_binarykey_t into global namespace.

struct typeadapt_getkey_it

typedef struct typeadapt_getkey_it typeadapt_getkey_it

Export typeadapt_getkey_it into global namespace.

Functions

test

unittest_ds_typeadapt_getkey

int unittest_ds_typeadapt_getkey(void)

Test typeadapt_getkey_it functionality.

typeadapt_binarykey_t

struct typeadapt_binarykey_t

Describes byte aligned binary data used as key.

Summary
addrStart address of binary data of key.
sizeSize in bytes of binary data addr points to.
lifetime
typeadapt_binarykey_FREEStatic initializer.
typeadapt_binarykey_INITInits typeadapt_binarykey_t with size in bytes in start (lowest) memory address.
generic
genericcast_typeadaptbinarykeyCasts parameter conststr into pointer to typeadapt_binarykey_t.

addr

const uint8_t * addr/*[size]*/

Start address of binary data of key.  The lowest address in memory.

size

size_t size

Size in bytes of binary data addr points to.

lifetime

typeadapt_binarykey_FREE

#define typeadapt_binarykey_FREE typeadapt_binarykey_INIT(0,
(const uint8_t*)0)

Static initializer.

typeadapt_binarykey_INIT

#define typeadapt_binarykey_INIT(size,
addr) { addr, size }

Inits typeadapt_binarykey_t with size in bytes in start (lowest) memory address.

generic

genericcast_typeadaptbinarykey

typeadapt_binarykey_t * genericcast_typeadaptbinarykey(void *conststr)

Casts parameter conststr into pointer to typeadapt_binarykey_t.  Parameter constr should be of type pointer to string_t.

typeadapt_getkey_it

struct typeadapt_getkey_it

Declares interface for getting a description of a binary key of the object.  If you change this interface do not forget to adapt typeadapt_getkey_EMBED and genericcast_typeadaptgetkey.

Summary
getbinarykeyReturns in typeadapt_binarykey_t the description of a binary key.
lifetime
typeadapt_getkey_FREEStatic initializer.
typeadapt_getkey_INITStatic initializer.
query
call-service
callgetbinarykey_typeadaptgetkeyCalls function typeadapt_getkey_it.getbinarykey.
generic
genericcast_typeadaptgetkeyCasts parameter adpgetkey into pointer to typeadapt_getkey_it.
typeadapt_getkey_DECLAREDeclares a derived interface from generic typeadapt_getkey_it.
typeadapt_getkey_EMBEDDeclares a derived interface from generic typeadapt_getkey_it.

getbinarykey

void (
   *getbinarykey
) (struct typeadapt_t * typeadp, struct typeadapt_object_t * node, /*out*/typeadapt_binarykey_t * binkey)

Returns in typeadapt_binarykey_t the description of a binary key.

lifetime

typeadapt_getkey_FREE

#define typeadapt_getkey_FREE { 0 }

Static initializer.  Sets all functions pointers of typeadapt_getkey_it to 0.

typeadapt_getkey_INIT

#define typeadapt_getkey_INIT(getbinarykey_f) { getbinarykey_f }

Static initializer.  Sets all function pointers to the provided values.

Parameters

getbinarykey_fFunction pointer to function returning the binary key of an object.  See typeadapt_getkey_it.getbinarykey.

query

call-service

callgetbinarykey_typeadaptgetkey

void callgetbinarykey_typeadaptgetkey(typeadapt_getkey_it *adpgetkey,
struct typeadapt_t *typeadp,
struct typeadapt_object_t *node,
/*out*/typeadapt_binarykey_t *binkey)

Calls function typeadapt_getkey_it.getbinarykey.  The first parameter is of type typeadapt_getkey_it the others are the same as in typeadapt_getkey_it.getbinarykey.  This function is implemented as macro and supports types derived from typeadapt_getkey_it - see use of typeadapt_getkey_DECLARE.

generic

genericcast_typeadaptgetkey

typeadapt_getkey_it * genericcast_typeadaptgetkey(void *adpgetkey,
TYPENAME typeadapter_t,
TYPENAME object_t) ;

Casts parameter adpgetkey into pointer to typeadapt_getkey_it.  The parameter adpgetkey has to be of type “pointer to declared_it” where declared_it is the name used as first parameter in typeadapt_getkey_DECLARE.  The second and third parameter must be the same as in typeadapt_getkey_DECLARE.

typeadapt_getkey_DECLARE

#define typeadapt_getkey_DECLARE(
   declared_it,
   typeadapter_t,
   object_t
) typedef struct declared_it declared_it ; struct declared_it { typeadapt_getkey_EMBED(typeadapter_t, object_t) ; }

Declares a derived interface from generic typeadapt_getkey_it.  It is structural compatible with typeadapt_getkey_it.  See typeadapt_getkey_it for a list of contained functions.

Parameter

declared_itThe name of the structure which is declared as the interface.  The name should have the suffix “_it”.
typeadapter_tThe adapter type which implements all interface functions.  The first parameter in every function is a pointer to this type.
object_tThe object type that typeadapt_getkey_it supports.

typeadapt_getkey_EMBED

#define typeadapt_getkey_EMBED(
   typeadapter_t,
   object_t
) void (* getbinarykey) (typeadapter_t * typeadp, object_t * node, /*out*/typeadapt_binarykey_t * binkey)

Declares a derived interface from generic typeadapt_getkey_it.  It is structural compatible with typeadapt_getkey_it.  See typeadapt_getkey_it for a list of contained functions.

Parameter

typeadapter_tThe adapter type which implements all interface functions.  The first parameter in every function is a pointer to this type.
object_tThe object type that typeadapt_getkey_it supports.

Macros

genericcast_typeadaptbinarykey

#define genericcast_typeadaptbinarykey(
   conststr
) ( __extension__ ({ typeof(conststr) _conststr = (conststr) ; static_assert( offsetof(typeadapt_binarykey_t, addr) == offsetof(typeof(*(conststr)), addr) && offsetof(typeadapt_binarykey_t, size) == offsetof(typeof(*(conststr)), size), "ensure same structure") ; if (0) { int _err = 0 ; const uint8_t * _addr = _conststr->addr ; size_t _size = _conststr->size ; _err = (int) (_addr[0] + _size) ; (void) _err ; } (typeadapt_binarykey_t*) _conststr ; }))

Implements typeadapt_binarykey_t.genericcast_typeadaptbinarykey.

genericcast_typeadaptgetkey

#define genericcast_typeadaptgetkey(
   adpgetkey,
   typeadapter_t,
   object_t
) ( __extension__ ({ static_assert( offsetof(typeadapt_getkey_it, getbinarykey) == offsetof(typeof(*(adpgetkey)), getbinarykey), "ensure same structure") ; if (0) { (adpgetkey)->getbinarykey( (typeadapter_t*)0, (object_t*)0, (typeadapt_binarykey_t*)0) ; } (typeadapt_getkey_it*) (adpgetkey) ; }))

Implements typeadapt_getkey_it.genericcast_typeadaptgetkey.

Functions

callgetbinarykey_typeadaptgetkey

Abstract interface (function table) to adapt a concrete user type to a container which needs to get the key from a node as binary string.
Implements Typeadapt-GetKey.
typedef struct typeadapt_binarykey_t typeadapt_binarykey_t
Export typeadapt_binarykey_t into global namespace.
struct typeadapt_binarykey_t
Describes byte aligned binary data used as key.
typedef struct typeadapt_getkey_it typeadapt_getkey_it
Export typeadapt_getkey_it into global namespace.
struct typeadapt_getkey_it
Declares interface for getting a description of a binary key of the object.
int unittest_ds_typeadapt_getkey(void)
Test typeadapt_getkey_it functionality.
const uint8_t * addr/*[size]*/
Start address of binary data of key.
size_t size
Size in bytes of binary data addr points to.
#define typeadapt_binarykey_FREE typeadapt_binarykey_INIT(0,
(const uint8_t*)0)
Static initializer.
#define typeadapt_binarykey_INIT(size,
addr) { addr, size }
Inits typeadapt_binarykey_t with size in bytes in start (lowest) memory address.
typeadapt_binarykey_t * genericcast_typeadaptbinarykey(void *conststr)
Casts parameter conststr into pointer to typeadapt_binarykey_t.
void (
   *getbinarykey
) (struct typeadapt_t * typeadp, struct typeadapt_object_t * node, /*out*/typeadapt_binarykey_t * binkey)
Returns in typeadapt_binarykey_t the description of a binary key.
#define typeadapt_getkey_FREE { 0 }
Static initializer.
#define typeadapt_getkey_INIT(getbinarykey_f) { getbinarykey_f }
Static initializer.
void callgetbinarykey_typeadaptgetkey(typeadapt_getkey_it *adpgetkey,
struct typeadapt_t *typeadp,
struct typeadapt_object_t *node,
/*out*/typeadapt_binarykey_t *binkey)
Calls function typeadapt_getkey_it.getbinarykey.
typeadapt_getkey_it * genericcast_typeadaptgetkey(void *adpgetkey,
TYPENAME typeadapter_t,
TYPENAME object_t) ;
Casts parameter adpgetkey into pointer to typeadapt_getkey_it.
#define typeadapt_getkey_DECLARE(
   declared_it,
   typeadapter_t,
   object_t
) typedef struct declared_it declared_it ; struct declared_it { typeadapt_getkey_EMBED(typeadapter_t, object_t) ; }
Declares a derived interface from generic typeadapt_getkey_it.
#define typeadapt_getkey_EMBED(
   typeadapter_t,
   object_t
) void (* getbinarykey) (typeadapter_t * typeadp, object_t * node, /*out*/typeadapt_binarykey_t * binkey)
Declares a derived interface from generic typeadapt_getkey_it.
#define genericcast_typeadaptbinarykey(
   conststr
) ( __extension__ ({ typeof(conststr) _conststr = (conststr) ; static_assert( offsetof(typeadapt_binarykey_t, addr) == offsetof(typeof(*(conststr)), addr) && offsetof(typeadapt_binarykey_t, size) == offsetof(typeof(*(conststr)), size), "ensure same structure") ; if (0) { int _err = 0 ; const uint8_t * _addr = _conststr->addr ; size_t _size = _conststr->size ; _err = (int) (_addr[0] + _size) ; (void) _err ; } (typeadapt_binarykey_t*) _conststr ; }))
Implements typeadapt_binarykey_t.genericcast_typeadaptbinarykey.
#define genericcast_typeadaptgetkey(
   adpgetkey,
   typeadapter_t,
   object_t
) ( __extension__ ({ static_assert( offsetof(typeadapt_getkey_it, getbinarykey) == offsetof(typeof(*(adpgetkey)), getbinarykey), "ensure same structure") ; if (0) { (adpgetkey)->getbinarykey( (typeadapter_t*)0, (object_t*)0, (typeadapt_binarykey_t*)0) ; } (typeadapt_getkey_it*) (adpgetkey) ; }))
Implements typeadapt_getkey_it.genericcast_typeadaptgetkey.
Close