nomlib
Loading...
Searching...
No Matches
platforms.hpp
1/******************************************************************************
2
3 nomlib - C++11 cross-platform game engine
4
5Copyright (c) 2013, 2014 Jeffrey Carpenter <i8degrees@gmail.com>
6All rights reserved.
7
8Redistribution and use in source and binary forms, with or without
9modification, are permitted provided that the following conditions are met:
10
111. Redistributions of source code must retain the above copyright notice, this
12 list of conditions and the following disclaimer.
132. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation
15 and/or other materials provided with the distribution.
16
17THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28******************************************************************************/
29#ifndef NOMLIB_SUPPORTED_PLATFORMS_HPP
30#define NOMLIB_SUPPORTED_PLATFORMS_HPP
31
37
38#if defined(_WIN32) || defined(__WIN32__)
39 #define NOM_PLATFORM_WINDOWS
40// NOTE: The following two macros -- linux and __linux -- are obsolete and are
41// not POSIX compliant!
42#elif defined(__linux__) || defined(linux) || defined(__linux)
43 #define NOM_PLATFORM_LINUX
44 #define NOM_PLATFORM_POSIX
45#elif defined(__APPLE__) || defined(__MAC__) || defined(MACOSX) || defined(macintosh) || defined(Macintosh)
46 #define NOM_PLATFORM_OSX
47 #define NOM_PLATFORM_POSIX // Assume POSIX-compliant Unix
48#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
49 defined(__bsdi__) || defined(__DragonFly__)
50 #define NOM_PLATFORM_BSD
51 #define NOM_PLATFORM_POSIX
52#endif
53
59#if defined( __i386__ ) || defined( _M_IX86 )
60 #define NOM_PLATFORM_ARCH_X86
61#elif defined( __x86_64__ ) || defined( _M_AMD64 )
62 #define NOM_PLATFORM_ARCH_X86_64
63#endif
64
68#if defined(_MSC_VER) // Microsoft Visual C++
69 #define NOM_COMPILER_MSVCPP
70 #define NOM_COMPILER_FEATURE_NULLPTR // See include/nomlib/types.hpp
71#else // Assume llvm-clang
72 #define NOM_COMPILER_CLANG
73 #define NOM_COMPILER_FEATURE_NULLPTR // See include/nomlib/types.hpp
74#endif
75
77#if defined ( NOM_COMPILER_MSVCPP ) // MSVC++
79 #define NOM_FUNC __FUNCTION__
80#else // We assume clang or GNU v2+
81 #define NOM_FUNC __PRETTY_FUNCTION__
82#endif
83
84#ifdef PATH_MAX
85 #undef PATH_MAX
86#endif
87
101#define PATH_MAX 256
102
103// Cross-platform macro for obtaining the CPU's Time Stamp Counter (RDTSC)
104//
105// See also
106// 1. http://handmadehero.com
107// 2. http://www.strchr.com/performance_measurements_with_rdtsc
108#if defined(NOM_PLATFORM_WINDOWS) && defined(NOM_COMPILER_MSVCPP)
109 // Use built-in compiler intrinsic
110 #define NOM_RDTSC() __rdtsc();
111#else // Assume clang compiler
112 #define NOM_RDTSC() nom::rdtsc()
113#endif // MS Windows && MSVCPP
114
115namespace nom {
116
117enum Platform
118{
119 PLATFORM_UNKNOWN = 0,
120 PLATFORM_WINDOWS,
121 PLATFORM_LINUX,
122 PLATFORM_BSD,
123 PLATFORM_OSX,
124 NUM_PLATFORMS,
125};
126
128{
130 const char* name = "Unknown";
131
133 Platform env = PLATFORM_UNKNOWN;
134
136 int num_cpus = 1;
137
140
142 int total_ram = 0;
143};
144
145PlatformSpec platform_info();
146
147} // namespace nom
148
149#endif // include guard
Platform env
The platform's environment.
int total_ram
The total available system RAM (in bytes).
const char * name
The platform name.
int cpu_cache_size
The L1 cache size of the CPU (in bytes).
int num_cpus
The number of available CPUs.