Itasca C++ Interface
basedef.h
Go to the documentation of this file.
1 #pragma once
2 
13 #include "export.h"
14 #include <cmath>
15 #include <cstdint>
16 #include <wchar.h>
17 
21 #if defined(BASE_LIB) | defined(BASE2017_LIB)
22 # define BASE_EXPORT EXPORT_TAG
23 #else
24 # define BASE_EXPORT IMPORT_TAG
25 #endif
26 //#define itascaxd "Error: Need to define DIM and include dim.h"
27 
28 // Better typedefs to use in the future
29 // In modern C++ we maybe should stick to int32_t etc, but these
30 // are shorted, and familiar to those of us who have spent a long time with Qt.
31 using char16 = char16_t; // Assume UTF-16 encoding
32 using char8 = char; // Assuming UTF-8 encoding
33 using int8 = int8_t;
34 using uint8 = uint8_t;
35 using int16 = int16_t;
36 using uint16 = uint16_t;
37 using int32 = int32_t;
38 using uint32 = uint32_t;
39 #ifdef __LINUX
40 using int64 = long long int;
41 using uint64 = unsigned long long int;
42 #else
43 using int64 = int64_t;
44 using uint64 = uint64_t;
45 #endif
46 using TType = uint32;
47 
48 static constexpr int32 linuxOS = 2;
49 static constexpr int32 windowsOS = 1;
50 #ifdef __LINUX
51 # include <fenv.h>
52 # define _EM_OVERFLOW FE_OVERFLOW
53 # define _EM_INVALID FE_INVALID
54 # define _EM_UNDERFLOW FE_UNDERFLOW
55 # define _EM_ZERODIVIDE FE_DIVBYZERO
56  inline unsigned doClearFP() {
57  int ret = fetestexcept(FE_ALL_EXCEPT);
58  feclearexcept(FE_ALL_EXCEPT);
59  return (unsigned)ret;
60  }
61 # define _clearfp doClearFP
62 # define __noop() { }
63  static constexpr int32 currentOS = linuxOS;
64  template <typename T,typename U>
65  constexpr const U &osval(const T &,const U &lval) { return lval; }
66 # define OSVAL(x,y) y
67 #else
68  static constexpr int32 currentOS = windowsOS;
69  template <typename T,typename U>
70  constexpr const T &osval(const T &wval,const U &) { return wval; }
71 # define OSVAL(x,y) x
72 #endif
73 
74 
75 // Floating point utility macros and functions
76 // Used to check for when a FP exception happens, generally only in debug mode
77 #ifndef DOXYGEN
78 # ifdef _DEBUG
79 # define CHECK_FP_STATUS checkFPStatus(__FILE__,__LINE__)
80 # define CLEAR_FP_STATUS _clearfp()
81 # else
82 # define CHECK_FP_STATUS __noop()
83 # define CLEAR_FP_STATUS __noop()
84 # endif
85 // A concise version of CHECK_FP_STATUS.
86 # define FP_S CHECK_FP_STATUS
87 // A concise version of CLEAR_FP_STATUS.
88 # define FP_C CLEAR_FP_STATUS
89 
90 // To check overflow error or invalid floating point result from the \a line of the \a file
91 BASE_EXPORT const char16 *checkFPStatus(const char *file=0,uint32 line=0);
92 enum FloatingPointCheck { FloatingPointCheckOff, FloatingPointCheckWarning, FloatingPointCheckException };
93 BASE_EXPORT FloatingPointCheck floatingPointCheckStatus();
94 BASE_EXPORT void floatingPointCheckStatus(FloatingPointCheck fpc);
95 static constexpr bool isCurrentOS(int i) { return i==currentOS; }
96 #endif
97 
98 // MACRO used before new for (auto x : c) syntax in C++.
99 // This should not be used in new code, and should be replaced in old code.
100 #define FOR(x,y) for (auto x=(y).begin();x!=(y).end();++x)
101 
103 #ifdef NDEBUG
104 static constexpr bool isDebugCompile = false;
105 #else
106 static constexpr bool isDebugCompile = true;
107 #endif
108 
109 // Prevent using std::filesystem directory
110 // (on windows anyway, linux has an obnoxious problem with forward declarations).
111 #ifndef __LINUX
112 # define filesystem ERROR_USE_SHARED_FILESTORE_INSTEAD
113 #endif
114 
115 // EoF
Defines automatic generation of DLL exports and imports for each system supported.
uint32 TType
class type indicator
Definition: basedef.h:46
#define BASE_EXPORT
Definition: basedef.h:24