General Macros


Detailed Description

global macros and types for EGlib

Version:
0.9.2
History:


Files

file  eg_macros.h

Code Location Utility:

this are utility macros to print information about where we are.
Note:
For some reason __func__ don't work correctly for sun's cc in inline functions, so we don't use in SUN architecture


#define __EG_PRINTLOC2__   __EG_PRINTLOC2F__(stderr)
#define __EG_PRINTLOC2F__(F)   fprintf(((F==0)?stderr:F),"in %s (%s:%d)\n",__func__,__FILE__,__LINE__)
#define __EG_PRINTLOC__   __EG_PRINTLOCF__(stderr)
#define __EG_PRINTLOCF__(F)   fprintf(((F==0)?stderr:F),", in %s (%s:%d)\n",__func__,__FILE__,__LINE__)

Number Types Definitions:

Define (as its name suggest) an internal identifier for the given type. this definitions are provided to select different types of data at compile time, thus allowing us to provide limited template support.

#define DBL_TYPE   0
#define FLOAT128_TYPE   13
#define FLT_TYPE   1
#define FP10_TYPE   3
#define FP20_TYPE   4
#define FP25_TYPE   6
#define FP28_TYPE   5
#define GNU_MP_F   10
#define GNU_MP_Q   9
#define GNU_MP_Z   8
#define INT_TYPE   2
#define LDBL_TYPE   11
#define LLINT_TYPE   12

Algorithms Return Status

Here we define some general status for algorithms, the exact meaning should be sought in the actual algorithm definition, but the definitions here provide a first overview of their meaning.

#define EG_ALGSTAT_ERROR   3
 the algorithm stop because of some unforeseen error
#define EG_ALGSTAT_NUMERROR   2
 the algorithm stop because of some numerical problem
#define EG_ALGSTAT_PARTIAL   1
 the algorithm could only partially finish
#define EG_ALGSTAT_SUCCESS   0
 the algorithm finish successfully.

External C-library functions:

Here we define some C-library functions that for some weird reason can't be found at compile time but are present at linking time

double drand48 (void)
int finite (double)
int getopt (int, char *const *, const char *)
long lrand48 (void)
long random (void)
void srandom (unsigned int)
char * optarg

Defines

#define ADVCHECKRVAL(A, B)
 this macro test if a value is non zero, if it is it print where is it and return B. The idea is to use it to check return values of functions
#define ADVTESTL(level, cond, rval,)
 This macro test a condition 'cond' when the debug level used at compile time is at least 'level'. If the condition is true, it print the message and return the 'rval' value.
#define CHECKRVAL(A)
 this macro test if a value is non zero, if it is it print where is it and return 1. The idea is to use it to check return values of functions
#define CHECKRVALG(A, B)
 this function, if the input is non zero, print a message of function, file and line and then goto the second parameter
#define EGcontainerOf(ptr, type, member)
 given a pointer to a member of a structure, return the pointer to the head of the structure. (idea taken from Linux Kernel).
#define EGoffsetOf(type, member)   ((size_t) &((type *)0)->member)
 return the offset of a member inside a structure.
#define EGosGetData(data, osN, type)   (*((type*)(((char*)data)+osN)))
 retrieve the data of type 'type' in the structure 'data' that is located in the offset 'osN'.
#define EGosGetOffset(my_struct, my_member)   EGoffsetOf(my_struct,my_member)
 This is a redifinition of an old function to the newer implementation provided by EGoffsetOf. It return the offset of a member inside a structure.
#define EGosSetData(data, osN, type, val)   (EGosGetData(data,osN,type)=val)
 set the data of type 'type' in the structure 'data' that is located in the offset 'osN' to the value 'val'.
#define EGRAND_MAX   RAND_MAX
 Define the real rand_max value of (random). In linux machines is as RAND_MAX, but in SUN is 2^31-1.
#define EXIT(A,)
 This macro is to print error messages and exit the program with code one from the current function, it also print the file and line where this happend.
#define EXITL(L, A,)
 This macro is to print error messages and to return with value one from the current function, it also print the file and line where this happend, but the condition is looked only if the debug level is at least L.
#define EXITRVAL(A)
 this macro test if a value is non zero, if it is it print where is it and exit 1. The idea is to use it to check return values of functions, and the calling function can't return a status, and then we are forced to exit.
#define HAVE_GNU_MP   1
#define MESSAGE(A,)
 This macro print messages to the screen when the debug level is as big as the first parameter, if the debug level is zero we eliminate the code and reduce it to the empty instruction.
#define MESSAGEF(A, F,)
 This macro print messages to the screen when the debug level is as big as the first parameter, if the debug level is zero we eliminate the code and reduce it to the empty instruction.
#define nullCopy   ((EGcopy_f)0)
 Define a null copy function.
