nomlib
Toggle main menu visibility
Loading...
Searching...
No Matches
include
nomlib
platforms.hpp
1
/******************************************************************************
2
3
nomlib - C++11 cross-platform game engine
4
5
Copyright (c) 2013, 2014 Jeffrey Carpenter <i8degrees@gmail.com>
6
All rights reserved.
7
8
Redistribution and use in source and binary forms, with or without
9
modification, are permitted provided that the following conditions are met:
10
11
1. Redistributions of source code must retain the above copyright notice, this
12
list of conditions and the following disclaimer.
13
2. 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
17
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
ON 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
26
SOFTWARE, 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
115
#include "export.hpp"
116
117
namespace
nom {
118
119
enum
Platform
120
{
121
PLATFORM_UNKNOWN = 0,
122
PLATFORM_WINDOWS,
123
PLATFORM_LINUX,
124
PLATFORM_BSD,
125
PLATFORM_OSX,
126
NUM_PLATFORMS,
127
};
128
129
struct
NOM_EXPORT
PlatformSpec
130
{
132
const
char
*
name
=
"Unknown"
;
133
135
Platform
env
= PLATFORM_UNKNOWN;
136
138
int
num_cpus
= 1;
139
141
int
cpu_cache_size
= 0;
142
144
int
total_ram
= 0;
145
};
146
147
NOM_EXPORT
PlatformSpec
platform_info();
148
149
}
// namespace nom
150
151
#endif
// include guard
nom::PlatformSpec
Definition
platforms.hpp:130
nom::PlatformSpec::env
Platform env
The platform's environment.
Definition
platforms.hpp:135
nom::PlatformSpec::total_ram
int total_ram
The total available system RAM (in bytes).
Definition
platforms.hpp:144
nom::PlatformSpec::name
const char * name
The platform name.
Definition
platforms.hpp:132
nom::PlatformSpec::cpu_cache_size
int cpu_cache_size
The L1 cache size of the CPU (in bytes).
Definition
platforms.hpp:141
nom::PlatformSpec::num_cpus
int num_cpus
The number of available CPUs.
Definition
platforms.hpp:138
Generated on
for nomlib by
1.18.0