MLib Alpha 1 API Reference

MLib Alpha 1 API Reference

Basic Types

This section contains the definitions of basic data types defined by the MLib


M_Byte


  typedef unsigned char   M_Byte;

an unsigned byte. Equivalent to unsigned char though a bit more convenient to use..



M_SChar


  typedef signed char     M_SChar;

a signed byte. Equivalent to signed char though a bit more convenient to use..



M_Char


  typedef char            M_Char;

a byte character. Equivalent to char but defined for completeness.



M_Short


  typedef short           M_Short;

a two-byte signed word. Equivalent to short but defined for completeness.



M_UShort


  typedef unsigned short  M_UShort;

a two-byte unsigned word. Equivalent to unsigned short though a bit more convenient to use.



M_Int


  typedef int             M_Int;

an integer. Equivalent to int but defined for completeness



M_UInt


  typedef unsigned int    M_UInt;

an unsigned word. Equivalent to unsigned int though a bit more convenient to use



M_Fast


#if M_SIZEOF_INT < 4
  typedef long            M_Fast;
#else
  typedef int             M_Fast;
#endif

a signed integer word that is at least 32-bits. This is often more convenient to use than M_Long which may be be 64-bits on some platforms (and slow)



M_UFast


#if M_SIZEOF_INT < 4
  typedef unsigned long   M_UFast;
#else
  typedef unsigned int    M_UFast;
#endif

an unsigned integer word that is at least 32-bits. This is often more convenient to use than M_ULong which may be be 64-bits on some platforms (and slow)



M_Long


  typedef long            M_Long;

a long integer. Equivalent to long but defined for completeness



M_ULong


  typedef unsigned long   M_ULong;

an unsigned long integer. Equivalent to unsigned long though a bit more convenient to use



M_Int8


  typedef M_SChar         M_Int8;

an 8-bit signed integer. Equivalent to M_SChar though defined for clarity.



M_UInt8


  typedef M_Byte          M_UInt8;

an 8-bit unsigned integer. Equivalent to M_Byte though defined for clarity.



M_Int16


  typedef short           M_Int16;

a 16-bit signed integer. Equivalent to M_Short though defined for clarity.



M_UInt16


  typedef unsigned short  M_UInt16;

a 16-bit unsigned integer. Equivalent to M_UShort though defined for clarity.



M_Int32


#if M_SIZEOF_INT == 4
  typedef int             M_Int32;
#elif M_SIZEOF_LONG == 4
  typedef long            M_Int32;
#else
# error "no 32-bits type found !!"
#endif

a 32-bit signed integer on all platforms



M_UInt32


#if M_SIZEOF_INT == 4
  typedef unsigned int    M_UInt32;
#elif M_SIZEOF_LONG == 4
  typedef unsigned long   M_UInt32;
#else
# error "no 32-bits type found !!"
#endif

a 32-bit unsigned integer on all platforms



M_Int64


#ifdef M_CONFIG_HAS_INT64
  typedef M_INT64        M_Int64;
#endif

a 64-bit signed integer. only available on certain platforms



M_UInt64


#ifdef M_CONFIG_HAS_INT64
  typedef unsigned M_INT64  M_UInt64;
#endif

a 64-bit unsigned integer. only available on certain platforms



M_Size


  typedef size_t          M_Size;

the largest unsigned integer available on the current platform.. (at least a 32-bit unsigned long)



M_Dist


  typedef ptrdiff_t       M_Dist;

the largest signed integer available on the current platform to express pointer differences.



M_String


  typedef char*           M_String;

a pointer to a character string. Equivalent to 'char *' though a bit more convenient..



M_CString


  typedef const char*     M_CString;

a pointer to a constant character string. Equivalent to 'const char *' though a bit more convenient..



M_Error


  typedef int             M_Error;

an integer error code. 0 means success, everything else indicates failure..



M_Bool


  typedef int             M_Bool;

a boolean, whose value can only be TRUE or FALSE



M_BOOL(x)


#define  M_BOOL(x)   ( (x) != 0 )

a macro used to convert a value to a boolean



M_Pointer


  typedef void*           M_Pointer;

a typeless pointer. Equivalent to void* though a bit more convenient to use



M_CPointer


  typedef const void*     M_CPointer;

a typeless constant pointer. Equivalent to const void* though a bit more convenient to use



M_NUM_ELEMENTS


#define  M_NUM_ELEMENTS(t)    (sizeof(t)/sizeof(t[0]))