#define OUTPUT(A,)
 This macro print messages to the screen when the verbose level is as big as the first parameter, if the verbose level is zero we eliminate the code and reduce it to the empty instruction.
#define PTRTEST(ptr, rval)
 this macro check if the value of a pointer is not bellow the first 64Kb, if so it return the given value
#define TEST(A,)
 This macro is to print error messages and to return with value one from the current function, it also print the file and line where this happend.
#define TESTG(A, B,)
 This macro is to print error messages and to return with value one from the current function, it also print the file and line where this happend.
#define TESTL(L, A,)
 This macro is to print error messages and to return with value one from the current function, it also print the file and line where this happend, but the condition is looked only if the debug level is at least L.
#define typeof   __typeof__
 We define the GNU C extension typeof if necesary.
#define WARNING(A,)
 This macro print messages to the screen when the condition A is true.
#define WARNINGL(L, A,)
 This macro print messages to the screen when the condition A is true .if the debug level is one we don't print any warning message. if the debug level is zero we eliminate the code and reduce it to the empty instruction.

Typedefs

typedef void *(* EGcopy_f )(void *p)
 Defione copy functions, these functions return copy of objects but with independent storage space, there are two versions, one that require a memory pool from where to look for memory, and another where we don't care about that.... the place from where the memory was asked for depend on the function, se the function definition for details. Note that if the is no more memory available the function should call exit(1). This is only intended as a readibility help.


Define Documentation

#define __EG_PRINTLOC2__   __EG_PRINTLOC2F__(stderr)
 

Definition at line 148 of file eg_macros.h.

#define __EG_PRINTLOC2F__  )     fprintf(((F==0)?stderr:F),"in %s (%s:%d)\n",__func__,__FILE__,__LINE__)
 

Definition at line 147 of file eg_macros.h.

#define __EG_PRINTLOC__   __EG_PRINTLOCF__(stderr)
 

Definition at line 146 of file eg_macros.h.

#define __EG_PRINTLOCF__  )     fprintf(((F==0)?stderr:F),", in %s (%s:%d)\n",__func__,__FILE__,__LINE__)
 

Definition at line 145 of file eg_macros.h.

#define ADVCHECKRVAL A,
 ) 
 

Value:

({\
  if(A){\
    __EG_PRINTLOC2__;\
    return B;}})
this macro test if a value is non zero, if it is it print where is it and return B. The idea is to use it to check return values of functions

Definition at line 287 of file eg_macros.h.

#define ADVTESTL level,
cond,
rval   ) 
 

Value:

({\
  if((DEBUG>=level)&&(cond)){\
    fprintf(stderr,__VA_ARGS__);\
    __EG_PRINTLOC__;\
    return rval;}})
This macro test a condition 'cond' when the debug level used at compile time is at least 'level'. If the condition is true, it print the message and return the 'rval' value.

Definition at line 296 of file eg_macros.h.

#define CHECKRVAL  ) 
 

Value:

({\
  if(A){\
    __EG_PRINTLOC2__;\
    return A;}})
this macro test if a value is non zero, if it is it print where is it and return 1. The idea is to use it to check return values of functions

Examples:
eg_net.ex.c.

Definition at line 306 of file eg_macros.h.

#define CHECKRVALG A,
 ) 
 

Value:

({\
  if(A){\
    __EG_PRINTLOC2__;\
    goto B;}})
this function, if the input is non zero, print a message of function, file and line and then goto the second parameter

Examples:
eg_dmatrix.ex.c, eg_ebtree.ex.c, eg_eheap.ex.c, eg_min_cut.ex.c, and eg_push_relabel.ex.c.

Definition at line 314 of file eg_macros.h.

#define DBL_TYPE   0
 

C double type.

Definition at line 355 of file eg_macros.h.

#define EG_ALGSTAT_ERROR   3
 

the algorithm stop because of some unforeseen error

Definition at line 418 of file eg_macros.h.

#define EG_ALGSTAT_NUMERROR   2
 

the algorithm stop because of some numerical problem

Definition at line 416 of file eg_macros.h.

#define EG_ALGSTAT_PARTIAL   1
 

the algorithm could only partially finish

Definition at line 414 of file eg_macros.h.

#define EG_ALGSTAT_SUCCESS   0
 

the algorithm finish successfully.

Definition at line 412 of file eg_macros.h.

#define EGcontainerOf ptr,
type,
member   ) 
 

Value:

({\
  typeof(((type *)0)->member) *const __EGcOf_ptr = (ptr);\
  (type *)( (char*)__EGcOf_ptr - EGoffsetOf(type,member));})
given a pointer to a member of a structure, return the pointer to the head of the structure. (idea taken from Linux Kernel).

Parameters:
ptr pointer to the member of the containing structure.
type name type of the containing structure.
member name of the given member in the containing structure.
Returns:
pointer to the containing structure.
Examples:
eg_edgraph.ex.c, eg_elist.ex.c, eg_eugraph.ex.c, eg_push_relabel.ex.c, and eg_shrink_graph.ex.c.

