1
2//
3// This source file is part of appleseed.
4// Visit http://appleseedhq.net/ for additional information and resources.
5//
6// This software is released under the MIT license.
7//
8// Copyright (c) 2010-2013 Francois Beaune, Jupiter Jazz Limited
9// Copyright (c) 2014-2017 Francois Beaune, The appleseedhq Organization
10//
11// Permission is hereby granted, free of charge, to any person obtaining a copy
12// of this software and associated documentation files (the "Software"), to deal
13// in the Software without restriction, including without limitation the rights
14// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15// copies of the Software, and to permit persons to whom the Software is
16// furnished to do so, subject to the following conditions:
17//
18// The above copyright notice and this permission notice shall be included in
19// all copies or substantial portions of the Software.
20//
21// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27// THE SOFTWARE.
28//
29
30#ifndef APPLESEED_FOUNDATION_PLATFORM_TYPES_H
31#define APPLESEED_FOUNDATION_PLATFORM_TYPES_H
32
33// appleseed.foundation headers.
34#include "foundation/platform/arch.h"
35
36// Boost headers.
37#include "boost/static_assert.hpp"
38
39// Make sure that uintptr_t is defined on all platforms.
40#if defined _MSC_VER
41#include <cstddef>
42#endif
43#if defined __GNUC__
44#include <stdint.h>
45#endif
46
47namespace foundation
48{
49
50//
51// Define fixed-size integral types.
52//
53
54// Visual C++.
55#if defined _MSC_VER
56
57 typedef signed char int8;
58 typedef unsigned char uint8;
59
60 typedef signed short int int16;
61 typedef unsigned short int uint16;
62
63 typedef signed int int32;
64 typedef unsigned int uint32;
65
66 typedef signed long long int int64;
67 typedef unsigned long long int uint64;
68
69// gcc.
70#elif defined __GNUC__
71
72 typedef signed char int8;
73 typedef unsigned char uint8;
74
75 typedef signed short int int16;
76 typedef unsigned short int uint16;
77
78 typedef signed int int32;
79 typedef unsigned int uint32;
80
81 #if defined APPLESEED_ARCH32
82 typedef signed long long int int64;
83 typedef unsigned long long int uint64;
84 #elif defined APPLESEED_ARCH64
85 typedef signed long int int64;
86 typedef unsigned long int uint64;
87 #else
88 #error Cannot determine machine architecture.
89 #endif
90
91// Other platforms.
92#else
93
94 #error Fixed-size integral types are not defined on this platform.
95
96#endif
97
98BOOST_STATIC_ASSERT(sizeof(int8) == 1);
99BOOST_STATIC_ASSERT(sizeof(int16) == 2);
100BOOST_STATIC_ASSERT(sizeof(int32) == 4);
101BOOST_STATIC_ASSERT(sizeof(int64) == 8);
102BOOST_STATIC_ASSERT(sizeof(uint8) == 1);
103BOOST_STATIC_ASSERT(sizeof(uint16) == 2);
104BOOST_STATIC_ASSERT(sizeof(uint32) == 4);
105BOOST_STATIC_ASSERT(sizeof(uint64) == 8);
106
107
108//
109// Define a signed counterpart to std::size_t, i.e. a synonym for the non-standard ssize_t type.
110//
111
112#if defined APPLESEED_ARCH32
113 typedef int32 isize_t;
114#elif defined APPLESEED_ARCH64
115 typedef int64 isize_t;
116#else
117 #error Cannot determine machine architecture.
118#endif
119
120BOOST_STATIC_ASSERT(sizeof(isize_t) == sizeof(size_t));
121
122
123//
124// Format strings to use with std::printf() variants.
125//
126
127// Visual C++.
128#if defined _MSC_VER
129
130 #define FMT_UINT64 "%llu"
131 #define FMT_UINT64_HEX "%llx"
132 #define FMT_SIZE_T "%Iu"
133
134// gcc.
135#elif defined __GNUC__
136
137 #if defined APPLESEED_ARCH32
138 #define FMT_UINT64 "%llu"
139 #define FMT_UINT64_HEX "%llx"
140 #elif defined APPLESEED_ARCH64
141 #define FMT_UINT64 "%lu"
142 #define FMT_UINT64_HEX "%lx"
143 #else
144 #error Cannot determine machine architecture.
145 #endif
146
147 #define FMT_SIZE_T "%zu"
148
149// Other compilers.
150#else
151
152 #error Format strings are not defined on this platform.
153
154#endif
155
156} // namespace foundation
157
158#endif // !APPLESEED_FOUNDATION_PLATFORM_TYPES_H
159