Typeadapt-Implementation

Implements typeadapt_t lifetime services which can be used for simple types.

Pecondition

1.Include “C-kern/api/ds/typeadapt.h”
Summary
Typeadapt-ImplementationImplements typeadapt_t lifetime services which can be used for simple types.
CopyrightThis program is free software.
Files
C-kern/api/ds/typeadapt/typeadapt_impl.hHeader file Typeadapt-Implementation.
C-kern/ds/typeadapt/typeadapt_impl.cImplementation file Typeadapt-Implementation impl.
Types
struct typeadapt_impl_tExport typeadapt_impl_t into global namespace.
Functions
test
unittest_ds_typeadapt_typeadaptimplTest typeadapt_impl_t functionality.
typeadapt_impl_tDefault implementation of typeadapt_t.
objectsizeThe size of supported structure.
lifetime
typeadapt_impl_FREEStatic initializer.
typeadapt_impl_INITStatic initializer.
init_typeadaptimplInitializes implementation to support objectes of size objectsize.
free_typeadaptimplSets all fields to 0.
lifetime-service-implementation
lifetime_newcopyobj_typeadaptimplImplements typeadapt_lifetime_it.newcopy_object.
lifetime_deleteobj_typeadaptimplImplements typeadapt_lifetime_it.delete_object.

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/typeadapt_impl.h

C-kern/ds/typeadapt/typeadapt_impl.c

Implementation file Typeadapt-Implementation impl.

Types

struct typeadapt_impl_t

typedef struct typeadapt_impl_t typeadapt_impl_t

Export typeadapt_impl_t into global namespace.

test

unittest_ds_typeadapt_typeadaptimpl

int unittest_ds_typeadapt_typeadaptimpl(void)

Test typeadapt_impl_t functionality.

typeadapt_impl_t

struct typeadapt_impl_t

Default implementation of typeadapt_t.

Assumptions

1.  This implementation assumes that objects can be copied with a simple call to memcpy and no special deep copy semantic is needed.  2. The second one is that objects always have the same size.

Both assumptions are too simple for supporting complex object types.  But for complex objects it is considered OK to implement their own typeadapt_t*.

Summary
objectsizeThe size of supported structure.
lifetime
typeadapt_impl_FREEStatic initializer.
typeadapt_impl_INITStatic initializer.
init_typeadaptimplInitializes implementation to support objectes of size objectsize.
free_typeadaptimplSets all fields to 0.
lifetime-service-implementation
lifetime_newcopyobj_typeadaptimplImplements typeadapt_lifetime_it.newcopy_object.
lifetime_deleteobj_typeadaptimplImplements typeadapt_lifetime_it.delete_object.

objectsize

size_t objectsize

The size of supported structure.

lifetime

typeadapt_impl_FREE

#define typeadapt_impl_FREE { typeadapt_FREE, 0 }

Static initializer.

typeadapt_impl_INIT

#define typeadapt_impl_INIT(
   objectsize
) { typeadapt_INIT_LIFETIME(&lifetime_newcopyobj_typeadaptimpl, &lifetime_deleteobj_typeadaptimpl), objectsize }

Static initializer.

init_typeadaptimpl

int init_typeadaptimpl(/*out*/typeadapt_impl_t *typeadp,
size_t objectsize)

Initializes implementation to support objectes of size objectsize.

free_typeadaptimpl

int free_typeadaptimpl(typeadapt_impl_t *typeadp)

Sets all fields to 0.  No additional resources are held.  Memory of objects which are not freed is kept intact.

lifetime-service-implementation

lifetime_newcopyobj_typeadaptimpl

int lifetime_newcopyobj_typeadaptimpl(
   typeadapt_impl_t *typeadp,
   /*out*/struct typeadapt_object_t **destobject,
   const struct typeadapt_object_t *srcobject
)

Implements typeadapt_lifetime_it.newcopy_object.

lifetime_deleteobj_typeadaptimpl

int lifetime_deleteobj_typeadaptimpl(typeadapt_impl_t *typeadp,
struct typeadapt_object_t **object)

Implements typeadapt_lifetime_it.delete_object.

Implements typeadapt_t lifetime services which can be used for simple types.
Implements Typeadapt-Implementation.
typedef struct typeadapt_impl_t typeadapt_impl_t
Export typeadapt_impl_t into global namespace.
struct typeadapt_impl_t
Default implementation of typeadapt_t.
int unittest_ds_typeadapt_typeadaptimpl(void)
Test typeadapt_impl_t functionality.
size_t objectsize
The size of supported structure.
#define typeadapt_impl_FREE { typeadapt_FREE, 0 }
Static initializer.
#define typeadapt_impl_INIT(
   objectsize
) { typeadapt_INIT_LIFETIME(&lifetime_newcopyobj_typeadaptimpl, &lifetime_deleteobj_typeadaptimpl), objectsize }
Static initializer.
int init_typeadaptimpl(/*out*/typeadapt_impl_t *typeadp,
size_t objectsize)
Initializes implementation to support objectes of size objectsize.
int free_typeadaptimpl(typeadapt_impl_t *typeadp)
Sets all fields to 0.
int lifetime_newcopyobj_typeadaptimpl(
   typeadapt_impl_t *typeadp,
   /*out*/struct typeadapt_object_t **destobject,
   const struct typeadapt_object_t *srcobject
)
Implements typeadapt_lifetime_it.newcopy_object.
int (
   *newcopy_object
) (struct typeadapt_t * typeadp, /*out*/struct typeadapt_object_t ** destobject, const struct typeadapt_object_t * srcobject)
Function copies an object.
int lifetime_deleteobj_typeadaptimpl(typeadapt_impl_t *typeadp,
struct typeadapt_object_t **object)
Implements typeadapt_lifetime_it.delete_object.
int (
   *delete_object
) (struct typeadapt_t * typeadp, struct typeadapt_object_t ** object)
Function frees memory and associated resources of object.
Close