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