Main Page   Class Hierarchy   Compound List   File List   Compound Members  

Utils.hpp

00001 /*
00002  *  This program is free software; you can redistribute it and/or modify
00003  *  it under the terms of the GNU General Public License as published by
00004  *  the Free Software Foundation; either version 2 of the License, or
00005  *  (at your option) any later version.
00006  *
00007  *  This program is distributed in the hope that it will be useful,
00008  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00009  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010  *  GNU General Public License for more details.
00011  *
00012  *  You should have received a copy of the GNU General Public License
00013  *  along with this program; if not, write to the Free Software
00014  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00015  *
00016  * (c)Copyright 2006 Hewlett-Packard Development Company, LP.
00017  *
00018  */
00019 
00020 #ifndef _UTILS_H_
00021 #define _UTILS_H_
00022 
00023 //-----------------------------------------------------------------------------
00024 // Include definitions
00025 //-----------------------------------------------------------------------------
00026 
00027 // System Include
00028 
00029 // New STL definition
00030 #include <cstdio>
00031 #include <cstdlib>
00032 
00033 #include "iostream_t.hpp"
00034 
00035 
00036 // Types definitions
00037 
00038 //-----------------------------------------------------------------------------
00039 // Constante and Macro definitions
00040 // -----------------------------------------------------------------------------
00041 
00042 typedef enum _enum_cons_result {
00043   E_CONSTRUCTOR_OK,
00044   E_CONSTRUCTOR_KO
00045 } T_ConstructorResult, *T_pContructorResult ;
00046 
00047 
00048 // boolean general definition
00049 #ifdef LOCAL_BOOLEAN
00050 #ifndef boolean
00051 typedef unsigned char boolean ;
00052 #endif /* boolean */
00053 #ifndef true
00054 #define true  (boolean) ((0) == (0))
00055 #endif /* true */
00056 #ifndef false
00057 #define false (boolean) ((0) == (1))
00058 #endif /* false */
00059 #endif /* LOCAL_BOOLEAN */
00060 
00061 //
00062 // Memory allocation general macros
00063 
00064 // Allocate a simple variable with malloc
00065 #define ALLOC_VAR(v,t,s)\
00066         (v) = (t) malloc (s); \
00067         if ((v) == NULL) { \
00068            fprintf(stderr, "ALLOC_VAR (" #v ", " #t ", size: %lu) failure\n", (unsigned long)(s));\
00069            exit(-1) ;\
00070         }
00071 
00072 #define REALLOC_VAR(v,t,s)\
00073         (v) = (t) realloc ((void*)(v),s); \
00074         if ((v) == NULL) { \
00075            fprintf(stderr, "REALLOC_VAR (" #v ", " #t ", size: %lu) failure\n", (unsigned long)(s));\
00076            exit(-1) ;\
00077         }
00078 
00079 // Allocate an array variable with malloc
00080 #define ALLOC_TABLE(v,t,s,nb)\
00081         (v) = (t) malloc ((s) * (nb)); \
00082         if ((v) == NULL) { \
00083            fprintf(stderr, "ALLOC_TABLE (" #v ", " #t ", size: %lu, nb: %lu) failure\n", (unsigned long)(s), (unsigned long)(nb));\
00084            exit(-1) ;\
00085         }
00086 
00087 // Allocate a simple variable with new
00088 #define NEW_VAR(v,t)\
00089         (v) = new t ;\
00090         if ((v) == NULL) {\
00091           iostream_error << "NEW_VAR (" #v ", " #t ") failure" << iostream_endl ;\
00092           exit(-1);\
00093         } 
00094 
00095 // Allocate an array variable with new
00096 #define NEW_TABLE(v,t,s)\
00097         (v) = new t [(s)] ;\
00098         if ((v) == NULL) {\
00099           iostream_error << "NEW_TABLE (" #v ", " #t ", nb: " << (s) << ") failure" << iostream_endl ;\
00100           exit(-1);\
00101         } 
00102 
00103 //
00104 // Memory release general macros
00105 
00106 // Free a simple variable
00107 #define FREE_VAR(p)\
00108         if ((p) != NULL) {\
00109            free (p) ; \
00110            (p) = NULL ; \
00111         }
00112 
00113 // Free an array variable
00114 #define FREE_TABLE(p)\
00115         if ((p) != NULL) {\
00116            free (p) ; \
00117            (p) = NULL ; \
00118         }
00119 
00120 // Delete a simple variable
00121 #define DELETE_VAR(p)\
00122         if ((p) != NULL) {\
00123            delete p ;\
00124            (p) = NULL ;\
00125         }
00126 
00127 // Delete an array variable
00128 #define DELETE_TABLE(p)\
00129         if ((p) != NULL) {\
00130            delete [] p ;\
00131            (p) = NULL ;\
00132         }
00133 
00134 #endif /* _UTILS_H_ */
00135 
00136 // End of file

Generated on Wed Mar 7 14:44:59 2007 for Seagull by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002