1// tPlatform.cpp 
2// 
3// Tacent platform defines, architecture, and endianness detection. The Tacent library has some preprocessor define 
4// requirements. One of PLATFORM_NNN, ARCHITECTURE_NNN, and CONFIG_NNN need to be defined. If you haven't bothered 
5// to define these in the project file with a /D switch, an attempt is made to define them automatically for you. 
6// 
7// Copyright (c) 2004-2006, 2015, 2017, 2020, 2021, 2023 Tristan Grimmer. 
8// Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby 
9// granted, provided that the above copyright notice and this permission notice appear in all copies. 
10// 
11// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL 
12// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 
13// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 
14// AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 
15// PERFORMANCE OF THIS SOFTWARE. 
16 
17#include "Foundation/tPlatform.h" 
18#include "Foundation/tString.h" 
19 
20 
21tPlatform tGetPlatform() 
22
23 #if defined(PLATFORM_WINDOWS) 
24 return tPlatform::Windows; 
25 #elif defined(PLATFORM_LINUX) 
26 return tPlatform::Linux
27 #elif defined(PLATFORM_MACOS) 
28 return tPlatform::MacOS; 
29 #elif defined(PLATFORM_ANDROID) 
30 return tPlatform::Android; 
31 #elif defined(PLATFORM_IOS) 
32 return tPlatform::iOS; 
33 #else 
34 return tPlatform::Invalid; 
35 #endif 
36
37 
38 
39tPlatform tGetPlatform(const tString& name
40
41 for (int p = 0; p < int(tPlatform::NumPlatforms); p++) 
42 if (name == tGetPlatformName(tPlatform(p))) 
43 return tPlatform(p); 
44 
45 return tPlatform::Invalid
46
47 
48 
49const char* tGetPlatformName(tPlatform plat
50
51 const static char* platNames[] = 
52
53 "Windows"
54 "Linux"
55 "MacOS"
56 "Android"
57 "iOS"
58 "All"
59 "Invalid"
60 }; 
61 tStaticAssert( ((sizeof(platNames)/sizeof(*platNames)) - 2) == int(tPlatform::NumPlatforms) ); 
62 
63 if (plat == tPlatform::Invalid
64 return platNames[int(tPlatform::NumPlatforms)+1]; 
65 
66 return platNames[int(plat)]; 
67
68 
69 
70const char* tGetPlatformNameShort(tPlatform plat
71
72 const static char* platNames[] = 
73
74 "Win"
75 "Lin"
76 "OSX"
77 "And"
78 "iOS"
79 "All"
80 "N/A"
81 }; 
82 tStaticAssert( ((sizeof(platNames)/sizeof(*platNames)) - 2) == int(tPlatform::NumPlatforms) ); 
83 
84 if (plat == tPlatform::Invalid
85 return platNames[int(tPlatform::NumPlatforms)+1]; 
86 
87 return platNames[int(plat)]; 
88
89 
90 
91tArchitecture tGetArchitecture() 
92
93 #if defined(ARCHITECTURE_X86) 
94 return tArchitecture::x86; 
95 
96 #elif defined(ARCHITECTURE_X64) 
97 return tArchitecture::x64
98 
99 #elif defined(ARCHITECTURE_A32) 
100 return tArchitecture::A32; 
101 
102 #elif defined(ARCHITECTURE_A64) 
103 return tArchitecture::A64; 
104 
105 #else 
106 return tArchitecture::Invalid; 
107 #endif 
108
109 
110 
111const char* tGetArchitectureName(tArchitecture arch
112
113 const static char* archNames[] = 
114
115 "x86"
116 "x64"
117 "A32"
118 "A64"
119 "Invalid" 
120 }; 
121 tStaticAssert( ((sizeof(archNames)/sizeof(*archNames)) - 1) == int(tArchitecture::NumArchitectures) ); 
122 
123 if (arch == tArchitecture::Invalid
124 return archNames[int(tArchitecture::NumArchitectures)]; 
125 
126 return archNames[int(arch)]; 
127
128 
129 
130const char* tGetArchitectureNameLong(tArchitecture arch
131
132 const static char* archNames[] = 
133
134 "x86|INTEL32|x86|32bit"
135 "x64|AMD64|x86-64|64bit"
136 "A32|ARM32|ARM|32bit"
137 "A64|ARM64|AArch64|64bit"
138 "Invalid" 
139 }; 
140 tStaticAssert( ((sizeof(archNames)/sizeof(*archNames)) - 1) == int(tArchitecture::NumArchitectures) ); 
141 
142 if (arch == tArchitecture::Invalid
143 return archNames[int(tArchitecture::NumArchitectures)]; 
144 
145 return archNames[int(arch)]; 
146
147 
148 
149tConfiguration tGetConfiguration() 
150
151 #if defined(CONFIG_DEBUG) 
152 return tConfiguration::Debug; 
153 
154 #elif defined(CONFIG_DEVELOP) 
155 return tConfiguration::Develop; 
156 
157 #elif defined(CONFIG_PROFILE) 
158 return tConfiguration::Profile; 
159 
160 #elif defined(CONFIG_RELEASE) 
161 return tConfiguration::Release
162 
163 #elif defined(CONFIG_SHIP) 
164 return tConfiguration::Ship; 
165 
166 #else 
167 return tConfiguration::Invalid; 
168 #endif 
169
170 
171 
172const char* tGetConfigurationName(tConfiguration config
173
174 const static char* configNames[] = 
175
176 "Debug"
177 "Develop"
178 "Profile"
179 "Release"
180 "Ship"
181 "Invalid" 
182 }; 
183 tStaticAssert( ((sizeof(configNames)/sizeof(*configNames)) - 1) == int(tConfiguration::NumConfigurations) ); 
184 
185 if (config == tConfiguration::Invalid
186 return configNames[int(tConfiguration::NumConfigurations)]; 
187 
188 return configNames[int(config)]; 
189
190 
191 
192tEndianness tGetEndianness(tPlatform plat
193
194 switch (plat
195
196 case tPlatform::Windows
197 case tPlatform::Linux
198 case tPlatform::MacOS
199 case tPlatform::Android
200 case tPlatform::iOS
201 return tEndianness::Little
202
203 
204 return tEndianness::Invalid
205
206