Libmacro  0.2
Libmacro is an extensible macro and hotkey library.
interface.h File Reference

mcr_Interface More...

Go to the source code of this file.

Classes

struct  mcr_Interface
 

Functions

MCR_API void mcr_Interface_init (struct mcr_Interface *interfacePt)
 
MCR_API void mcr_Interface_ctor (struct mcr_Interface *interfacePt, struct mcr_context *context, size_t dataSize, void *(*allocate)(), void(*deallocate)(void *), mcr_data_fnc init, mcr_data_fnc deinit, mcr_compare_fnc compare, mcr_copy_fnc copy)
 
MCR_API void mcr_Interface_deinit (struct mcr_Interface *interfacePt)
 
MCR_API void mcr_Interface_set_all (struct mcr_Interface *interfacePt, struct mcr_context *context, size_t dataSize, void *(*allocate)(), void(*deallocate)(void *), mcr_data_fnc init, mcr_data_fnc deinit, mcr_compare_fnc compare, mcr_copy_fnc copy)
 
MCR_API size_t mcr_Interface_id (struct mcr_Interface *interfacePt)
 
MCR_API int mcr_Interface_allocate (const struct mcr_Interface *interfacePt, struct mcr_DataMember *dataMemberPt)
 
MCR_API int mcr_Interface_deallocate (const struct mcr_Interface *interfacePt, struct mcr_DataMember *dataMemberPt)
 
MCR_API int mcr_Interface_compare (const struct mcr_Interface *interfacePt, const struct mcr_DataMember *lhs, const struct mcr_DataMember *rhs)
 
MCR_API int mcr_Interface_copy (const struct mcr_Interface *interfacePt, struct mcr_DataMember *dstPt, const struct mcr_DataMember *srcPt)
 
MCR_API int mcr_Interface_set_data (const struct mcr_Interface *interfacePt, struct mcr_DataMember *dataMemberPt, void *data, bool heapFlag)
 
MCR_API int mcr_Interface_reset (const struct mcr_Interface *interfacePt, struct mcr_DataMember *dataMemberPt)
 

Detailed Description

mcr_Interface

Definition in file interface.h.

Function Documentation

§ mcr_Interface_allocate()

MCR_API int mcr_Interface_allocate ( const struct mcr_Interface interfacePt,
struct mcr_DataMember dataMemberPt 
)

Heap-allocate and initialize an object

1) Use malloc to allocate object
2) Initialize object with mcr_Interface::init
3) Set mcr_DataMember::deallocate to free

Parameters
interfacePtopt The initialized object will be empty without this
dataMemberPtopt Object to initialize
Returns
reterr

§ mcr_Interface_compare()

MCR_API int mcr_Interface_compare ( const struct mcr_Interface interfacePt,
const struct mcr_DataMember lhs,
const struct mcr_DataMember rhs 
)

Use an interface to compare two objects

mcr_compare_fnc

Parameters
interfacePt
lhsopt Left side of comparison
rhsopt Right side of comparison
Returns
retcmp

§ mcr_Interface_copy()

MCR_API int mcr_Interface_copy ( const struct mcr_Interface interfacePt,
struct mcr_DataMember dstPt,
const struct mcr_DataMember srcPt 
)

Use an interface to copy an object

mcr_copy_fnc If no source is given, destination will be freed.

Parameters
interfacePt
dstPtObject data is copied into
srcPtopt Object data is copied from
Returns
reterr

§ mcr_Interface_ctor()

MCR_API void mcr_Interface_ctor ( struct mcr_Interface interfacePt,
struct mcr_context context,
size_t  dataSize,
void *(*)()  allocate,
void(*)(void *)  deallocate,
mcr_data_fnc  init,
mcr_data_fnc  deinit,
mcr_compare_fnc  compare,
mcr_copy_fnc  copy 
)

§ mcr_Interface_deallocate()

MCR_API int mcr_Interface_deallocate ( const struct mcr_Interface interfacePt,
struct mcr_DataMember dataMemberPt 
)

Release object resources and deallocate if needed.

1) Release resources with mcr_Interface::deinit
2) Use mcr_DataMember::deallocate if it is set
3) Nullify mcr_DataMember object

Parameters
interfacePtopt
dataMemberPtopt Object to deallocate or free
Returns
reterr

§ mcr_Interface_deinit()

MCR_API void mcr_Interface_deinit ( struct mcr_Interface interfacePt)

dtor

Removes self from registry, if the registry is set.

Parameters
interfacePtopt

§ mcr_Interface_id()

MCR_API size_t mcr_Interface_id ( struct mcr_Interface interfacePt)

Get the id of an interface.

Parameters
interfacePtopt
Returns
retid

§ mcr_Interface_init()

MCR_API void mcr_Interface_init ( struct mcr_Interface interfacePt)

ctor

Parameters
interfacePtopt

§ mcr_Interface_reset()

MCR_API int mcr_Interface_reset ( const struct mcr_Interface interfacePt,
struct mcr_DataMember dataMemberPt 
)

Deinit and reinitialize data.

Precondition
If mcr_Interface::init and mcr_Interface::deinit are not defined then nothing will be done. Zeroing object would be unsafe here.
Parameters
interfacePt
dataMemberPtopt Data to reset. Do nothing if this is null
Returns
reterr

§ mcr_Interface_set_all()

MCR_API void mcr_Interface_set_all ( struct mcr_Interface interfacePt,
struct mcr_context context,
size_t  dataSize,
void *(*)()  allocate,
void(*)(void *)  deallocate,
mcr_data_fnc  init,
mcr_data_fnc  deinit,
mcr_compare_fnc  compare,
mcr_copy_fnc  copy 
)

§ mcr_Interface_set_data()

MCR_API int mcr_Interface_set_data ( const struct mcr_Interface interfacePt,
struct mcr_DataMember dataMemberPt,
void *  data,
bool  heapFlag 
)

Replace object reference using an interface

Existing data will be freed. The assigned data will be copied directly and without modification.

Parameters
interfacePt
dataMemberPtopt Object to assign to
dataopt mcr_DataMember::data
heapFlagIf true, the data member will remember to deallocate from heap. mcr_Interface::deallocate
Returns
reterr