1 /* 2 * Platform.h 3 * Apto 4 * 5 * Created by David on 3/2/07. 6 * Copyright 2007-2011 David Michael Bryson. All rights reserved. 7 * http://programerror.com/software/apto 8 * 9 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the 10 * following conditions are met: 11 * 12 * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the 13 * following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the 15 * following disclaimer in the documentation and/or other materials provided with the distribution. 16 * 3. Neither the name of David Michael Bryson, nor the names of contributors may be used to endorse or promote 17 * products derived from this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY DAVID MICHAEL BRYSON AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 * DISCLAIMED. IN NO EVENT SHALL DAVID MICHAEL BRYSON OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 25 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * 27 * Authors: David M. Bryson <david@programerror.com> 28 * 29 * Platform detection macro structure inspired by platform detection in Webkit <http://www.webkit.org> 30 * Initial implementation was in Avida <http://avida.devosoft.org> 31 */ 32 33 #ifndef AptoPlatformPlatform_h 34 #define AptoPlatformPlatform_h 35 36 // spaces between defined's parentheses and contained value are required by Visual Studio's preprocessor 37 #define APTO_PLATFORM(PROP) (defined( APTO_PLATFORM_ ## PROP ) && APTO_PLATFORM_##PROP) 38 39 #if defined(WIN32) || defined(_WIN32) 40 # define APTO_PLATFORM_WINDOWS 1 41 # ifdef _MSC_VER 42 # define APTO_PLATFORM_MSVC 1 43 # define NOMINMAX 44 # else 45 # define APTO_PLATFORM_MSVC 0 46 # endif 47 # ifdef DISABLE_THREADS 48 # define APTO_PLATFORM_THREADS 0 49 # else 50 # define APTO_PLATFORM_THREADS 1 51 # endif 52 // Disable warning C4355: 'this' : used in base member initializer list 53 # pragma warning( disable : 4355 ) 54 #endif 55 56 #if defined(__APPLE__) || defined(unix) || defined(__unix) || defined(__unix__) || defined (__NetBSD__) || defined(_AIX) || defined(__FreeBSD__) 57 # define APTO_PLATFORM_UNIX 1 58 # define APTO_PLATFORM_THREADS 1 59 #endif 60 61 #if defined(__FreeBSD__) 62 # define APTO_PLATFORM_FREEBSD 1 63 #endif 64 65 #if defined(__APPLE__) 66 # define APTO_PLATFORM_APPLE 1 67 #endif 68 69 #if defined(__GNUC__) && __GNUC__ >= 4 70 # define APTO_PLATFORM_GNUC 1 71 #endif 72 73 #if defined(__hppa__) || defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || \ 74 (defined(__MIPS__) && defined(__MISPEB__)) || defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || \ 75 defined(__sparc__) 76 # define APTO_PLATFORM_BIG_ENDIAN 1 77 # define APTO_PLATFORM_LITTLE_ENDIAN 0 78 #else 79 # define APTO_PLATFORM_BIG_ENDIAN 0 80 # define APTO_PLATFORM_LITTLE_ENDIAN 1 81 #endif 82 83 84 #ifdef DEBUG 85 # include <cstdlib> 86 # include <iostream> 87 # define ASSERT_MSG(VALUE, MSG) if (!(VALUE)) { std::cerr << "Error: " << MSG << std::endl; abort(); } 88 #else 89 # define ASSERT_MSG(VALUE, MSG) 90 #endif 91 92 93 #ifndef NULL 94 #define NULL 0 95 #endif 96 97 98 namespace Apto { 99 namespace Platform 100 { 101 void Initialize(); 102 103 int AvailableCPUs(); 104 }; 105 }; 106 107 108 109 #endif 110