Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages | Examples

mac/Core.h

Go to the documentation of this file.
00001 //
00002 //  Copyright (c) 2003-2005 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     // calculate length of ascii string
00121     //
00122 #ifndef DWFCORE_ASCII_STRING_LENGTH
00123 #define DWFCORE_ASCII_STRING_LENGTH( s )    \
00124         ::strlen( s )
00125 #endif
00126 
00127     //
00128     // calculate length of wide string in wchar_t
00129     //
00130 #ifndef DWFCORE_WIDE_STRING_LENGTH_IN_WCHARS
00131 #define DWFCORE_WIDE_STRING_LENGTH_IN_WCHARS( s )    \
00132         ::wcslen( s )
00133 #endif
00134 
00135     //
00136     // calculate length of wide string in bytes
00137     //
00138 #ifndef DWFCORE_WIDE_STRING_LENGTH_IN_BYTES
00139 #define DWFCORE_WIDE_STRING_LENGTH_IN_BYTES( s )    \
00140         (::wcslen( s ) * sizeof(wchar_t))
00141 #endif
00142 
00143     //
00144     // copy ascii strings
00145     //
00146 #ifndef DWFCORE_ASCII_STRING_COPY
00147 #define DWFCORE_ASCII_STRING_COPY( a, b )    \
00148         ::strcpy(a, b)
00149 #endif
00150 
00151     //
00152     // copy wide strings
00153     //
00154 #ifndef DWFCORE_WIDE_STRING_COPY
00155 #define DWFCORE_WIDE_STRING_COPY( a, b )    \
00156         ::wcscpy(a, b)
00157 #endif
00158 
00159     //
00160     // copy ascii strings with a given length
00161     //
00162 #ifndef DWFCORE_ASCII_STRING_COPY_LENGTH
00163 #define DWFCORE_ASCII_STRING_COPY_LENGTH( a, b, c )    \
00164         ::strncpy(a, b, c)
00165 #endif
00166 
00167     //
00168     // copy wide strings with a given length
00169     //
00170 #ifndef DWFCORE_WIDE_STRING_COPY_LENGTH
00171 #define DWFCORE_WIDE_STRING_COPY_LENGTH( a, b, c )    \
00172         ::wcsncpy(a, b, c)
00173 #endif
00174 
00175     //
00176     // compare ascii strings
00177     //
00178 #ifndef DWFCORE_COMPARE_ASCII_STRINGS_NO_CASE
00179 inline size_t _dwfcore_compare_ascii_strings_no_case( const char* a, const char* b )
00180 {
00181         size_t len_a = DWFCORE_ASCII_STRING_LENGTH(a);
00182         size_t len_b = DWFCORE_ASCII_STRING_LENGTH(b);
00183         
00184         char* _a = DWFCORE_ALLOC_MEMORY( char, len_a );
00185         char* _b = DWFCORE_ALLOC_MEMORY( char, len_b );
00186         
00187         if ((_a == NULL) || (_b == NULL))
00188         {
00189                 return 0;
00190         }
00191         
00192         DWFCORE_ASCII_STRING_COPY( _a, a );
00193         DWFCORE_ASCII_STRING_COPY( _b, b );
00194         
00195         size_t i = 0;
00196         for(; i<len_a; i++)
00197         {
00198                 _a[i] = ::tolower( a[i] );
00199         }
00200         for(i=0; i<len_b; i++)
00201         {
00202                 _b[i] = ::tolower( b[i] );
00203         }
00204         return DWFCORE_COMPARE_ASCII_STRINGS( a, b );
00205 }       
00206 #define DWFCORE_COMPARE_ASCII_STRINGS_NO_CASE( a, b )   \
00207         _dwfcore_compare_ascii_strings_no_case( a, b )
00208 #endif
00209 
00210     //
00211     // compare wide strings
00212     //
00213 #ifndef DWFCORE_COMPARE_WIDE_STRINGS
00214 #define DWFCORE_COMPARE_WIDE_STRINGS( a, b )   \
00215         ::wcscmp( a, b )
00216 #endif
00217 
00218     //
00219     // compare wide strings
00220     //
00221 #ifndef DWFCORE_COMPARE_WIDE_STRINGS_NO_CASE
00222 #define DWFCORE_COMPARE_WIDE_STRINGS_NO_CASE( a, b )   \
00223         ::wcsicmp( a, b )
00224 #endif
00225 
00226     //
00227     // concatenate ascii strings
00228     //
00229 #ifndef DWFCORE_ASCII_STRING_CONCATENATE
00230 #define DWFCORE_ASCII_STRING_CONCATENATE( a, b )    \
00231         ::strcat(a, b)
00232 #endif
00233 
00234     //
00235     // concatenate wide strings
00236     //
00237 #ifndef DWFCORE_WIDE_STRING_CONCATENATE
00238 #define DWFCORE_WIDE_STRING_CONCATENATE( a, b )    \
00239         ::wcscat(a, b)
00240 #endif
00241 
00242 
00243 
00244     //
00245     // max
00246     //
00247 #ifndef max
00248 #define max( a, b )    a >? b
00249 #endif
00250 
00251     //
00252     // min
00253     //
00254 #ifndef min
00255 #define min( a, b )    a <? b
00256 #endif
00257 
00258     //
00259     // for some reason, having a pure virtual member function
00260     // sharing one of these names upsets gcc on OS X
00261     //
00262 #undef minor
00263 #undef major
00264 
00265     //
00266     // 
00267     //
00268 #define _DWFCORE_SWPRINTF   swprintf
00269 
00270 
00271 //
00272 //
00273 // Configuration
00274 //
00275 //
00276 
00277     //
00278     // use the ANSI string implementation
00279     //
00280 #define DWFCORE_USE_ANSI_STRING
00281 
00282     //
00283     // use ANSI specific file implementations
00284     //
00285 #define DWFCORE_USE_ANSI_FILE
00286 
00287 
00288 
00289 
00290 
00291 
00292 #else
00293 #error  This is a Mac OSX header file and is incompatible with your current system configuration
00294 #endif 
00295 
00296 #endif
00297 
00298 
00299 

Generated on Tue May 17 12:05:10 2005 for Autodesk DWF Core Library by  doxygen 1.4.1