Definition at line 119 of file eg_macros.h.

#define EGoffsetOf type,
member   )     ((size_t) &((type *)0)->member)
 

return the offset of a member inside a structure.

Parameters:
type the type of the containing structure.
member the name of the member that we are interested in compute the offset.
Returns:
the number of bytes between the member and the beginning of the structure.

Definition at line 109 of file eg_macros.h.

#define EGosGetData data,
osN,
type   )     (*((type*)(((char*)data)+osN)))
 

retrieve the data of type 'type' in the structure 'data' that is located in the offset 'osN'.

Definition at line 335 of file eg_macros.h.

#define EGosGetOffset my_struct,
my_member   )     EGoffsetOf(my_struct,my_member)
 

This is a redifinition of an old function to the newer implementation provided by EGoffsetOf. It return the offset of a member inside a structure.

Definition at line 346 of file eg_macros.h.

#define EGosSetData data,
osN,
type,
val   )     (EGosGetData(data,osN,type)=val)
 

set the data of type 'type' in the structure 'data' that is located in the offset 'osN' to the value 'val'.

Definition at line 340 of file eg_macros.h.

#define EGRAND_MAX   RAND_MAX
 

Define the real rand_max value of (random). In linux machines is as RAND_MAX, but in SUN is 2^31-1.

Examples:
eg_memslab.ex.c.

Definition at line 323 of file eg_macros.h.

#define EXIT  ) 
 

Value:

({if(A){\
    fprintf(stderr,__VA_ARGS__);\
    __EG_PRINTLOC__;\
    exit(1);}})
This macro is to print error messages and exit the program with code one from the current function, it also print the file and line where this happend.

Definition at line 278 of file eg_macros.h.

#define EXITL L,
 ) 
 

Value:

({\
  if(L<=DEBUG){\
  if(A){\
    fprintf(stderr,__VA_ARGS__);\
    __EG_PRINTLOC__;\
    exit(1);}}})
This macro is to print error messages and to return with value one from the current function, it also print the file and line where this happend, but the condition is looked only if the debug level is at least L.

Definition at line 157 of file eg_macros.h.

#define EXITRVAL  ) 
 

Value:

({\
  if(A){\
    __EG_PRINTLOC2__;\
    exit(1);}})
this macro test if a value is non zero, if it is it print where is it and exit 1. The idea is to use it to check return values of functions, and the calling function can't return a status, and then we are forced to exit.

Definition at line 269 of file eg_macros.h.

#define FLOAT128_TYPE   13
 

SoftFloat 128-bit floating point numbner

Definition at line 385 of file eg_macros.h.

#define FLT_TYPE   1
 

C float type.

Definition at line 357 of file eg_macros.h.

#define FP10_TYPE   3
 

EGlib EGfp10_t type, this is an implementation of fixed precision arithmetic with 10 bits for fractional representation.

Definition at line 362 of file eg_macros.h.

#define FP20_TYPE   4
 

EGlib EGfp20_t type, this is an implementation of fixed precision arithmetic with 20 bits for fractional representation.

Definition at line 365 of file eg_macros.h.

#define FP25_TYPE   6
 

EGlib EGfp25_t type, this is an implementation of fixed precision arithmetic with 25 bits for fractional representation.

Definition at line 371 of file eg_macros.h.

#define FP28_TYPE   5
 

EGlib EGfp28_t type, this is an implementation of fixed precision arithmetic with 28 bits for fractional representation.

Definition at line 368 of file eg_macros.h.

#define GNU_MP_F   10
 

GNU_MP library mpf_t type

Definition at line 378 of file eg_macros.h.

#define GNU_MP_Q   9
 

GNU_MP library mpq_t type

Definition at line 376 of file eg_macros.h.

#define GNU_MP_Z   8
 

GNU_MP library mpz_t type

Definition at line 374 of file eg_macros.h.

#define HAVE_GNU_MP   1
 

Definition at line 93 of file eg_macros.h.

#define INT_TYPE   2
 

C int type.

Definition at line 359 of file eg_macros.h.

#define LDBL_TYPE   11
 

C long double type

Definition at line 381 of file eg_macros.h.

#define LLINT_TYPE   12
 

C long long int type

Definition at line 383 of file eg_macros.h.

#define MESSAGE  ) 
 

Value:

({\
  if(A <= DEBUG ){\
    fprintf(stderr,__VA_ARGS__);\
    __EG_PRINTLOC__;}})
This macro print messages to the screen when the debug level is as big as the first parameter, if the debug level is zero we eliminate the code and reduce it to the empty instruction.

Examples:
eg_eheap.ex.c, and eg_net.ex.c.

