GoogleToolboxSubset/GTMDefines.h
author Jens Alfke <jens@mooseyard.com>
Sat Mar 28 09:39:31 2009 -0700 (2009-03-28)
changeset 21 88d7e2455a7f
permissions -rw-r--r--
(merge)
     1 // 
     2 // GTMDefines.h
     3 //
     4 //  Copyright 2008 Google Inc.
     5 //
     6 //  Licensed under the Apache License, Version 2.0 (the "License"); you may not
     7 //  use this file except in compliance with the License.  You may obtain a copy
     8 //  of the License at
     9 // 
    10 //  http://www.apache.org/licenses/LICENSE-2.0
    11 // 
    12 //  Unless required by applicable law or agreed to in writing, software
    13 //  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    14 //  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
    15 //  License for the specific language governing permissions and limitations under
    16 //  the License.
    17 //
    18  
    19 // ============================================================================
    20 
    21 // ----------------------------------------------------------------------------
    22 // CPP symbols that can be overridden in a prefix to control how the toolbox
    23 // is compiled.
    24 // ----------------------------------------------------------------------------
    25 
    26 
    27 // GTMHTTPFetcher will support logging by default but only hook its input
    28 // stream support for logging when requested.  You can control the inclusion of
    29 // the code by providing your own definitions for these w/in a prefix header.
    30 //
    31 #ifndef GTM_HTTPFETCHER_ENABLE_LOGGING
    32 # define GTM_HTTPFETCHER_ENABLE_LOGGING 1
    33 #endif // GTM_HTTPFETCHER_ENABLE_LOGGING
    34 #ifndef GTM_HTTPFETCHER_ENABLE_INPUTSTREAM_LOGGING
    35 # define GTM_HTTPFETCHER_ENABLE_INPUTSTREAM_LOGGING 0
    36 #endif // GTM_HTTPFETCHER_ENABLE_INPUTSTREAM_LOGGING
    37 
    38 
    39 // _GTMDevLog & _GTMDevAssert
    40 //
    41 // _GTMDevLog & _GTMDevAssert are meant to be a very lightweight shell for
    42 // developer level errors.  This implementation simply macros to NSLog/NSAssert.
    43 // It is not intended to be a general logging/reporting system.
    44 //
    45 // Please see http://code.google.com/p/google-toolbox-for-mac/wiki/DevLogNAssert
    46 // for a little more background on the usage of these macros.
    47 //
    48 //    _GTMDevLog           log some error/problem in debug builds
    49 //    _GTMDevAssert        assert if conditon isn't met w/in a method/function
    50 //                           in all builds.
    51 // 
    52 // To replace this system, just provide different macro definitions in your
    53 // prefix header.  Remember, any implementation you provide *must* be thread
    54 // safe since this could be called by anything in what ever situtation it has
    55 // been placed in.
    56 // 
    57 
    58 // We only define the simple macros if nothing else has defined this.
    59 #ifndef _GTMDevLog
    60 
    61 #ifdef DEBUG
    62  #define _GTMDevLog(...) NSLog(__VA_ARGS__)
    63 #else
    64  #define _GTMDevLog(...) do { } while (0)
    65 #endif
    66 
    67 // we directly invoke the NSAssert handler so we can pass on the varargs
    68 // (NSAssert doesn't have a macro we can use that takes varargs)
    69 #if !defined(NS_BLOCK_ASSERTIONS)
    70 #define _GTMDevAssert(condition, ...)                                    \
    71   do {                                                                   \
    72     if (!(condition)) {                                                  \
    73       [[NSAssertionHandler currentHandler]                               \
    74           handleFailureInFunction:[NSString stringWithCString:__PRETTY_FUNCTION__] \
    75                              file:[NSString stringWithCString:__FILE__]  \
    76                        lineNumber:__LINE__                               \
    77                       description:__VA_ARGS__];                          \
    78     }                                                                    \
    79   } while(0)
    80 #else // !defined(NS_BLOCK_ASSERTIONS)
    81 #define _GTMDevAssert(condition, ...) do { } while (0)
    82 #endif // !defined(NS_BLOCK_ASSERTIONS)
    83 
    84 #endif // _GTMDevLog
    85 
    86 // ============================================================================
    87 
    88 // ----------------------------------------------------------------------------
    89 // CPP symbols defined based on the project settings so the GTM code has
    90 // simple things to test against w/o scattering the knowledge of project
    91 // setting through all the code.
    92 // ----------------------------------------------------------------------------
    93 
    94 // Provide a single constant CPP symbol that all of GTM uses for ifdefing
    95 // iPhone code.
    96 #include <TargetConditionals.h>
    97 #if TARGET_OS_IPHONE // iPhone SDK
    98   // For iPhone specific stuff
    99   #define GTM_IPHONE_SDK 1
   100 #else
   101   // For MacOS specific stuff
   102   #define GTM_MACOS_SDK 1
   103 #endif
   104 
   105 // To simplify support for 64bit (and Leopard in general), we provide the type
   106 // defines for non Leopard SDKs
   107 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
   108  // NSInteger/NSUInteger and Max/Mins
   109  #ifndef NSINTEGER_DEFINED
   110   #if __LP64__ || NS_BUILD_32_LIKE_64
   111    typedef long NSInteger;
   112    typedef unsigned long NSUInteger;
   113   #else
   114    typedef int NSInteger;
   115    typedef unsigned int NSUInteger;
   116   #endif
   117   #define NSIntegerMax    LONG_MAX
   118   #define NSIntegerMin    LONG_MIN
   119   #define NSUIntegerMax   ULONG_MAX
   120   #define NSINTEGER_DEFINED 1
   121  #endif  // NSINTEGER_DEFINED
   122  // CGFloat
   123  #ifndef CGFLOAT_DEFINED
   124   #if defined(__LP64__) && __LP64__
   125    // This really is an untested path (64bit on Tiger?)
   126    typedef double CGFloat;
   127    #define CGFLOAT_MIN DBL_MIN
   128    #define CGFLOAT_MAX DBL_MAX
   129    #define CGFLOAT_IS_DOUBLE 1
   130   #else /* !defined(__LP64__) || !__LP64__ */
   131    typedef float CGFloat;
   132    #define CGFLOAT_MIN FLT_MIN
   133    #define CGFLOAT_MAX FLT_MAX
   134    #define CGFLOAT_IS_DOUBLE 0
   135   #endif /* !defined(__LP64__) || !__LP64__ */
   136   #define CGFLOAT_DEFINED 1
   137  #endif // CGFLOAT_DEFINED
   138 #endif  // MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4