mac/Core.h

Go to the documentation of this file.
00001 //
00002 //  Copyright (c) 2003-2006 by Autodesk, Inc.
00003 //
00004 //  By using this code, you are agreeing to the terms and conditions of
00005 //  the License Agreement included in the documentation for this code.
00006 //
00007 //  AUTODESK MAKES NO WARRANTIES, EXPRESS OR IMPLIED,
00008 //  AS TO THE CORRECTNESS OF THIS CODE OR ANY DERIVATIVE
00009 //  WORKS WHICH INCORPORATE IT.
00010 //
00011 //  AUTODESK PROVIDES THE CODE ON AN "AS-IS" BASIS
00012 //  AND EXPLICITLY DISCLAIMS ANY LIABILITY, INCLUDING
00013 //  CONSEQUENTIAL AND INCIDENTAL DAMAGES FOR ERRORS,
00014 //  OMISSIONS, AND OTHER PROBLEMS IN THE CODE.
00015 //
00016 //  Use, duplication, or disclosure by the U.S. Government is subject to
00017 //  restrictions set forth in FAR 52.227-19 (Commercial Computer Software
00018 //  Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) (Rights in Technical
00019 //  Data and Computer Software), as applicable.
00020 //
00021 
00022 #ifndef _DWFCORE_MAC_H
00023 #define _DWFCORE_MAC_H
00024 
00025 
00032 
00033 
00034 
00035 
00036 
00037 #ifdef  _DWFCORE_MAC_SYSTEM
00038 
00039 #include <time.h>
00040 #include <ctype.h>
00041 #include <stdio.h>
00042 #include <wchar.h>
00043 #include <string.h>
00044 #include <stdlib.h>
00045 #include <unistd.h>
00046 #include <sys/types.h>
00047 #include <sys/stat.h>
00048 
00049 //
00050 //
00051 // Macros
00052 //
00053 //
00054 
00055     //
00056     // byte block memory allocator
00057     //
00058 #ifndef DWFCORE_ALLOC_MEMORY
00059 #define DWFCORE_ALLOC_MEMORY( primitive_type, bytes )  \
00060         (primitive_type*) new primitive_type[bytes]
00061 #endif
00062 
00063     //
00064     // byte block memory deallocator
00065     //
00066 #ifndef DWFCORE_FREE_MEMORY
00067 #define DWFCORE_FREE_MEMORY( pointer ) \
00068         delete [] pointer; pointer = NULL;
00069 #endif
00070 
00071     //
00072     // object memory allocator
00073     //
00074 #ifndef DWFCORE_ALLOC_OBJECT
00075 #define DWFCORE_ALLOC_OBJECT( object_type ) \
00076         new object_type
00077 #endif
00078 
00079     //
00080     // object memory deallocator
00081     //
00082 #ifndef DWFCORE_FREE_OBJECT
00083 #define DWFCORE_FREE_OBJECT( pointer )  \
00084         delete pointer; pointer = NULL;
00085 #endif
00086 
00087     //
00088     // zero fill memory
00089     //
00090 #ifndef DWFCORE_ZERO_MEMORY
00091 #define DWFCORE_ZERO_MEMORY( pointer, bytes )   \
00092         ::memset( (void*)pointer, 0, bytes )
00093 #endif
00094 
00095     //
00096     // copy memory
00097     //
00098 #ifndef DWFCORE_COPY_MEMORY
00099 #define DWFCORE_COPY_MEMORY( dest, src, bytes ) \
00100         ::memcpy( (void*)dest, (const void*)src, bytes )
00101 #endif
00102 
00103     //
00104     // compare memory regions
00105     //
00106 #ifndef DWFCORE_COMPARE_MEMORY
00107 #define DWFCORE_COMPARE_MEMORY( a, b, bytes )   \
00108         ::memcmp( (const void*)a, (const void*)b, bytes )
00109 #endif
00110 
00111     //
00112     // compare ascii strings
00113     //
00114 #ifndef DWFCORE_COMPARE_ASCII_STRINGS
00115 #define DWFCORE_COMPARE_ASCII_STRINGS( a, b )   \
00116         ::strcmp( a, b )
00117 #endif
00118 
00119     //
00120     // compare atmost n characters in ascii strings 
00121     //
00122 #ifndef DWFCORE_COMPARE_ASCII_STRINGS_NCHARS
00123 #define DWFCORE_COMPARE_ASCII_STRINGS_NCHARS( a, b, n )   \
00124         ::strncmp( a, b, n )
00125 #endif
00126 
00127     //
00128     // calculate length of ascii string
00129     //
00130 #ifndef DWFCORE_ASCII_STRING_LENGTH
00131 #define DWFCORE_ASCII_STRING_LENGTH( s )    \
00132         ::strlen( s )
00133 #endif
00134 
00135     //
00136     // calculate length of wide string in wchar_t
00137     //
00138 #ifndef DWFCORE_WIDE_STRING_LENGTH_IN_WCHARS
00139 #define DWFCORE_WIDE_STRING_LENGTH_IN_WCHARS( s )    \
00140         ::wcslen( s )
00141 #endif
00142 
00143     //
00144     // calculate length of wide string in bytes
00145     //
00146 #ifndef DWFCORE_WIDE_STRING_LENGTH_IN_BYTES
00147 #define DWFCORE_WIDE_STRING_LENGTH_IN_BYTES( s )    \
00148         (::wcslen( s ) * sizeof(wchar_t))
00149 #endif
00150 
00151     //
00152     // copy ascii strings
00153     //
00154 #ifndef DWFCORE_ASCII_STRING_COPY
00155 #define DWFCORE_ASCII_STRING_COPY( a, b )    \
00156         ::strcpy(a, b)
00157 #endif
00158 
00159     //
00160     // copy wide strings
00161     //
00162 #ifndef DWFCORE_WIDE_STRING_COPY
00163 #define DWFCORE_WIDE_STRING_COPY( a, b )    \
00164         ::wcscpy(a, b)
00165 #endif
00166 
00167     //
00168     // copy ascii strings with a given length
00169     //
00170 #ifndef DWFCORE_ASCII_STRING_COPY_LENGTH
00171 #define DWFCORE_ASCII_STRING_COPY_LENGTH( a, b, c )    \
00172         ::strncpy(a, b, c)
00173 #endif
00174 
00175     //
00176     // copy wide strings with a given length
00177     //
00178 #ifndef DWFCORE_WIDE_STRING_COPY_LENGTH
00179 #define DWFCORE_WIDE_STRING_COPY_LENGTH( a, b, c )    \
00180         ::wcsncpy(a, b, c)
00181 #endif
00182 
00183     //
00184     // compare ascii strings
00185     //
00186 #ifndef DWFCORE_COMPARE_ASCII_STRINGS_NO_CASE
00187 inline size_t _dwfcore_compare_ascii_strings_no_case( const char* a, const char* b )
00188 {
00189     size_t len_a = DWFCORE_ASCII_STRING_LENGTH(a);
00190     size_t len_b = DWFCORE_ASCII_STRING_LENGTH(b);
00191     
00192     char* _a = DWFCORE_ALLOC_MEMORY( char, len_a );
00193     char* _b = DWFCORE_ALLOC_MEMORY( char, len_b );
00194     
00195     if ((_a == NULL) || (_b == NULL))
00196     {
00197         return 0;
00198     }
00199     
00200     DWFCORE_ASCII_STRING_COPY( _a, a );
00201     DWFCORE_ASCII_STRING_COPY( _b, b );
00202     
00203     size_t i = 0;
00204     for(; i<len_a; i++)
00205     {
00206         _a[i] = ::tolower( a[i] );
00207     }
00208     for(i=0; i<len_b; i++)
00209     {
00210         _b[i] = ::tolower( b[i] );
00211     }
00212     return DWFCORE_COMPARE_ASCII_STRINGS( a, b );
00213 }   
00214 #define DWFCORE_COMPARE_ASCII_STRINGS_NO_CASE( a, b )   \
00215     _dwfcore_compare_ascii_strings_no_case( a, b )
00216 #endif
00217 
00218     //
00219     // compare wide strings
00220     //
00221 #ifndef DWFCORE_COMPARE_WIDE_STRINGS
00222 #define DWFCORE_COMPARE_WIDE_STRINGS( a, b )   \
00223         ::wcscmp( a, b )
00224 #endif
00225 
00226     //
00227     // compare wide strings
00228     //
00229 #ifndef DWFCORE_COMPARE_WIDE_STRINGS_NO_CASE
00230 #define DWFCORE_COMPARE_WIDE_STRINGS_NO_CASE( a, b )   \
00231         ::wcsicmp( a, b )
00232 #endif
00233 
00234     //
00235     // concatenate ascii strings
00236     //
00237 #ifndef DWFCORE_ASCII_STRING_CONCATENATE
00238 #define DWFCORE_ASCII_STRING_CONCATENATE( a, b )    \
00239         ::strcat(a, b)
00240 #endif
00241 
00242     //
00243     // concatenate wide strings
00244     //
00245 #ifndef DWFCORE_WIDE_STRING_CONCATENATE
00246 #define DWFCORE_WIDE_STRING_CONCATENATE( a, b )    \
00247         ::wcscat(a, b)
00248 #endif
00249 
00250 
00251 
00252     //
00253     // max
00254     //
00255 #ifndef max
00256 #define max( a, b )    ( (a > b) ? a : b ) // max operator: a >? b is deprecated by gcc 4.0
00257 #endif
00258 
00259     //
00260     // min
00261     //
00262 #ifndef min
00263 #define min( a, b )    ( (a < b) ? a : b) // max operator: a <? b is deprecated by gcc 4.0
00264 #endif
00265 
00266     //
00267     // for some reason, having a pure virtual member function
00268     // sharing one of these names upsets gcc on OS X
00269     //
00270 #undef minor
00271 #undef major
00272 
00273     //
00274     // 
00275     //
00276 #define _DWFCORE_SWPRINTF   swprintf
00277 
00278 
00279 //
00280 //
00281 // Configuration
00282 //
00283 //
00284 
00285     //
00286     // use the ANSI string implementation
00287     //
00288 #define DWFCORE_USE_ANSI_STRING
00289 
00290     //
00291     // use ANSI specific file implementations
00292     //
00293 #define DWFCORE_USE_ANSI_FILE
00294 
00295 
00296 
00297 
00298 
00299 
00300 #else
00301 #error  This is a Mac OSX header file and is incompatible with your current system configuration
00302 #endif 
00303 
00304 #endif
00305 
00306 
00307 

Generated on Tue Jan 6 22:39:28 2009 for Autodesk DWF Core Library by  doxygen 1.4.5