Humble Framework for SkyOS


Main Page | Modules | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

HAL.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 **  $Header: /SkyOS.root/HFramework/HAL.h 9     4/17/05 12:29p Lee Neuse $
00004 **
00005 ****************************************************************************/
00022 #ifndef HAL_H
00023     #define HAL_H
00024 /*  ----------------------------------------------------------------------
00025     OS-specific headers
00026     ----------------------------------------------------------------------  */
00027 //
00028 //  ANSI C++ RTL
00029 //
00030 #include <ctype.h>
00031 #include <limits.h>
00032 //
00033 //  STL headers
00034 //
00035 #include <algorithm>
00036 #include <functional>
00037 #include <iterator>
00038 #include <list>
00039 #include <map>
00040 #include <stdexcept>
00041 #include <string>
00042 #include <vector>
00043 //
00044 //  SkyOS headers
00045 //
00046 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00047 
00048 extern "C"
00049     {
00050     #include <skygi.h>
00051     #include <gc.h>
00052 /*
00053 **  SkyGI Function Prototypes missing from system headers
00054 */
00055     HRESULT             DefaultWindowFunc(HANDLE, s_gi_msg *);
00056     HRESULT             GetApplicationDirectory(char *); 
00057     
00058     HRESULT             GC_ResetBlit(sBlit *);
00059 
00060     int                 GI_beginpaint(void);
00061     int                 GI_endpaint(void);
00062 
00063     HANDLE              GI_CreateWidgetPanel(HANDLE, unsigned char *, int, int, int, int, int, int);
00064     HANDLE              GI_CreateWidgetPanelItem(HANDLE, unsigned char *, int, int, int, int, int, int);
00065     HRESULT             GI_LayoutAdd(HANDLE, HANDLE, int, int, int, int);
00066     HRESULT             GI_LayoutRemove(HANDLE, HANDLE);
00067     HRESULT             GI_LayoutSetItemSize(HANDLE, HANDLE, int);
00068     
00069     HANDLE              GI_create_widget_splitter(HANDLE, unsigned char *, int, int, int, int, int, int);
00070     int                 GI_widget_splitter_add_window(HANDLE, int, HANDLE);
00071     int                 GI_widget_splitter_set_width(HANDLE, int);
00072     int                 GI_widget_splitter_set_bar_width(HANDLE, int);
00073 
00074     int                 GI_widget_static_set_font(HANDLE, int, int);
00075     int                 GI_widget_static_use_parent_background(HANDLE, int);
00076     
00077     int                 GI_widget_textfield_delete(HANDLE);
00078     int                 GI_widget_textfield_redraw(HANDLE);
00079     int                 GI_widget_textfield_set_rdonly(HANDLE, int);
00080     int                 GI_widget_textfield_set_line_backcolor(HANDLE, int, COLOR);
00081 
00082     int                 GI_FileSelect(HANDLE, unsigned int, char *, unsigned char *, unsigned char *, sSelectFileTypes *);
00083 
00084     unsigned int        SkyGI_PostMessage(HANDLE, unsigned int, unsigned int, unsigned int);
00085     }
00086 #endif  // DOXYGEN_SHOULD_SKIP_THIS
00087 /*  ----------------------------------------------------------------------
00088     Global Data Primitives
00089     ----------------------------------------------------------------------  */
00093 
00095 typedef char                Text;
00097 typedef Text *              TextPtr;
00099 typedef Text const *        StringPtr;
00100 /*
00101 **  [u]int8 -- an 8-bit value, better known to millions as a "byte".
00102 */
00103 #ifndef int8
00104 
00105     typedef signed char     int8;
00106 #endif
00107 #ifndef uint8
00108 
00109     typedef unsigned char   uint8;
00110 #endif
00111 
00112 const int8                  INT8_MAX = SCHAR_MAX;      
00113 const int8                  INT8_MIN = SCHAR_MIN;      
00114 const uint8                 UINT8_MAX = UCHAR_MAX;     
00115 /*
00116 **  [u]int16 -- an 16-bit value, aka a "word".
00117 */
00118 #ifndef int16
00119 
00120     typedef short           int16;
00121 #endif
00122 #ifndef uint16
00123 
00124     typedef unsigned short  uint16;
00125 #endif
00126 
00127 const int16                 INT16_MAX = SHRT_MAX;      
00128 const int16                 INT16_MIN = SHRT_MIN;      
00129 const uint16                UINT16_MAX = USHRT_MAX;    
00130 /*
00131 **  [u]int32 -- an 32-bit value, or a "double word".
00132 */
00133 #ifndef int32
00134 
00135     typedef long            int32;
00136 #endif
00137 #ifndef uint32
00138 
00139     typedef unsigned long   uint32;
00140 #endif
00141 
00142 const int32                 INT32_MAX = LONG_MAX;      
00143 const int32                 INT32_MIN = LONG_MIN;      
00144 const uint32                UINT32_MAX = ULONG_MAX;    
00145 /*
00146 **  Other stuff
00147 */
00149 typedef void *          Ptr;
00151 typedef void const *    PtrConst;
00153 typedef uint8 *         PtrData;
00155 typedef uint8 const *   PtrDataConst;
00157 #define TEXT(p)         ((unsigned char *)(p))
00158 
00159 /*  ----------------------------------------------------------------------
00160     Global Constants
00161     ----------------------------------------------------------------------  */
00163 const StringPtr         kStrEmpty       = "";
00165 const StringPtr         kStrEOL         = "\n";
00167 const Text              kDirSeparator   = '/';
00168 
00169 #ifndef MAX_PATH
00170 
00171 const uint32            MAX_PATH = 1023;
00172 #endif
00173 
00174 #ifndef S_FAILED
00175 const HRESULT           S_FAILED = ~S_OK;
00176 #endif
00177 
00178 /*  ----------------------------------------------------------------------
00179     Global Macros
00180     ----------------------------------------------------------------------  */
00181 #define NOTHING         ((void)0)
00182 
00183 #define KB(n)           ((n) * 1024)
00184 #define MB(n)           (KB(n) * 1024)
00185 #define GB(n)           (MB(n) * 1024)
00186 
00188 #define ARRAY_DIM(x)    (sizeof(x)/sizeof((x)[0]))
00189 
00191 #define GOOD_HND(h)     (NULL != HANDLE(h))
00192 
00193 #define NULL_HND(h)     (NULL == HANDLE(h))
00194 
00195 #define GOOD_PTR(p)     (NULL != Ptr(p))
00196 
00197 #define NULL_PTR(p)     (NULL == Ptr(p))
00198 //
00199 //  MAKE_PTR(cast, ptr, count) simplifies ptr math by adding "count" to
00200 //  the "ptr", and then casting the new value as a "cast".  For example
00201 //  MAKE_PTR(DIB *, pVoid, 5) is equivalent to (DIB *)&(((uint8 *)pVoid)[5])
00202 //
00203 #define MAKE_PTR(c,p,n) reinterpret_cast<c>(size_t(p)+size_t(n))
00204 //
00205 //  Since GCC seems to be the default compiler for SkyOS, take advantage of 
00206 //  some of it's better features...
00207 //
00208 #ifdef  __GNUC__
00209 #   if  ((__GNUC__ < 2) || (__GNUC__ == 2 && __GNUC_MINOR__ < 95))
00210 #       error The Humble Framework requires GCC 2.95 or better.
00211 #   endif
00212 #   define  GCC_ONLY(x) x
00213 #else
00214 #   define  GCC_ONLY(x)
00215 #endif
00216 //
00217 //  Test macros
00218 //
00219 #ifdef  HTEST_H
00220 #   define TEST_ONLY(x) x
00221 #else
00222 #   define TEST_ONLY(x)
00223 #endif
00224 /*  ----------------------------------------------------------------------
00225     Global Functions
00226     ----------------------------------------------------------------------  */
00227 namespace Humble
00228     {
00229     const uint32        BAD_INDEX = std::string::npos;
00236 #ifndef max
00237     template <class T> T
00238     max(const T & x, const T & y)
00239         { return (x > y) ? x : y; }
00240 #endif
00247 #ifndef min
00248     template <class T> T
00249     min(const T & x, const T & y)
00250         { return (x < y) ? x : y; }
00251 #endif
00263     template <class T> void
00264     minmax(const T * array, uint32 uCount, T & minVal, T & maxVal)
00265         {
00266         T       x1, x2;
00267         uint32  udx, udx1, udx2, udx3, udx4, udx5;
00268 
00269         udx1 = udx2 = 0;
00270         udx3 = ((uCount % 2) != 0) ? 0 : 1;
00271         minVal = maxVal = array[0];
00272 
00273         for (udx = udx3; udx < uCount; udx += 2)
00274             {
00275             udx4 = udx;
00276             udx5 = udx + 1;
00277             x1 = array[udx4];
00278             x2 = array[udx5];
00279 
00280             if (x1 > x2)
00281                 {
00282                 udx4 = udx5;
00283                 udx5 = udx;
00284                 x1 = x2;
00285                 x2 = array[udx5];
00286                 }
00287 
00288             if (x1 < minVal)
00289                 {
00290                 minVal = x1;
00291                 udx1 = udx4;
00292                 }
00293 
00294             if (x2 > maxVal)
00295                 {
00296                 maxVal = x2;
00297                 udx2 = udx5;
00298                 }
00299             }
00300         }
00311 #ifndef swap
00312     template<class T> void
00313     swap(T & x, T & y)
00314         { T t = x; x = y; y = t; }
00315 #endif
00327     template <class T> void
00328     swapInPlace(T & x, T & y)
00329         { x ^= y; y ^= x; x ^= y; }
00330     };  // namespace Humble
00331 /*  ----------------------------------------------------------------------
00332     Memory Macros
00333     ----------------------------------------------------------------------  */
00339 #define MEM_CMP(x,y,n)  Humble::safe_memcmp((x),(y),(n))
00340 
00341 #define MEM_COPY(d,s,n) Humble::safe_memcpy((d),(s),(n))
00342 
00343 #define MEM_FILL(d,c,n) Humble::safe_memset((d),(c),(n))
00344 
00345 #define MEM_MOVE(d,s,n) Humble::safe_memmove((d),(s),(n))
00346 
00347 #define MEM_ZERO(d,n)   Humble::safe_memset((d),0x00,(n))
00348 
00349 /*  ----------------------------------------------------------------------
00350     String Macros
00351     ----------------------------------------------------------------------  */
00362 #define STR_COUNT(p,c)  Humble::safe_strcount((p),(c))
00363 
00364 #define STR_EMPTY(p)    (NULL_PTR(p) || *(p) == '\0')
00365 
00366 #define STR_SAFE(p)     (GOOD_PTR(p) ? (p) : kStrEmpty)
00367 
00368 #define STR_VALID(p)    (GOOD_PTR(p) && *(p) != '\0')
00369 
00370 #define STR_CAT(s,d,n)  Humble::safe_strncat((s),(d),(n))
00371 
00372 #define STR_CHR(s,c)    Humble::safe_strchr((s),(c))
00373 
00374 #define STR_CMP(a,b)    Humble::safe_strcmp((a),(b))
00375 
00376 #define STR_ICMP(a,b)   Humble::safe_strcmpi((a),(b))
00377 
00378 #define STR_NCMP(a,b,n) Humble::safe_strcmpn((a),(b),(n))
00379 
00380 #define STR_WCMP(a,b)   Humble::safe_strcmpw((a),(b))
00381 
00382 #define STR_CPY(s,d)    Humble::safe_strncpy((s),(d))
00383 #define STR_NCPY(s,d,n) Humble::safe_strncpy((s),(d),(n))
00384 
00385 #define STR_LEN(s)      Humble::safe_strlen(s)
00386 #define STR_NLEN(s,u)   Humble::safe_strlen((s),(u))
00387 
00388 #define STR_LWR(s)      Humble::safe_strlwr(s)
00389 
00390 #define STR_RCHR(s,c)   Humble::safe_strrchr((s),(c))
00391 
00392 #define STR_REV(s)      Humble::safe_strrev(s)
00393 
00394 #define STR_SPRINTF     Humble::safe_sprintf
00395 
00396 #define STR_STR(s,a)    Humble::safe_strstr((s),(a))
00397 
00398 #define STR_TO_INT(s)   Humble::safe_strtoi(s)
00399 
00400 #define STR_UPR(s)      Humble::safe_strupr(s)
00401 
00402 #define STR_VSPRINTF    Humble::safe_vsprintf
00403 
00404 /*  ----------------------------------------------------------------------
00405     Global Function Prototypes -- see Humble.cpp for implementation
00406     ----------------------------------------------------------------------  */
00407 namespace Humble
00408     {
00409 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00410     GCC_ONLY(__attribute__((format(printf,2,3))))
00411 #endif
00412     void                PopUpAlert(StringPtr, StringPtr pstrBase = NULL, ...);
00413 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00414     GCC_ONLY(__attribute__((format(printf,2,3))))
00415 #endif
00416     void                PopUpInfo(StringPtr, StringPtr pstrBase = NULL, ...);
00417 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00418     GCC_ONLY(__attribute__((format(printf,2,3))))
00419 #endif
00420     int32               PopUpOKCancel(StringPtr, StringPtr pstrBase = NULL, ...);
00421 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00422     GCC_ONLY(__attribute__((format(printf,2,3))))
00423 #endif
00424     int32               PopUpYesNo(StringPtr, StringPtr pstrBase = NULL, ...);
00425 
00426     int32               safe_memcmp(PtrConst, PtrConst, uint32);
00427     Ptr                 safe_memcpy(Ptr, PtrConst, uint32);
00428     Ptr                 safe_memmove(Ptr, PtrConst, uint32);
00429     Ptr                 safe_memset(Ptr, uint8, uint32);
00430 
00431     StringPtr           safe_strchr(StringPtr, Text);
00432     int32               safe_strcmp(StringPtr, StringPtr);
00433     int32               safe_strcmpi(StringPtr, StringPtr);
00434     int32               safe_strcmpn(StringPtr, StringPtr, uint32);
00435     bool                safe_strcmpw(StringPtr, StringPtr);
00436     TextPtr             safe_strncat(TextPtr, StringPtr, int32);
00437     TextPtr             safe_strncpy(TextPtr, StringPtr, int32 nMaxLen = INT32_MAX);
00438     int32               safe_strcount(StringPtr, Text);
00439     int                 safe_strlen(StringPtr, int32 nMaxLen = INT32_MAX);
00440     TextPtr             safe_strlwr(TextPtr);
00441     StringPtr           safe_strrchr(StringPtr, Text);
00442     TextPtr             safe_strrev(TextPtr);
00443     StringPtr           safe_strstr(StringPtr, StringPtr);
00444     int32               safe_strtoi(StringPtr);
00445     TextPtr             safe_strupr(TextPtr);
00446     int32               safe_vsprintf(TextPtr, int32, StringPtr, va_list);
00447 
00448 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00449     GCC_ONLY(__attribute__ ((format (printf,3,4))))
00450 #endif
00451     int32               safe_sprintf(TextPtr, int32, StringPtr, ...);
00452     };  // namespace Humble
00453 
00454 #endif  //  HAL_H
00455 /****************************************************************************
00456 **
00457 **  $History: HAL.h $
00458  * 
00459  * *****************  Version 9  *****************
00460  * User: Lee Neuse    Date: 4/17/05    Time: 12:29p
00461  * Updated in $/SkyOS.root/HFramework
00462  * Development snapshot 050417
00463  * 
00464  * *****************  Version 7  *****************
00465  * User: Neusel       Date: 2/04/05    Time: 10:45a
00466  * Updated in $/SkyOS.root/pig/Humble
00467  * 
00468  * *****************  Version 6  *****************
00469  * User: Neusel       Date: 12/24/04   Time: 3:59p
00470  * Updated in $/SkyOS.root/pig/Humble
00471  * 
00472  * *****************  Version 5  *****************
00473  * User: Neusel       Date: 12/23/04   Time: 1:34p
00474  * Updated in $/SkyOS.root/pig/Humble
00475  * Posted as HFramework-debug 20041223
00476  * 
00477  * *****************  Version 4  *****************
00478  * User: Neusel       Date: 12/10/04   Time: 3:57p
00479  * Updated in $/SkyOS.root/pig/Humble
00480  * 20041210
00481  * 
00482  * *****************  Version 3  *****************
00483  * User: Neusel       Date: 12/08/04   Time: 5:06p
00484  * Updated in $/SkyOS.root/pig/Humble
00485  * 20041208
00486  * 
00487  * *****************  Version 2  *****************
00488  * User: Neusel       Date: 11/30/04   Time: 1:01p
00489  * Updated in $/SkyOS.root/pig/Humble
00490  * Released as HUMBLE_VER 20041130.
00491  * 
00492  * *****************  Version 1  *****************
00493  * User: Neusel       Date: 11/23/04   Time: 8:24a
00494  * Created in $/SkyOS.root/pig/Humble
00495 **
00496 **  -------------------------------------------------------------------------
00497 **
00498 **  End of HAL.h
00499 **
00500 ****************************************************************************/