OpenStructure
base.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2020 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 #ifndef OST_BASE_HH
20 #define OST_BASE_HH
21 
22 #include <cmath>
23 #include <math.h>
24 #include <complex>
25 #include <ost/config.hh>
26 #include <ost/dllexport.hh>
27 
28 #ifndef uint
29 typedef unsigned int uint;
30 #endif
31 
32 #ifndef uchar
33  typedef unsigned char uchar;
34 #endif
35 
36 #ifndef ushort
37  typedef unsigned short int ushort;
38 #endif
39 
40 
41 #if OST_DOUBLE_PRECISION
42  typedef double Real;
43 #else
44  typedef float Real;
45 #endif
46 
47 #ifdef Complex
48  // undef Complex from xorg X.h to avoid clash with our definition
49  #undef Complex
50 #endif
51 typedef std::complex<Real> Complex;
52 typedef unsigned short Word;
53 
54 typedef std::string String;
55 
56 // NOTE: Before OST 1.8, we used to have round and rint functions defined here
57 // -> round and rint are available for any compiler since many years now
58 // -> Tested for GCC 4.1.2 - 9.0.0, clang 3.3.0 - 8.0.0, MSVC 2015 - 2017 using
59 // godbolt.org. In all cases: call with float is not casted to double, but
60 // kept as float which is desired behaviour for good performance.
61 
62 // NOTE: OST has not been tested in MSVC for a very long time!
63 #if _MSC_VER
64 #pragma warning(disable:4251)
65 #pragma warning(disable:4275)
66 #pragma warning(disable:4244)
67 #pragma warning(disable:4231)
68 #pragma warning(disable:4305)
69 #pragma warning(disable:4351) // turn off "new behavior ... will be default initialized" warning
70 
71 #ifndef log2_function
72 #define log2_function
73 #ifndef log2
74  //C99 defines log2, C90 does not and MSVC is C90:(
75  // Calculates log2 of number.
76 inline double log2( double n )
77  {
78  // log(n)/log(2) is log2.
79  return log( double(n) ) / log( 2.0 );
80  }
81 #endif
82 #endif
83 
84 # ifdef FindAtom
85 # undef FindAtom
86 # endif
87 # ifdef AddAtom
88 # undef AddAtom
89 # endif
90 
91 #endif
92 
93 
94 #endif
unsigned short int ushort
Definition: base.hh:37
unsigned char uchar
Definition: base.hh:33
unsigned int uint
Definition: base.hh:29
float Real
Definition: base.hh:44
std::complex< Real > Complex
Definition: base.hh:51
std::string String
Definition: base.hh:54
unsigned short Word
Definition: base.hh:52