definitions.h

Go to the documentation of this file.
00001 #ifndef BASIS_DEFINITIONS_GROUP
00002 #define BASIS_DEFINITIONS_GROUP
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : definitions                                                       *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 1991-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00019 
00025 // include support that we always like to see.
00026 #include <ctype.h>
00027 #ifndef EMBEDDED_BUILD
00028   #include <new>
00029 #else
00030   #include <string.h>
00031 #endif
00032 
00033 #ifdef __WIN32__
00034   #ifndef CLAM_BUILT
00035     #include <__build_configuration.h>
00036   #endif
00037 #endif
00038 
00040 
00042 
00045 #ifndef HOOPLE_CODEBASE
00046   #define HOOPLE_CODEBASE
00047 #endif
00048 
00049 // postpone this until we have turned on the codebase flag.
00050 #include "outcome.h"
00051 
00053 
00055 const char *software_product_name();
00056 
00057 #ifndef NIL
00059   #define NIL 0
00060 #endif
00061 
00062 #ifndef NULL
00064   #define NULL 0
00065 #endif
00066 
00067 #ifndef BITS_PER_BYTE
00069   #define BITS_PER_BYTE 8
00070 #endif
00071 
00072 #ifndef PI_APPROX 
00074   #define PI_APPROX 3.14159265358
00075 #endif
00076 
00078 
00079 #ifndef formal
00081   #define formal(parameter)
00082 #endif
00083 
00084 #ifndef byte
00086   typedef unsigned char byte;
00087 #endif
00088 
00089 #if defined(UNICODE) && defined(__WIN32__)
00091   typedef wchar_t flexichar;
00092 #else
00093   // this version simply defangs any conversions.
00094   typedef char flexichar;
00095 #endif
00096 
00097 #ifndef u_int
00099   typedef unsigned int u_int;
00100 #endif
00101 #ifndef u_short
00103   typedef unsigned short u_short;
00104 #endif
00105 #ifndef u_long
00107   typedef unsigned long u_long;
00108 #endif
00109 
00110 // we define some maximum and minimum values that are helpful.  note that this
00111 // assumes a platform where the "int" type is 32 bits.  also note that this no
00112 // longer supports antiquated platforms like windows 3.x or pc dos.
00113 #ifndef MAXINT
00115   #define MAXINT 0x7fffffff
00116 #endif
00117 #ifndef MININT
00119   #define MININT 0x80000000
00120 #endif
00121 #ifndef MAXLONG
00123   #define MAXLONG 0x7fffffff
00124 #endif
00125 #ifndef MINLONG
00127   #define MINLONG 0x80000000
00128 #endif
00129 #ifndef MAXCHAR
00131   #define MAXCHAR 0x7f
00132 #endif
00133 #ifndef MINCHAR
00135   #define MINCHAR 0x80
00136 #endif
00137 #ifndef MAXSHORT
00139   #define MAXSHORT 0x7fff
00140 #endif
00141 #ifndef MINSHORT
00143   #define MINSHORT 0x8000
00144 #endif
00145 #ifndef MAXBYTE
00147   #define MAXBYTE 0xff
00148 #endif
00149 #ifndef MINBYTE
00151   #define MINBYTE 0x00
00152 #endif
00153 
00154 // Provide definitions for integers with platform independent specific sizes.
00155 // Note that these may have to be adjusted for 64 bit platforms.
00156 typedef char int8;
00157 typedef unsigned char uint8;
00158 typedef signed short int16;
00159 typedef unsigned short uint16;
00160 typedef signed long int32;
00161 typedef unsigned long uint32;
00162 
00164 
00165 // useful time constants.
00166 
00167 // the _ms suffix indicates that these are measured in milliseconds.
00168 const int SECOND_ms = 1000;  
00169 const int MINUTE_ms = 60 * SECOND_ms;  
00170 const int HOUR_ms = 60 * MINUTE_ms;  
00171 const int DAY_ms = 24 * HOUR_ms;  
00172 
00173 // the _s suffix indicates that these are measured in seconds.
00174 const int MINUTE_s = 60;  
00175 const int HOUR_s = 60 * MINUTE_s;  
00176 const int DAY_s = 24 * HOUR_s;  
00177 
00178 // useful general constants.
00179 
00180 const int KILOBYTE = 1024;  
00181 const int MEGABYTE = KILOBYTE * KILOBYTE;  
00182 const int GIGABYTE = MEGABYTE * KILOBYTE;  
00183 inline double TERABYTE() { return double(GIGABYTE) * double(KILOBYTE); }
00185 
00188 
00189 
00190 // these forwards are so commonly used that they have made it into being
00191 // part of the HOOPLE API.  they are all defined in basis headers.
00192 
00193 class byte_array;
00194 class byte_sequence;
00195 class chaos;
00196 class int_array;
00197 class int_set;
00198 class istring;
00199 class istring_object;
00200 class mutex;
00201 class string_array;
00202 class unichar_sequence;
00203 
00205 
00207 
00211 #define DEFINE_FILTER(NAME, CURRENT_VALUE, INFO_STRING) \
00212   NAME = CURRENT_VALUE
00213 
00215 
00217 
00223 #define DEFINE_EVENT(NAME, CURRENT_VALUE, INFO_STRING) \
00224   NAME = CURRENT_VALUE
00225 
00227 
00229 
00230 struct common {
00231 
00233 
00235   enum outcomes {
00236     DEFINE_API_OUTCOME(OKAY, 0, "Everything is just fine"),
00237     DEFINE_API_OUTCOME(NOT_IMPLEMENTED, -1, "The invoked method is "
00238         "unimplemented"),
00239     DEFINE_API_OUTCOME(OUT_OF_RANGE, -2, "The value specified was out "
00240         "of bounds"),
00241     DEFINE_API_OUTCOME(NOT_FOUND, -3, "The item sought is not present"),
00242     DEFINE_API_OUTCOME(BAD_INPUT, -4, "Precondition failure--the parameters "
00243         "were inappropriate"),
00244     DEFINE_API_OUTCOME(BAD_TYPE, -5, "The objects are of incompatible types"),
00245     DEFINE_API_OUTCOME(IS_FULL, -6, "There is no room in the storage facility"),
00246     DEFINE_API_OUTCOME(IS_EMPTY, -7, "The container is empty currently"),
00247     DEFINE_API_OUTCOME(IS_NEW, -8, "The item is new"),
00248     DEFINE_API_OUTCOME(EXISTING, -9, "The item was already present"),
00249     DEFINE_API_OUTCOME(FAILURE, -10, "A failure has occurred"),
00250     DEFINE_API_OUTCOME(OUT_OF_MEMORY, -11, "There is not enough memory for the "
00251         "request according to the operating system"),
00252     DEFINE_API_OUTCOME(ACCESS_DENIED, -12, "The request was denied, possibly "
00253         "by the operating system"),
00254     DEFINE_API_OUTCOME(IN_USE, -13, "The object is already in exclusive use"),
00255     DEFINE_API_OUTCOME(UNINITIALIZED, -14, "The object has not been "
00256         "constructed properly"),
00257     DEFINE_API_OUTCOME(TIMED_OUT, -15, "The allowed time has now elapsed"),
00258     DEFINE_API_OUTCOME(GARBAGE, -16, "The request or response has been "
00259         "corrupted"),
00260     DEFINE_API_OUTCOME(NO_SPACE, -17, "A programmatic limit on storage space "
00261         "has been reached"),
00262     DEFINE_API_OUTCOME(DISALLOWED, -18, "The method denied the request"),
00263     DEFINE_API_OUTCOME(INCOMPLETE, -19, "The operation did not finish or the "
00264         "object is not completed"),
00265     DEFINE_API_OUTCOME(NO_HANDLER, -20, "The object type passed in was not "
00266         "understood by the invoked method"),
00267     DEFINE_API_OUTCOME(NONE_READY, -21, "There were no objects available"),
00268     DEFINE_API_OUTCOME(INVALID, -22, "That request or object was invalid"),
00269     DEFINE_API_OUTCOME(PARTIAL, -23, "The request was only partially finished"),
00270     DEFINE_API_OUTCOME(NO_LICENSE, -24, "The software license does not permit"
00271         "this request"),
00272     DEFINE_API_OUTCOME(UNEXPECTED, -25, "This item was unexpected, although "
00273         "not necessarily erroneous"),
00274     DEFINE_API_OUTCOME(ENCRYPTION_MISMATCH, -26, "The request failed due to a "
00275         "mismatch between encryption expected and encryption provided")
00276   };
00277 
00278   static const char *outcome_name(const outcome &to_name);
00280 
00285   enum list_positions {
00286     HEAD = -298,   
00287     TAIL,          
00288     MIDDLE         
00289   };
00290 
00291   enum how_to_copy { NEW_AT_END, NEW_AT_BEGINNING, DONT_COPY }; 
00293 
00303 
00304   enum filters {
00305     DEFINE_FILTER(NEVER_PRINT, -1, "Indicates that the diagnostic entry "
00306         "should be dropped"),
00307     DEFINE_FILTER(ALWAYS_PRINT, 0, "Indicates that the diagnostic entry "
00308         "should always be recorded"),
00309     DEFINE_FILTER(NETWORK_LOGGING, 1, "Extra logging of network events "
00310         "will be performed"),
00311     DEFINE_FILTER(UNUSUAL_LOGGING, 2, "Logging of unusual but not "
00312         "necessarily erroneous events"),
00313 
00314     // these must be updated if the above ordering or contents change.
00315     FIRST_LOW_LEVEL_FILTER = NETWORK_LOGGING,
00316     LAST_LOW_LEVEL_FILTER = UNUSUAL_LOGGING
00317   };
00318 
00319   static int_set low_level_filters();
00321 };
00322 
00324 
00325 // this declares the program-wide argument storage area.  these hang onto argc
00326 // and argv if a program uses our macros for main.  visual c++ provides these
00327 // (unless the program is linked erroneously, mixing statically and dynamically
00328 // linked libraries), but we define them for unix & linux.  the HOOPLE_MAIN
00329 // macro (see <opsystem/application_base.h>) sets them from the initial
00330 // program arguments, although you can do that manually also.
00331 
00332 #ifdef __UNIX__
00333   extern int __argc;
00334   extern char **__argv;
00336   #define DEFINE_ARGC_AND_ARGV int __argc = 0; char **__argv = NIL
00337 #elif defined(__WIN32__)
00338   #include <stdlib.h>
00339     // the macros are defined in a fairly hard to untangle way in this header.
00340   #define DEFINE_ARGC_AND_ARGV 
00341     // the allocation of these two is already provided by ms-c.
00342 #else
00343   // guessing this will be okay for other platforms.
00344   extern int __argc;
00345   extern char **__argv;
00346   #define DEFINE_ARGC_AND_ARGV int __argc = 0; char **__argv = NIL
00347 #endif
00348 
00350 
00351 #ifdef ENABLE_MEMORY_HOOK
00352 
00353 // this section is what hooks us into the memory allocation scheme of c++.
00354 // the new macro replaces standard ::new with our version so that we can track
00355 // the file and line number along with the memory itself.
00356 
00357 #define _AFX_NO_DEBUG_CRT
00358   // turn off debugging memory hooks for win32 since ours is enabled.
00359 
00360 #ifndef __WIN32__
00362   void *operator new(size_t size, char *file, int line) throw (std::bad_alloc);
00363 
00365   inline void* operator new [] (size_t size, char *file, int line)
00366       throw (std::bad_alloc) { return ::operator new(size, file, line); }
00367 
00369   void operator delete (void *ptr) throw ();
00370 
00372   inline void operator delete [] (void *ptr) throw ()
00373   { ::operator delete(ptr); }
00374 #else
00375   // win32 has different needs.
00376   void *operator new(size_t size, char *file, int line);
00377   inline void* operator new [] (size_t size, char *file, int line)
00378       { return ::operator new(size, file, line); }
00379   void operator delete (void *ptr);
00380   inline void operator delete [] (void *ptr) { ::operator delete(ptr); }
00381   inline void operator delete (void *ptr, char *file, int line)
00382       { ::operator delete(ptr); }
00383   inline void operator delete [] (void *ptr, char *file, int line)
00384       { ::operator delete(ptr); }
00385 #endif
00386 
00388 #define HOOPLE_NEW new(__FILE__, __LINE__)
00389 
00391 #define new HOOPLE_NEW
00392 
00393 #endif // ENABLE_MEMORY_HOOK
00394 
00396 
00397 // compiler specific sections lie ahead.
00398 
00399 #if defined(__WIN32__) || defined(_MSC_VER)
00400   // general windows defs.
00401 
00402   // allows older-style borland windows flags to work with mfc.
00403   #ifndef WIN32
00404     #define WIN32
00405   #endif
00406   #ifndef __WIN32__
00407     #define __WIN32__
00408   #endif
00409   #ifndef _WIN32
00410     #define _WIN32
00411   #endif
00412   #ifndef _Windows
00413     #define _Windows
00414   #endif
00415   #ifndef _WINDOWS
00416     #define _WINDOWS
00417   #endif
00418 
00419   #ifdef _MSC_VER
00420     // support for ms visual c++ compiler.
00421 
00422     // this special block is required for debugging builds to operate correctly.
00423     #ifdef _AFXDLL
00424       #ifdef _DEBUG
00425         #ifndef ENABLE_MEMORY_HOOK
00426           // this is needed for the ms memory debugging version.
00427           #include <afx.h>
00428           #define new DEBUG_NEW
00429             // redefine the new operator for debugging.
00430         #endif
00431       #endif
00432   
00433       // NOTE: if you are having compilation problems related to a line in
00434       // a header that has "new" in it, try modifying the file where the
00435       // problem occurs by putting this before the usages of "new":
00436       //     #include <basis/trap_new.addin>
00437       // and by putting this at the end of the file:
00438       //     #include <basis/untrap_new.addin>
00439       // this will turn off the new macro for the area between the includes.
00440 
00441       // the following blocks take care of getting us hooked into the modern
00442       // form of the common controls properly.
00443       #ifdef _M_IX86
00444         #pragma comment(linker,"/manifestdependency:\"type='win32' "   \
00445           "name='Microsoft.Windows.Common-Controls' "                \
00446           "version='6.0.0.0' "                                       \
00447           "processorArchitecture='x86' "                             \
00448           "publicKeyToken='6595b64144ccf1df' "                       \
00449           "language='*'\"")
00450       #endif
00451 
00452       #ifdef _M_AMD64
00453          #pragma comment(linker,"/manifestdependency:\"type='win32' "   \
00454           "name='Microsoft.Windows.Common-Controls' "                \
00455           "version='6.0.0.0' "                                       \
00456           "processorArchitecture='amd64' "                           \
00457           "publicKeyToken='6595b64144ccf1df' "                       \
00458           "language='*'\"")
00459       #endif
00460 
00461       #ifdef _M_IA64
00462          #pragma comment(linker,"/manifestdependency:\"type='win32' "   \
00463           "name='Microsoft.Windows.Common-Controls' "                \
00464           "version='6.0.0.0' "                                       \
00465           "processorArchitecture='ia64' "                            \
00466           "publicKeyToken='6595b64144ccf1df' "                       \
00467           "language='*'\"")
00468       #endif
00469 
00470     #endif
00471   
00472     // turns off annoying complaints from visual c++.
00473     #pragma warning(disable : 4251 4275 4003 4800 4355 4786 4290 4996 4407)
00474     #pragma warning(error : 4172)
00475       // 4251 and 4275 turn off warnings regarding statically linked code
00476       //    not being marked with dll import/export flags.
00477       // 4003 turns off warnings about insufficient number of parameters passed
00478       //    to a macro.
00479       // 4800 turns off the warning about conversion from int to bool not being
00480       //    efficient.
00481       // 4355 turns off the warning re 'this' used in base member init list.
00482       // 4786 turns off the warning about 'identifier' was truncated to 'number' 
00483       //    characters in the debug information which frequenly happens when 
00484       //    STL pair and set templates are expanded.
00485       // 4172 is made an error because this warning is emitted for a dangerous
00486       //    condition; the address of a local variable is being returned, making
00487       //    the returned object junk in almost all cases.
00488 
00489   #endif  // visual c++.
00490   
00491 #elif defined(__UNIX__)
00492   #define LOBYTE(to_chop) (byte(to_chop))
00494   #define HIBYTE(to_chop) (byte(0xff & (u_short(to_chop) >> 8)))
00496 #else
00497   // otherwise we know nothing about the compiler environment.
00498   // we'll go ahead and define a bool type in case the compiler hasn't.
00499   typedef int bool;  // simple bool type for compilers without it.
00500   enum _boolean_enumeration_ { false, true };
00501 #endif
00502 
00503 #endif // outer guard.
00504 

Generated on Fri Oct 10 04:28:41 2008 for HOOPLE Libraries by  doxygen 1.5.1