src/foundation/ZTypes.h

00001 /*  @(#) $Id: ZTypes.h,v 1.19 2006/04/26 22:31:27 agreen Exp $ */
00002 
00003 /* ------------------------------------------------------------
00004 Copyright (c) 2000 Andrew Green and Learning in Motion, Inc.
00005 http://www.zoolib.org
00006 
00007 Permission is hereby granted, free of charge, to any person obtaining a copy
00008 of this software and associated documentation files (the "Software"), to deal
00009 in the Software without restriction, including without limitation the rights
00010 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00011 copies of the Software, and to permit persons to whom the Software is
00012 furnished to do so, subject to the following conditions:
00013 
00014 The above copyright notice and this permission notice shall be included in
00015 all copies or substantial portions of the Software.
00016 
00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00020 COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00021 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00022 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00023 ------------------------------------------------------------ */
00024 
00025 #ifndef __ZTypes__
00026 #define __ZTypes__
00027 
00028 #include "zconfig.h"
00029 
00030 #include <cstdio> // Pull in definition of size_t, which is heavily used by zoolib
00031 
00032 // ==================================================
00033 // The usual suite of types with known sizes and signedness.
00034 
00035 #if ZCONFIG(OS, Be)
00036 
00037 #       include<support/SupportDefs.h>
00038 
00039 #elif ZCONFIG(Compiler, MSVC)
00040 
00041         typedef signed char int8;
00042         typedef unsigned char uint8;
00043 
00044         typedef signed short int16;
00045         typedef unsigned short uint16;
00046 
00047         typedef signed int int32;
00048         typedef unsigned int uint32;
00049 
00050         typedef __int64 int64;
00051         typedef unsigned __int64 uint64;
00052 
00053         typedef int64 bigtime_t;
00054 
00055 #elif ZCONFIG(OS, MacOS7) || ZCONFIG(OS, Carbon)
00056 
00057         #if ZCONFIG(Compiler, GCC)
00058                 #include <Carbon/Carbon.h>
00059         #else
00060                 #include <MacTypes.h>
00061         #endif
00062 
00063         typedef SInt8 int8;
00064         typedef UInt8 uint8;
00065 
00066         typedef SInt16 int16;
00067         typedef UInt16 uint16;
00068 
00069         typedef SInt32 int32;
00070         typedef UInt32 uint32;
00071 
00072         typedef SInt64 int64;
00073         typedef UInt64 uint64;
00074 
00075         typedef int64 bigtime_t;
00076         
00077 #else
00078 
00079         #include <stdint.h>
00080 
00081         typedef int8_t int8;
00082         typedef uint8_t uint8;
00083 
00084         typedef int16_t int16;
00085         typedef uint16_t uint16;
00086 
00087         typedef int32_t int32;
00088         typedef uint32_t uint32;
00089 
00090         typedef int64_t int64;
00091         typedef uint64_t uint64;
00092 
00093         typedef int64 bigtime_t;
00094 
00095 #endif
00096 
00097 // ==================================================
00098 
00099 // Use the ZFourCC inline if possible.
00100 inline uint32 ZFourCC(uint8 a, uint8 b, uint8 c, uint8 d)
00101         { return uint32((a << 24) | (b << 16) | (c << 8) | d); }
00102 
00103 // And the macro if a compile-time constant is needed (case statements).
00104 #define ZFOURCC(a,b,c,d) \
00105         ((uint32)((((uint8)a) << 24) | (((uint8)b) << 16) | (((uint8)c) << 8) | (((uint8)d))))
00106 
00107 // ==================================================
00108 // Macros to help harmonize function signatures between 68K and PPC.
00109 
00110 #if ZCONFIG(Processor, 68K)
00111 #       define ZPARAM_D0 : __D0
00112 #       define ZPARAM_A0 : __A0
00113 #       define ZPARAM_A1 : __A1
00114 #else
00115 #       define ZPARAM_D0
00116 #       define ZPARAM_A0
00117 #       define ZPARAM_A1
00118 #endif
00119 
00120 // ==================================================
00121 
00122 struct ZPointPOD
00123         {
00124         int32 h;
00125         int32 v;
00126         };
00127 
00128 struct ZRectPOD
00129         {
00130         int32 left;
00131         int32 top;
00132         int32 right;
00133         int32 bottom;
00134         };
00135 
00136 // ==================================================
00137 
00138 enum ZType
00139         {
00140         eZType_Null,
00141         eZType_String, eZType_CString,
00142         eZType_Int8, eZType_Int16, eZType_Int32, eZType_Int64,
00143         eZType_Float, eZType_Double,
00144         eZType_Bool,
00145         eZType_Pointer,
00146         eZType_Raw,
00147         eZType_Tuple,
00148         eZType_RefCounted,
00149         eZType_Rect,
00150         eZType_Point,
00151         eZType_Region,
00152         eZType_ID,
00153         eZType_Vector,
00154         eZType_Type,
00155         eZType_Time
00156         };
00157 
00158 const char* ZTypeAsString(ZType iType);
00159 
00160 // ==================================================
00161 namespace ZooLib {
00162 
00163 // There are several places where we need a buffer for some other code
00164 // to dump data into, the content of which we don't care about. Rather
00165 // than having multiple static buffers, or requiring wasteful use of
00166 // stack space (a problem on MacOS 9) we instead have a shared garbage
00167 // buffer. The key thing to remember in using it is that it must never
00168 // be read from -- there's no way to know what other code is also using it.
00169 
00170 extern char sGarbageBuffer[4096];
00171 
00172 // In many places we need a stack-based buffer. Ideally they'd be quite large
00173 // but on MacOS 9 we don't want to blow the 24K - 32K that's normally available.
00174 // This constant is 4096 on most platforms, 256 on MacOS 9.
00175 
00176 #if ZCONFIG(OS, MacOS7) || (ZCONFIG(OS, Carbon) && !__MACH__)
00177         static const size_t sStackBufferSize = 256;
00178 #else
00179         static const size_t sStackBufferSize = 4096;
00180 #endif
00181 
00182 } // namespace ZooLib
00183 
00184 // ==================================================
00185 // For a discussion of the implementation of countof See section 14.3 of
00186 // "Imperfect C++" by Matthew Wilson, published by Addison Wesley.
00187 namespace ZooLib {
00188 template<typename T, int N>
00189 uint8 (&byte_array_of_same_dimension_as(T(&)[N]))[N];
00190 } // namespace ZooLib
00191 
00192 #define countof(x) sizeof(ZooLib::byte_array_of_same_dimension_as((x)))
00193 
00194 // ==================================================
00195 // AG 2000-08-16. ZMouse being here is a temporary stopgap. We have to lose the file ZMouse.h,
00196 // because it conflicts with Microsoft's file of the same name, and I haven't decided where to
00197 // go with the ZMouse enums.
00198 
00199 namespace ZMouse {
00200 
00201 enum Motion { eMotionEnter, eMotionMove, eMotionLinger, eMotionLeave };
00202 enum Button { eButtonLeft, eButtonMiddle, eButtonRight,
00203                                 buttonLeft = eButtonLeft,
00204                                 buttonMiddle = eButtonMiddle,
00205                                 buttonRight = eButtonRight };
00206 } // namespace ZMouse
00207 
00208 #endif // __ZTypes__

Generated on Thu Jul 26 11:21:52 2007 for ZooLib by  doxygen 1.4.7