a macro used to return the number of elements in a static table.



M_FIELD_OFFSET


#define  M_FIELD_OFFSET(_type,_field)    offsetof(_type,_field)

returns the offset in bytes of a given field in an object of type 'type'.



M_FIELD_SIZE


#define  M_FIELD_SIZE(_type,_field)     \
               sizeof( ((_type*)&_mlib_dummy_byte)->_field )

returns the size in bytes of a given field in an object of type '*ptype'.


note

we need to use a dummy constant variable in this macro because something like:

      sizeof( ((_type*)0)->_field )

is not portable among all compilers..


M_POINTER


#define  M_POINTER(x)    ((M_Pointer)(x))

a convenient macro used to convert anything to a pointer



M_POINTER_P


#define  M_POINTER_P(x)  ((M_Pointer*)(x))

a convenient macro used to convert anything to a pointer pointer



M_POINTER_TO_DIST


#define  M_POINTER_TO_DIST(x)    ((M_Dist)(x))

a convenient macro used to convert a pointer to a M_Dist integer (without potential bit loss)


note

you should only use this macro with pointer values created with M_POINTER_FROM_DIST . Any other use might result in unexpected results on some platforms


M_POINTER_FROM_DIST


#define  M_POINTER_FROM_DIST(x)  ((M_Pointer)(M_Dist)(x))

a convenient macro used to convert a M_Dist into a pointer.


note

only use M_POINTER_TO_DIST to retrieve the value embedded in the pointer..


M_POINTER_TO_UINT


#define  M_POINTER_TO_UINT(x)    ((M_UInt)(x))

a convenient macro used to convert a pointer to a M_UInt integer.


note

you should only use this macro with pointer values created with M_POINTER_FROM_UINT . Any other use might result in unexpected results on some platforms


M_POINTER_FROM_UINT


#define  M_POINTER_FROM_UINT(x)  ((M_Pointer)(M_UInt)(x))

a convenient macro used to convert a M_Dist into a pointer.


note

only use M_POINTER_TO_UINT to retrieve the value embedded in the pointer.


M_POINTER_TO_INT


#define  M_POINTER_TO_INT(x)    ((M_Int)(M_Pointer)(x))

a convenient macro used to convert a pointer to a M_Int integer (without potential bit loss)


note

you should only use this macro with pointer values created with M_POINTER_FROM_INT . Any other use might result in unexpected results on some platforms


M_POINTER_FROM_INT


#define  M_POINTER_FROM_INT(x)  ((M_Pointer)(M_Int)(x))

a convenient macro used to convert a M_Int into a pointer.


note

only use M_POINTER_TO_INT to retrieve the value embedded in the pointer.


M_CPOINTER


#define  M_CPOINTER(x)    ((M_CPointer)(x))

a convenient macro used to convert anything to a constant pointer



M_CPOINTER_P


#define  M_CPOINTER_P(x)  ((M_CPointer*)(x))

a convenient macro used to convert anything to a pointer to a constant pointer



M_DestroyFunc


  typedef void  (*M_DestroyFunc)( M_CPointer  item );

a type describing a function used to destroy (or unref) a single object


input
item

handle to target element


M_DestroyDataFunc


  typedef void  (*M_DestroyDataFunc)( M_CPointer  item,
                                      M_CPointer  item_data );

a variant of M_DestroyFunc used to pass item-specific data to the destructor


input
item

handle to target element

item_data

item-specific data


M_CompareFunc


  typedef M_Int  (*M_CompareFunc)( M_CPointer   a,
                                   M_CPointer   b );

a type describing a simple comparison function


input
a

first element

b

second element

return

-1, 0 or +1 if a < b, a==b or a > b, respectively


M_CompareDataFunc


  typedef M_Int  (*M_CompareDataFunc)( M_CPointer   a,
                                       M_CPointer   b,
                                       M_CPointer   data );

a type describing a comparison function using extra data


input
a

first element

b

second element

data

extra data used by the comparison

return

-1, 0 or +1 if a < b, a==b or a > b, respectively


M_HashFunc


  typedef M_Size  (*M_HashFunc)( M_CPointer   key );

type describing a simple hashing function


input
key

input key

return

key hash


M_HashDataFunc


  typedef M_Size  (*M_HashDataFunc)( M_CPointer   key,
                                     M_CPointer   user_data );

type describing a hashing function using several parameters


input
key

input key

user_data

user-provided data

return

key hash


generated on Tue Oct 09 23:59:46 2001