Definition at line 217 of file eg_macros.h.

#define MESSAGEF A,
 ) 
 

Value:

({\
  if(A <= DEBUG ){\
    fprintf(((F==0)?stderr:F),__VA_ARGS__);\
    __EG_PRINTLOCF__(F);}})
This macro print messages to the screen when the debug level is as big as the first parameter, if the debug level is zero we eliminate the code and reduce it to the empty instruction.

Definition at line 208 of file eg_macros.h.

#define nullCopy   ((EGcopy_f)0)
 

Define a null copy function.

Definition at line 403 of file eg_macros.h.

#define OUTPUT  ) 
 

Value:

({\
  if(A <= VERBOSE_LEVEL ){\
    fprintf(stderr,__VA_ARGS__);}})
This macro print messages to the screen when the verbose level is as big as the first parameter, if the verbose level is zero we eliminate the code and reduce it to the empty instruction.

Definition at line 227 of file eg_macros.h.

#define PTRTEST ptr,
rval   ) 
 

Value:

{\
  if(ptr) ADVTESTL(0,((size_t)(ptr)) < (1U<<16),rval, \
                 "%s=%p is not a valid pointer",\
                  #ptr, (void*)(ptr));}
this macro check if the value of a pointer is not bellow the first 64Kb, if so it return the given value

Definition at line 179 of file eg_macros.h.

#define TEST  ) 
 

Value:

({\
  if(A){\
    fprintf(stderr,__VA_ARGS__);\
    __EG_PRINTLOC__;\
    return 1;}})
This macro is to print error messages and to return with value one from the current function, it also print the file and line where this happend.

Examples:
eg_eheap.ex.c, and eg_net.ex.c.

Definition at line 198 of file eg_macros.h.

#define TESTG A,
 ) 
 

Value:

({\
  if(A){\
    fprintf(stderr,__VA_ARGS__);\
    __EG_PRINTLOC__;\
    goto B;}})
This macro is to print error messages and to return with value one from the current function, it also print the file and line where this happend.

Examples:
eg_eheap.ex.c, eg_min_cut.ex.c, eg_push_relabel.ex.c, and eg_shrink_graph.ex.c.

Definition at line 188 of file eg_macros.h.

#define TESTL L,
 ) 
 

Value:

({\
  if(L<=DEBUG){\
  if(A){\
    fprintf(stderr,__VA_ARGS__);\
    __EG_PRINTLOC__;\
    return 1;}}})
This macro is to print error messages and to return with value one from the current function, it also print the file and line where this happend, but the condition is looked only if the debug level is at least L.

Definition at line 169 of file eg_macros.h.

#define typeof   __typeof__
 

We define the GNU C extension typeof if necesary.

Definition at line 99 of file eg_macros.h.

#define WARNING  ) 
 

Value:

({if(A){\
    fprintf(stderr,"WARNING: ");\
    fprintf(stderr,__VA_ARGS__);\
    __EG_PRINTLOC__;}})
This macro print messages to the screen when the condition A is true.

Definition at line 259 of file eg_macros.h.

#define WARNINGL L,
 ) 
 

Value:

({\
  if((A)&&(DEBUG>=L)){\
    fprintf(stderr,"WARNING: ");\
    fprintf(stderr,__VA_ARGS__);\
    __EG_PRINTLOC__;}})
This macro print messages to the screen when the condition A is true .if the debug level is one we don't print any warning message. if the debug level is zero we eliminate the code and reduce it to the empty instruction.

Definition at line 239 of file eg_macros.h.


Typedef Documentation

typedef void*(* EGcopy_f)(void *p)
 

Defione copy functions, these functions return copy of objects but with independent storage space, there are two versions, one that require a memory pool from where to look for memory, and another where we don't care about that.... the place from where the memory was asked for depend on the function, se the function definition for details. Note that if the is no more memory available the function should call exit(1). This is only intended as a readibility help.

Definition at line 398 of file eg_macros.h.


Function Documentation

double drand48 void   ) 
 

int finite double   ) 
 

int getopt int  ,
char *const *  ,
const char * 
 

Examples:
eg_dmatrix.ex.c, eg_ebtree.ex.c, eg_eheap.ex.c, eg_min_cut.ex.c, and eg_net.ex.c.

long lrand48 void   ) 
 

long random void   ) 
 

Examples:
eg_elist.ex.c, eg_memslab.ex.c, and eg_net.ex.c.

void srandom unsigned  int  ) 
 

Examples:
eg_ebtree.ex.c, and eg_memslab.ex.c.


Variable Documentation

char* optarg
 

Examples:
eg_dmatrix.ex.c, eg_ebtree.ex.c, eg_eheap.ex.c, eg_min_cut.ex.c, and eg_net.ex.c.


Generated on Mon Jan 30 08:55:34 2006 for EGlib by  doxygen 1.4.5