definitions.h

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

Generated on Mon Jan 14 04:30:52 2008 for HOOPLE Libraries by  doxygen 1.5.1