Tissue Forge C++ 0.2.1
Interactive, particle-based physics, chemistry and biology modeling and simulation environment
Loading...
Searching...
No Matches
tf_port.h
Go to the documentation of this file.
1/*******************************************************************************
2 * This file is part of Tissue Forge.
3 * Copyright (c) 2022-2024 T.J. Sego
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 ******************************************************************************/
19
24
25#ifndef _INCLUDE_TF_PORT_H_
26#define _INCLUDE_TF_PORT_H_
27
28#include <stdint.h>
29#include <stddef.h>
30#include <assert.h>
31
32#if (!defined(__cplusplus) || defined(_TF_ASC))
33# if !defined(TF_ASC)
34# define TF_ASC
35# endif
36#else
37# if defined(TF_ASC)
38# undef TF_ASC
39# endif
40#endif
41
42#if defined(__cplusplus)
43# include <cstdio>
44# include <cstring>
45#else
46# include <stdio.h>
47# include <string.h>
48#endif
49
50#include <tf_config.h>
51
52// select support for old C++ stuff
53#if (!defined(TF_ASC) && !defined(__GNUC__))
54 namespace std {
55 template<typename A, typename R>
56 struct unary_function {
57 typedef A argument_type;
58 typedef R result_type;
59 };
60 };
61#endif // (!defined(TF_ASC) && !defined(__GNUC__))
62
63
67#if defined(TF_FPTYPE_SINGLE)
68 typedef float tfFloatP_t;
69#else
70 typedef double tfFloatP_t;
71#endif
72
73#if !defined(TF_ASC)
74 namespace TissueForge {
75 typedef tfFloatP_t FloatP_t;
76 }
77#endif
78
79
80#if !defined(__cplusplus)
81 typedef uint8_t bool;
82# define true 1
83# define false 0
84#endif
85
86
87// Ensure sync with mdcore precision
88#if defined(TF_FPTYPE_SINGLE)
89# if !defined(MDCORE_SINGLE)
90# define MDCORE_SINGLE
91# endif
92# if defined(MDCORE_DOUBLE)
93# undef MDCORE_DOUBLE
94# endif
95# if !defined(FPTYPE_SINGLE)
96# define FPTYPE_SINGLE
97# endif
98# if defined(FPTYPE_DOUBLE)
99# undef FPTYPE_DOUBLE
100# endif
101#else
102# if defined(MDCORE_SINGLE)
103# undef MDCORE_SINGLE
104# endif
105# if !defined(MDCORE_DOUBLE)
106# define MDCORE_DOUBLE
107# endif
108# if defined(FPTYPE_SINGLE)
109# undef FPTYPE_SINGLE
110# endif
111# if !defined(FPTYPE_DOUBLE)
112# define FPTYPE_DOUBLE
113# endif
114#endif
115
116
117#ifndef __has_attribute // Optional of course.
118 #define __has_attribute(x) 0 // Compatibility with non-clang compilers.
119#endif
120
121
122/* Get the inlining right. */
123#ifndef INLINE
124# if __GNUC__ && !__GNUC_STDC_INLINE__
125# define TF_INLINE extern inline
126# else
127# define TF_INLINE inline
128# endif
129#endif
130
131#if __has_attribute(always_inline)
132#define TF_ALWAYS_INLINE __attribute__((always_inline)) TF_INLINE
133#else
134#define TF_ALWAYS_INLINE TF_INLINE
135#endif
136
137#if defined(__CUDACC__)
138 #define TF_ALIGNED(RTYPE, VAL) RTYPE __align__(VAL)
139#elif __has_attribute(aligned)
140 #define TF_ALIGNED(RTYPE, VAL) RTYPE __attribute__((aligned(VAL)))
141#elif defined(_MSC_VER)
142 #define TF_ALIGNED(RTYPE, VAL) __declspec(align(VAL)) RTYPE
143#else
144 #define TF_ALIGNED(RTYPE, VAL) RTYPE
145#endif
146
147#if __has_attribute(flatten)
148# define TF_FLATTEN __attribute__((flatten))
149#else
150# define TF_FLATTEN [[msvc::flatten]]
151#endif
152
153/* Declarations for symbol visibility.
154
155 CAPI_FUNC(TYPE): Declares a public Tissue Forge C API function and return type
156 CPPAPI_FUNC(TYPE): Declares a public Tissue Forge C++ API function and return type
157 CAPI_DATA(TYPE): Declares public Tissue Forge data and its type
158 CAPI_STRUCT(TYPE): Declares opaque public Tissue Forge data types
159
160 As a number of platforms support/require "__declspec(dllimport/dllexport)",
161 we support a HAVE_DECLSPEC_DLL macro to save duplication.
162*/
163
164/*
165 All windows ports, except cygwin, are handled in PC/pyconfig.h.
166
167 Cygwin is the only other autoconf platform requiring special
168 linkage handling and it uses __declspec().
169*/
170
171#if defined(__CYGWIN__)
172# define HAVE_DECLSPEC_DLL
173#endif
174
175/* Only get special linkage if built as shared */
176
177#if defined(HAVE_DECLSPEC_DLL)
178 /* Building an extension module, or an embedded situation */
179 /* public Tissue Forge functions and data are imported */
180 /* Under Cygwin, auto-import functions to prevent compilation */
181 /* failures similar to those described at the bottom of 4.1: */
182 /* http://docs.python.org/extending/windows.html#a-cookbook-approach */
183# define CAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE
184#endif // HAVE_DECLSPEC
185
186/* If no external linkage macros defined by now, create defaults */
187
188#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
189# if defined(C_BUILDING_DLL)
190# define CAPI_EXPORT __declspec(dllexport)
191# else
192# define CAPI_EXPORT __declspec(dllimport)
193# endif
194#else
195# define CAPI_EXPORT __attribute__((visibility("default")))
196#endif
197
198#if !defined(CAPI_FUNC)
199# if defined(__cplusplus)
200# define CAPI_FUNC(RTYPE) extern "C" CAPI_EXPORT RTYPE
201# else
202# define CAPI_FUNC(RTYPE) extern CAPI_EXPORT RTYPE
203# endif
204#endif
205
206#ifndef CPPAPI_FUNC
207# if defined(__cplusplus)
208# define CPPAPI_FUNC(...) extern CAPI_EXPORT __VA_ARGS__
209# else
210# define CPPAPI_FUNC(RTYPE) RTYPE
211# endif
212#endif
213
214#ifndef CAPI_DATA
215# if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
216# define CAPI_DATA(RTYPE) extern "C" CAPI_EXPORT RTYPE
217# else
218# define CAPI_DATA(RTYPE) extern CAPI_EXPORT RTYPE
219# endif
220#endif
221
223#ifndef CAPI_STRUCT
224# if defined(__cplusplus)
225# define CAPI_STRUCT(...) struct __VA_ARGS__
226# else
227# define CAPI_STRUCT(TYPE) typedef struct TYPE TYPE
228# endif
229#endif
230
231
232#if !(defined(_WIN32) || defined(__WIN32__) || defined(WIN32))
233
234
255typedef int32_t HRESULT;
256
257#define S_OK 0x00000000 // Operation successful
258#define E_ABORT 0x80004004 // Operation aborted
259#define E_ACCESSDENIED 0x80070005 // General access denied error
260#define E_FAIL 0x80004005 // Unspecified failure
261#define E_HANDLE 0x80070006 // Handle that is not valid
262#define E_INVALIDARG 0x80070057 // One or more arguments are not valid
263#define E_NOINTERFACE 0x80004002 // No such interface supported
264#define E_NOTIMPL 0x80004001 // Not implemented
265#define E_OUTOFMEMORY 0x8007000E // Failed to allocate necessary memory
266#define E_POINTER 0x80004003 // Pointer that is not valid
267#define E_UNEXPECTED 0x8000FFFF // Unexpected failure
268
269
270
271
272
280#define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0)
281
282#define FAILED(hr) (((HRESULT)(hr)) < 0)
283
296#define MAKE_HRESULT(sev,fac,code) \
297 static_cast<HRESULT>((static_cast<uint32_t>(sev)<<31) | (static_cast<uint32_t>(fac)<<16) | (static_cast<uint32_t>(code)))
298
305#define HRESULT_CODE(hr) ((hr) & 0xFFFF)
306
313#define HRESULT_FACILITY(hr) (((hr) >> 16) & 0x1fff)
314
321#define HRESULT_SEVERITY(hr) (((hr) >> 31) & 0x1)
322
326#define TF_FUNCTION __PRETTY_FUNCTION__
327
328#else
329// Windows
330#undef min
331#undef max
332#undef inline
333#include <Windows.h>
334#undef min
335#undef max
336#undef inline
337
338#define TF_FUNCTION __func__
339#endif
340
341#if !defined(C_UNUSED)
342# define C_UNUSED(x) (void)(x);
343#endif
344
345
346#if defined(_WIN32)
347# define _USE_MATH_DEFINES
348# define bzero(b,len) memset((b), '\0', (len))
349#else
350# define algined_free(x) free(x)
351#endif
352
357
358#if !defined(NDEBUG)
359# define VERIFY(hr) assert(SUCCEEDED(hr))
360#else
361# define VERIFY(hr) hr
362#endif
363
367#define FACULTY_MESH 10
368#define FACULTY_MESHOPERATION 11
369
370#define CE_ABORT ((HRESULT)0x80004004)
371#define CE_INVALIDARG ((HRESULT)0x80070057)
372#define CE_NOTIMPL ((HRESULT)0x80004001)
373#define CE_OUTOFMEMORY ((HRESULT)0x8007000E)
374#define CE_POINTER ((HRESULT)0x80004003)
375#define CE_UNEXPECTED ((HRESULT)0x8000FFFF)
376#define CE_FAIL ((HRESULT)0x80004005)
377#define CE_ARGUMENT ((HRESULT)0x80070057)
378#define CE_ARGUMENTOUTOFRANGE ((HRESULT)0x80131502)
379#define CE_TYPEMISMATCH ((HRESULT)0x80028ca0)
380
381
382
383
384
385#define CE_HANDLE ((HRESULT)0x80070006)
386
387#define CE_NOINTERFACE ((HRESULT)0x80004002)
388
389
390#define CE_CLOSED ((HRESULT)0x80000013)
391#define CE_BOUNDS ((HRESULT)0x8000000B)
392#define CE_CHANGED_STATE ((HRESULT)0x8000000C)
393
394#define CE_CLASSNOTREG ((HRESULT)0x80040154)
395#define CE_AMBIGUOUSMATCH ((HRESULT)0x8000211D)
396#define CE_APPDOMAINUNLOADED ((HRESULT)0x80131014)
397#define CE_APPLICATION ((HRESULT)0x80131600)
398
399#define CE_ARITHMETIC ((HRESULT)0x80070216)
400#define CE_ARRAYTYPEMISMATCH ((HRESULT)0x80131503)
401#define CE_BADIMAGEFORMAT ((HRESULT)0x8007000B)
402#define CE_TYPEUNLOADED ((HRESULT)0x80131013)
403#define CE_CANNOTUNLOADAPPDOMAIN ((HRESULT)0x80131015)
404#define CE_COMEMULATE ((HRESULT)0x80131535)
405#define CE_CONTEXTMARSHAL ((HRESULT)0x80131504)
406#define CE_DATAMISALIGNED ((HRESULT)0x80131541)
407#define CE_TIMEOUT ((HRESULT)0x80131505)
408#define CE_CUSTOMATTRIBUTEFORMAT ((HRESULT)0x80131605)
409#define CE_DIVIDEBYZERO ((HRESULT)0x80020012)
410#define CE_DUPLICATEWAITOBJECT ((HRESULT)0x80131529)
411#define CE_EXCEPTION ((HRESULT)0x80131500)
412#define CE_EXECUTIONENGINE ((HRESULT)0x80131506)
413#define CE_FIELDACCESS ((HRESULT)0x80131507)
414#define CE_FORMAT ((HRESULT)0x80131537)
415#define CE_INDEXOUTOFRANGE ((HRESULT)0x80131508)
416#define CE_INSUFFICIENTMEMORY ((HRESULT)0x8013153D)
417#define CE_INSUFFICIENTEXECUTIONSTACK ((HRESULT)0x80131578)
418#define CE_INVALIDCAST ((HRESULT)0x80004002)
419#define CE_INVALIDCOMOBJECT ((HRESULT)0x80131527)
420#define CE_INVALIDFILTERCRITERIA ((HRESULT)0x80131601)
421#define CE_INVALIDOLEVARIANTTYPE ((HRESULT)0x80131531)
422#define CE_INVALIDOPERATION ((HRESULT)0x80131509)
423#define CE_INVALIDPROGRAM ((HRESULT)0x8013153A)
424#define CE_KEYNOTFOUND ((HRESULT)0x80131577)
425#define CE_MARSHALDIRECTIVE ((HRESULT)0x80131535)
426#define CE_MEMBERACCESS ((HRESULT)0x8013151A)
427#define CE_METHODACCESS ((HRESULT)0x80131510)
428#define CE_MISSINGFIELD ((HRESULT)0x80131511)
429#define CE_MISSINGMANIFESTRESOURCE ((HRESULT)0x80131532)
430#define CE_MISSINGMEMBER ((HRESULT)0x80131512)
431#define CE_MISSINGMETHOD ((HRESULT)0x80131513)
432#define CE_MISSINGSATELLITEASSEMBLY ((HRESULT)0x80131536)
433#define CE_MULTICASTNOTSUPPORTED ((HRESULT)0x80131514)
434#define CE_NOTFINITENUMBER ((HRESULT)0x80131528)
435#define CE_PLATFORMNOTSUPPORTED ((HRESULT)0x80131539)
436#define CE_NOTSUPPORTED ((HRESULT)0x80131515)
437#define CE_NULLREFERENCE ((HRESULT)0x80004003)
438#define CE_OBJECTDISPOSED ((HRESULT)0x80131622)
439#define CE_OPERATIONCANCELED ((HRESULT)0x8013153B)
440#define CE_OVERFLOW ((HRESULT)0x80131516)
441#define CE_RANK ((HRESULT)0x80131517)
442#define CE_REFLECTIONTYPELOAD ((HRESULT)0x80131602)
443#define CE_RUNTIMEWRAPPED ((HRESULT)0x8013153E)
444#define CE_SAFEARRAYRANKMISMATCH ((HRESULT)0x80131538)
445#define CE_SAFEARRAYTYPEMISMATCH ((HRESULT)0x80131533)
446#define CE_SAFEHANDLEMISSINGATTRIBUTE ((HRESULT)0x80131623)
447#define CE_SECURITY ((HRESULT)0x8013150A)
448#define CE_SERIALIZATION ((HRESULT)0x8013150C)
449#define CE_SEMAPHOREFULL ((HRESULT)0x8013152B)
450#define CE_WAITHANDLECANNOTBEOPENED ((HRESULT)0x8013152C)
451#define CE_ABANDONEDMUTEX ((HRESULT)0x8013152D)
452#define CE_STACKOVERFLOW ((HRESULT)0x800703E9)
453#define CE_SYNCHRONIZATIONLOCK ((HRESULT)0x80131518)
454#define CE_SYSTEM ((HRESULT)0x80131501)
455#define CE_TARGET ((HRESULT)0x80131603)
456#define CE_TARGETINVOCATION ((HRESULT)0x80131604)
457#define CE_TARGETPARAMCOUNT ((HRESULT)0x8002000e)
458#define CE_THREADABORTED ((HRESULT)0x80131530)
459#define CE_THREADINTERRUPTED ((HRESULT)0x80131519)
460#define CE_THREADSTATE ((HRESULT)0x80131520)
461#define CE_THREADSTOP ((HRESULT)0x80131521)
462#define CE_THREADSTART ((HRESULT)0x80131525)
463#define CE_TYPEACCESS ((HRESULT)0x80131543)
464#define CE_TYPEINITIALIZATION ((HRESULT)0x80131534)
465#define CE_TYPELOAD ((HRESULT)0x80131522)
466#define CE_ENTRYPOINTNOTFOUND ((HRESULT)0x80131523)
467#define CE_DLLNOTFOUND ((HRESULT)0x80131524)
468#define CE_UNAUTHORIZEDACCESS ((HRESULT)0x80070005)
469#define CE_UNSUPPORTEDFORMAT ((HRESULT)0x80131523)
470#define CE_VERIFICATION ((HRESULT)0x8013150D)
471#define CE_HOSTPROTECTION ((HRESULT)0x80131640)
472
473
474#define CERR_EXCEP CE_FAIL
475#define CERR_ARITHMETIC CE_ARITHMETIC
476#define CERR_TYPE CE_TYPEMISMATCH
477#define CERR_INVALIDARG CE_INVALIDARG
478#define CERR_FAIL CE_FAIL
479
480#endif // _INCLUDE_TF_PORT_H_
Include Python header, disable linking to pythonX_d.lib on Windows in debug mode.
Definition tfAngleConfig.h:26
int32_t HRESULT
Definition tf_port.h:255
double tfFloatP_t
Definition tf_port.h:70