- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# /home/coin/SVN-release/Osi-0.98.1/DyLP/src/DylpStdLib/dylib_std.h

Go to the documentation of this file.

    00001 #ifndef _DYLIB_STD_H
    00002 #define _DYLIB_STD_H
    00003
    00004 /*
    00005   This file is part of the support library for the Dylp LP distribution.
    00006
    00007         Copyright (C) 2005 -- 2007 Lou Hafer
    00008
    00009         School of Computing Science
    00010         Simon Fraser University
    00011         Burnaby, B.C., V5A 1S6, Canada
    00012         lou@cs.sfu.ca
    00013
    00014   This code is licensed under the terms of the Common Public License (CPL).
    00015 */
    00016
    00017 /*
    00018   @(#)dylib_std.h       1.5     09/25/04
    00019   svn/cvs: $Id: dylib_std.h 148 2007-06-09 03:15:30Z lou $
    00020 */
    00021
    00022 /*
    00023   This file contains common definitions.
    00024
    00025   First thing to do is haul in the Ansi C standard definitions. Takes care of
    00026   NULL plus a few more obscure definitions. Also haul in the standard library
    00027   declarations.
    00028 */
    00029
    00030 #include <stddef.h>
    00031 #include <stdlib.h>
    00032
    00033 #include "DylpConfig.h"
    00034
    00035 /*
    00036   A utility definition which allows for easy suppression of unused variable
    00037   warnings from GCC. Useful when a variable is used only for assert()
    00038   statements, and for sccsid/cvsid strings.
    00039 */
    00040 #ifndef UNUSED
    00041 # if defined(_GNU_SOURCE) || defined(__GNUC__)
    00042 #   define UNUSED __attribute__((unused))
    00043 # else
    00044 #   define UNUSED
    00045 # endif
    00046 #endif
    00047
    00048 /*
    00049   Memory copy functions --- memcpy, memset, and other less common ones.
    00050 */
    00051
    00052 #include <string.h>
    00053
    00054 /*
    00055   We need a boolean type. Never could understand why C doesn't have this.
    00056
    00057   [Aug 10, 01] For compatibility with C++, TRUE and FALSE are defined to be
    00058   the corresponding C++ values. BOOL should be set in the compiler command
    00059   line to be the storage type (char/short/int/long) that matches the size of
    00060   a C++ "bool".  All these are necessary to link with and be called by C++
    00061   code in osi-bonsai.
    00062 */
    00063
    00064 #ifndef __cplusplus
    00065 #define FALSE 0
    00066 #define TRUE 1
    00067 # ifdef BOOL
    00068   typedef BOOL bool ;
    00069 # else
    00070 /*
    00071   You're in trouble. The likely source of the problem is that this file is
    00072   being included in the course of a build controlled by a makefile that
    00073   doesn't know about the booltype utility in the dylp distribution. See the
    00074   Utils subdirectory, and also check the makefile for dylp to see how this is
    00075   used.  If you don't want to fiddle with your build control files, just
    00076   build booltype, run it, and edit in the appropriate definition. If you're
    00077   not worried about C++ compatibility, int is a good as anything.
    00078 */
    00079 # warning The compile-time symbol BOOL is not defined (dylib_std.h)
    00080   typedef int bool ;
    00081 # endif
    00082 #endif
    00083
    00084 #ifdef __cplusplus
    00085 #ifndef FALSE
    00086 # define FALSE false
    00087 #endif
    00088 #ifndef TRUE
    00089 # define TRUE true
    00090 #endif
    00091 #endif
    00092
    00093 /*
    00094   flags is used to indicate a data type composed of one-bit flags. Manipulated
    00095   with the set of flag manipulation macros defined below.
    00096 */
    00097
    00098 typedef unsigned int flags ;
    00099
    00100 #define setflg(zz_flgs,zz_flg) ((zz_flgs) |= (zz_flg))
    00101 #define clrflg(zz_flgs,zz_flg) ((zz_flgs) &= ~(zz_flg))
    00102 #define comflg(zz_flgs,zz_flg) ((zz_flgs) ^= (zz_flg))
    00103 #define getflg(zz_flgs,zz_flg) ((zz_flgs)&(zz_flg))
    00104 #define flgon(zz_flgs,zz_flg)  ((zz_flgs)&(zz_flg)?TRUE:FALSE)
    00105 #define flgoff(zz_flgs,zz_flg) ((zz_flgs)&(zz_flg)?FALSE:TRUE)
    00106 #define flgall(zz_flgs,zz_flg) ((((zz_flgs)&(zz_flg)) == (zz_flg))?TRUE:FALSE)
    00107
    00108
    00109 /*
    00110   lnk_struct is a general-purpose linked list structure.
    00111
    00112   Field         Description
    00113   -----         -----------
    00114   llnxt         pointer to the next list element
    00115   llval         pointer to the associated value
    00116 */
    00117
    00118 typedef struct lnk_struct_tag
    00119 { struct lnk_struct_tag *llnxt ;
    00120   void *llval ; } lnk_struct ;
    00121
    00122 #define lnk_in(qqlnk,qqval) ((qqlnk)->llval = (void *) (qqval))
    00123 #define lnk_out(qqlnk,qqtype) ((qqtype) (qqlnk)->llval)
    00124
    00125
    00126 /* Max and min macros */
    00127
    00128 #define minn(qa,qb) (((qa) > (qb))?(qb):(qa))
    00129 #define maxx(qa,qb) (((qa) > (qb))?(qa):(qb))
    00130
    00131
    00132 /*
    00133   Some macros to hide the memory allocation functions.
    00134
    00135   The serious debugging versions of these macros (MALLOC_DEBUG = 2) use
    00136   outfmt from the io library and assume the existence of a string, rtnnme
    00137   (typically the name of the current subroutine) that's used to identify the
    00138   origin of the message. There's enough information in the messages to track
    00139   the allocation and deallocation of blocks, should you not have access to an
    00140   interactive debugger with this capability.
    00141
    00142   The casual debugging versions (MALLOC_DEBUG = 1) only check for a return
    00143   value of 0 and print a message to stderr with the file and line number.
    00144   This at least tells you when your code has core dumped because it ran out
    00145   of space (as opposed to a bug you can actually fix).
    00146 */
    00147
    00148 #if (MALLOC_DEBUG == 2)
    00149
    00150 #include "dylib_io.h"
    00151
    00152 void *zz_ptr_zz ;
    00153 ioid  zz_chn_zz ;
    00154
    00155 #define MALLOC_DBG_INIT(chn) ( zz_chn_zz = chn )
    00156
    00157 #define MALLOC(zz_sze_zz) \
    00158   ( zz_ptr_zz = (void *) malloc(zz_sze_zz), \
    00159     outfmt(zz_chn_zz,FALSE,":malloc: %d bytes at %#08x in %s.\n", \
    00160             zz_sze_zz,zz_ptr_zz,rtnnme), \
    00161     zz_ptr_zz )
    00162
    00163 #define CALLOC(zz_cnt_zz,zz_sze_zz) \
    00164   ( zz_ptr_zz = (void *) calloc(zz_cnt_zz,zz_sze_zz), \
    00165     outfmt(zz_chn_zz,FALSE,":calloc: %d (%d*%d) bytes at %#08x in %s.\n", \
    00166             zz_cnt_zz*zz_sze_zz,zz_cnt_zz,zz_sze_zz,zz_ptr_zz,rtnnme), \
    00167     zz_ptr_zz )
    00168
    00169 #define REALLOC(zz_rptr_zz,zz_sze_zz) \
    00170   ( zz_ptr_zz = (void *) realloc(zz_rptr_zz,zz_sze_zz), \
    00171     outfmt(zz_chn_zz,FALSE, \
    00172            ":realloc: %#08x changed to %d bytes at %#08x in %s.\n", \
    00173             zz_rptr_zz,zz_sze_zz,zz_ptr_zz,rtnnme), \
    00174     zz_ptr_zz )
    00175
    00176 #define FREE(zz_fptr_zz) \
    00177   ( outfmt(zz_chn_zz,FALSE,":free: %#08x in %s.\n",zz_fptr_zz,rtnnme), \
    00178     free((void *) zz_fptr_zz) )
    00179
    00180 #elif (MALLOC_DEBUG == 1)
    00181
    00182 #include <stdio.h>
    00183 void *zz_ptr_zz ;
    00184
    00185 #define MALLOC(zz_sze_zz) \
    00186   ( zz_ptr_zz = (void *) malloc(zz_sze_zz), \
    00187     (zz_ptr_zz != 0)?0:\
    00188       fprintf(stderr,":malloc: failed to get %d bytes at %s:%d.\n", \
    00189               zz_sze_zz,__FILE__,__LINE__), \
    00190     zz_ptr_zz )
    00191
    00192 #define CALLOC(zz_cnt_zz,zz_sze_zz) \
    00193   ( zz_ptr_zz = (void *) calloc(zz_cnt_zz,zz_sze_zz), \
    00194     (zz_ptr_zz != 0)?0:\
    00195       fprintf(stderr,":calloc: failed to get %d bytes at %s:%d.\n", \
    00196               zz_sze_zz*zz_cnt_zz,__FILE__,__LINE__), \
    00197     zz_ptr_zz )
    00198
    00199 #define REALLOC(zz_rptr_zz,zz_sze_zz) \
    00200   ( zz_ptr_zz = (void *) realloc(zz_rptr_zz,zz_sze_zz), \
    00201     (zz_ptr_zz != 0)?0:\
    00202       fprintf(stderr,":realloc: failed to get %d bytes at %s:%d.\n", \
    00203               zz_sze_zz,__FILE__,__LINE__), \
    00204     zz_ptr_zz )
    00205
    00206 #define FREE(zz_fptr_zz) free((void *) zz_fptr_zz)
    00207
    00208 #else
    00209
    00210 #define MALLOC_DBG_INIT(chn)
    00211
    00212 #define MALLOC(zz_sze_zz) malloc(zz_sze_zz)
    00213
    00214 #define CALLOC(zz_cnt_zz,zz_sze_zz) calloc(zz_cnt_zz,zz_sze_zz)
    00215
    00216 #define REALLOC(zz_rptr_zz,zz_sze_zz) realloc(zz_rptr_zz,zz_sze_zz)
    00217
    00218 #define FREE(zz_fptr_zz) free((void *) zz_fptr_zz)
    00219
    00220 #endif
    00221
    00222
    00223 #endif /* _DYLIB_STD_H */