![]() |
Main Page
Class Hierarchy
Alphabetical List
Compound List
File List
Compound Members
![]() |
00001 /******************************************************************************** 00002 * * 00003 * FOX extension library: Definitions, Types, and Macros * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 2003 by Mathew Robertson. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU Lesser General Public * 00010 * License as published by the Free Software Foundation; either * 00011 * version 2.1 of the License, or (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public * 00019 * License along with this library; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 00021 ********************************************************************************/ 00022 #ifndef FXEXDEFS_H 00023 #define FXEXDEFS_H 00024 00025 // loads the FOX defs 00026 #ifndef FXDEFS_H 00027 #include <fox/fxdefs.h> 00028 /** 00029 * The FOX namespace is defined with the symbol 'FX'. Refer to the FOX documentation for 00030 * more information. 00031 */ 00032 using namespace FX; 00033 #endif 00034 00035 // Disable warnings on extern before template instantiation for the Microsoft compiler. 00036 // see "HOWTO: Exporting STL Components Inside & Outside of a Class" on the microsoft website 00037 #if defined(WIN32) && defined(_MSC_VER) 00038 #pragma warning (disable : 4231) 00039 #endif 00040 00041 00042 // implement CALLBACK for unix 00043 #ifndef CALLBACK 00044 #define CALLBACK 00045 #endif 00046 00047 /** 00048 * FXEX is the namespace encapsulating the FOXEX library, in a similar vein to the FOX 00049 * namespace. This should not affect you too much, since if you dont explicately #define 00050 * FX_NO_GLOBAL_NAMESPACE, the FXEX namespace automatically imported when you #include 00051 * <fxex/fxex.h>. 00052 */ 00053 namespace FXEX { 00054 00055 // provide an extern mechanism 00056 #ifdef WIN32 00057 #ifdef FOXDLL 00058 #ifndef FOXDLL_EXPORTS 00059 #define FXEXTERN extern 00060 #endif 00061 #endif 00062 #endif 00063 00064 #ifndef FXEXTERN 00065 #define FXEXTERN 00066 #endif 00067 00068 00069 // Valid compression factors for Bzip and Gzip compression libraries 00070 #define COMPRESS_MAX 9 00071 #define COMPRESS_NORMAL 6 00072 #define COMPRESS_FAST 1 00073 #define COMPRESS_NONE 0 00074 00075 00076 // Win32 defines INFINITE to be -1, we might as well do it too. 00077 #ifndef WIN32 00078 # define INFINITE (-1) 00079 #endif 00080 00081 00082 // determine the newline charater(s) 00083 #ifdef WIN32 00084 #define FXNEWLINE "\r\n" 00085 #endif 00086 #ifdef MAC 00087 #define FXNEWLINE "\r" 00088 #endif 00089 #ifndef FXNEWLINE 00090 #define FXNEWLINE "\n" 00091 #endif 00092 00093 00094 // make a short from two chars 00095 #define MKUSHORT(l,h) ((((FX::FXuchar)(l))&0xff) | (((FX::FXuchar)(h))<<8)) 00096 00097 // Make a long from two ints - provided longs are twice the size of an int 00098 #ifdef FX_LONG 00099 # define MKULONG(l,h) ((((FX::FXuint)(l))&0xffffffff) | (((FX::FXuint)(h))<<32)) 00100 #else 00101 # if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64 00102 # error "You wanted 64bit file sizes (actually 63), but I couldn't make it so..." 00103 # endif 00104 #endif 00105 00106 00107 /** 00108 * Quite a while ago (18/08/2000), these macros (or something similar) were 00109 * posted to the FOX users list, by Dirk Zoller. I cleaned them up a little. 00110 */ 00111 #define FXDeclare(Class) \ 00112 FXDECLARE(Class) 00113 #define FXDeclareAbstract(Class) \ 00114 FXDECLARE_ABSTRACT(Class) 00115 #define FXDefMap(Class) \ 00116 FXDEFMAP(Class) Class##Map[] 00117 #define FXImplementAbstract(Class,Parent) \ 00118 FXIMPLEMENT_ABSTRACT(Class,Parent,Class##Map,ARRAYNUMBER(Class##Map)) 00119 #define FXImplement(Class,Parent) \ 00120 FXIMPLEMENT(Class,Parent,Class##Map,ARRAYNUMBER(Class##Map)) 00121 #define FXFuncDecl(Func) \ 00122 long on##Func (FXObject*,FXSelector,void*) 00123 #define FXFuncImpl(Class,Func,tgt,sel,ptr) \ 00124 long Class::on##Func (FXOject *tgt,FXSelector sel, void *ptr) 00125 #define FXMapTypes(Class,FromType,ToType,Func) \ 00126 FXMAPTYPES(SEL_##FromType,SEL_##ToType,Class::on##Func) 00127 #define FXMapType(Class,SelType,Func) \ 00128 FXMAPTYPE(SEL_##SelType,Class::on##Func) 00129 #define FXMapFuncs(Class,SelType,FromId,ToId,Func) \ 00130 FXMAPFUNCS(SEL_##SelType,Class::ID_##FromId,Class::ID_##ToId,Class::on#Func) 00131 #define FXMapFunc(Class,SelType,Id,Func) \ 00132 FXMAPFUNC(SEL_##SelType,Class::ID_##Id,Class::on##Func) 00133 00134 00135 /// Zed A Shaw posted these (09/09/02), or a variation of them 00136 #define FXSEND(tgt,sel,msg,ptr) \ 00137 (tgt->handle(this,FXSEL(sel,msg),ptr) 00138 #define FXROUTE(src,tgt,sel,msg,ptr) \ 00139 (tgt->handle(src,FXSEL(sel,msg),ptr) 00140 00141 00142 // debugging macros 00143 #ifndef NDEBUG 00144 # define FXCTOR() fxtrace (100,"%s::%s %p\n",getClassName(),getClassName(),this) 00145 # define FXMETHOD(methodname) fxtrace (100,"%s::%s %p\n",getClassName(),#methodname,this) 00146 # define FXDTOR() fxtrace (100,"%s::~%s %p\n",getClassName(),getClassName(),this) 00147 #else 00148 # define FXCTOR() 00149 # define FXMETHOD(methodname) 00150 # define FXDTOR() 00151 #endif 00152 00153 00154 // New selector types 00155 enum { 00156 SEL_DATA=FX::SEL_LAST, // form of data as an event 00157 SEL_THREAD, // thread/runnable events 00158 SEL_WAITABLE_WAIT, // waitable event such as a Condition variable, semaphore, etc 00159 SEL_WAITABLE_ACTIVATE, // waitable event such as a Condition variable, semaphore, etc 00160 SEL_INTERLOCK, // interlocked event; object went into lock 00161 SEL_BARRIER_LOCK, // barrier event; thread waiting in barrier lock 00162 SEL_BARRIER_UNLOCK, // barrier event; barrier object reset, threads released 00163 SEL_INPUT, // some type of input event 00164 SEL_OUTPUT, // some type of output event 00165 SEL_ERROR, // some type of error event 00166 SEL_IO, // Some form of IO 00167 SEL_IO_CONNECT, // Connection event 00168 SEL_EVENT, // a generic event 00169 SEL_BEGIN, // en event defining some begining 00170 SEL_END, // an event defining some ending 00171 SEL_TAG, // tag event 00172 SEL_CONTENT, // content event 00173 SEL_REGISTRY, // a registry event (TODO I have a plan for this...) 00174 SEL_LASTEX // Last message 00175 }; 00176 00177 00178 /// IO status definitions 00179 typedef FXint FXIOStatus; 00180 enum { 00181 FXIOStatusUnknown=-2, 00182 FXIOStatusError=-1, 00183 FXIOStatusOk=0, 00184 FXIOStatusOK=0, 00185 FXIOStatusLast 00186 }; 00187 #ifndef INVALID_HANDLE 00188 # ifdef WIN32 00189 # define INVALID_HANDLE INVALID_HANDLE_VALUE 00190 # else 00191 # define INVALID_HANDLE -1 00192 # endif 00193 #endif 00194 00195 #ifndef VALID_RESULT 00196 # define VALID_RESULT 0 00197 #endif 00198 00199 00200 /// IO state definitions 00201 typedef FXint FXIOState; 00202 enum { 00203 FXIOStateUnknown=-1, 00204 FXIOStateNone=-1, 00205 FXIOStateOk=0, 00206 FXIOStateOK=0, 00207 FXIOStateUnconnected, 00208 FXIOStateConnected, 00209 FXIOStateOpen=FXIOStateConnected, 00210 FXIOStateListener, 00211 FXIOStateAccepted, 00212 FXIOStateDuplicated, 00213 FXIOStateLast 00214 }; 00215 00216 00217 /** 00218 * Socket definitions, for types and families 00219 */ 00220 /// Socket types 00221 enum FXSocketType { 00222 FXSocketTypeNone=0, // unknown socket type 00223 FXSocketTypeStream, // TCP socket 00224 FXSocketTypeTCP=FXSocketTypeStream, // TCP socket 00225 FXSocketTypeDatagram, // UDP socket 00226 FXSocketTypeUDP=FXSocketTypeDatagram, // UDP socket 00227 }; 00228 00229 /// Socket families 00230 enum FXSocketFamily { 00231 FXSocketFamilyNone=0, // unknown socket family 00232 FXSocketFamilyLocal, // Local domain socket (on nearly every system, same as Unix domain) 00233 FXSocketFamilyInet, // Internet domain socket, version 4 (ie the default internet family) 00234 FXSocketFamilyInet6, // Internet domain socket, version 6 00235 FXSocketFamilyAutomatic, // automatically choose UNIX domain (local) socket, when connecting 00236 // to localhost, internet domain for internet sockets 00237 FXSocketFamilyUnix=FXSocketFamilyLocal 00238 }; 00239 00240 00241 /** 00242 * File permissions: 00243 * 00244 * Use these with fxfilemode to set platform specific mode flags. For example: 00245 * 00246 * FXFileIO fileio(getApp(),"somefile.txt"); 00247 * ... 00248 * fileio->mode(FXUtils::fxfilemode(FILEPERM_DEFAULT_IO)); 00249 * 00250 * or: 00251 * 00252 * FXFile::mode("file.txt",FXUtils::fxfilemode(FILEPERM_DEFAULT_IO)); 00253 * 00254 * or: 00255 * 00256 * FXuint mode=FXFile::mode("file.txt"); 00257 * if (mode & FILEPERM_READ) {...} 00258 * 00259 */ 00260 enum FXFilePermission { 00261 FILEPERM_NONE = 0, // file has no permissions 00262 FILEPERM_USER_READ = 0x00000001, // user can read from file 00263 FILEPERM_USER_WRITE = 0x00000002, // user can write to file 00264 FILEPERM_USER_EXEC = 0X00000004, // user can execute file 00265 FILEPERM_GROUP_READ = 0x00000010, // group can read from file 00266 FILEPERM_GROUP_WRITE = 0x00000020, // group can write to file 00267 FILEPERM_GROUP_EXEC = 0x00000040, // group can execute the file 00268 FILEPERM_OTHER_READ = 0x00000100, // everybody can read from file 00269 FILEPERM_OTHER_WRITE = 0x00000200, // everybody can write to file 00270 FILEPERM_OTHER_EXEC = 0x00000400, // everybody can execute the file 00271 FILEPERM_READ = 0x00000111, // file read mask; set all read permissions 00272 FILEPERM_WRITE = 0x00000222, // file write mask; set all write permissions 00273 FILEPERM_EXEC = 0x00000444, // file execute mask; set all execute permissions 00274 FILEPERM_ALL = 0x00000777, // permissions mask; set all permissions 00275 FILEPERM_SET_UID = 0x00001000, // set the UID permission 00276 FILEPERM_SET_GID = 0x00002000, // set the GID permisssion 00277 FILEPERM_STICKY = 0x00004000, // set the STICKY permission 00278 FILEPERM_SECURE_IO = FILEPERM_USER_READ|FILEPERM_USER_WRITE, // permissions suitable for single user IO access 00279 FILEPERM_DEFAULT_IO = FILEPERM_READ|FILEPERM_USER_WRITE|FILEPERM_GROUP_WRITE, // permissions suitable for group IO access 00280 FILEPERM_DEFAULT_EXEC = FILEPERM_READ|FILEPERM_USER_WRITE|FILEPERM_GROUP_WRITE|FILEPERM_EXEC, // permissions suitable for all users to execute a file 00281 }; 00282 00283 00284 // thread stuff 00285 #ifndef WIN32 00286 typedef void* FXThreadHandle; // handle to a thread 00287 typedef void* FXThreadMutex; // handle to a mutex 00288 typedef void* FXThreadCondition; // handle to a condition variable 00289 typedef void* FXThreadSemaphore; // handle to a semaphore 00290 typedef FXInputHandle* FXThreadEventHandle; // handle to a thread event object 00291 #else 00292 typedef HANDLE FXThreadHandle; // handle to a thread 00293 typedef HANDLE FXThreadMutex; // handle to a mutex 00294 typedef HANDLE FXThreadCondition; // handle to a condition variable 00295 typedef HANDLE FXThreadSemaphore; // handle to a semaphore 00296 typedef FXInputHandle FXThreadEventHandle; // handle to a thread event object 00297 #endif 00298 00299 00300 // dynamic library loading 00301 #ifndef WIN32 00302 typedef void* FXDLLHandle; // handle to a dynamically loaded file 00303 #else 00304 typedef HMODULE FXDLLHandle; // handle to a dynamically loaded file 00305 #endif 00306 00307 00308 // database interface handle 00309 //typedef void* FXDatabaseHandle; // handle to a database connection 00310 00311 00312 namespace FXUtils { 00313 00314 ////////////// global variables //////////////////// 00315 00316 /// Version number that the library version is compiled with 00317 extern FXAPI const FXuchar fxexversion[3]; 00318 00319 00320 ////////////// global functions //////////////////// 00321 00322 /// time conversion routines 00323 #ifdef WIN32 00324 static void get_time_now(unsigned long* abs_sec, unsigned long* abs_nsec); 00325 static DWORD get_timeout(unsigned long secs, unsigned long nsecs,DWORD default_to); 00326 #else 00327 void convert_timeval(struct timeval *tv,FXuint ms); 00328 void convert_timespec(struct timespec *ts,FXuint ms); 00329 #endif 00330 00331 }; // namespace FXUtils 00332 }; // namespace FXEX 00333 00334 #endif // FXEXDEFS_H 00335