Programming tasks to Scientific Computing I
aol.h
Go to the documentation of this file.
1 #ifndef __AOL_H
2 #define __AOL_H
3 
4 #ifdef USE_SSE
5 #include <xmmintrin.h>
6 #include <emmintrin.h>
7 #endif
8 
9 // TODO: Organize includes
10 // C standard libraries
11 #include <cmath>
12 #include <cstdio>
13 #include <cstdarg>
14 #include <cstdlib>
15 #include <cstring>
16 #include <memory>
17 
18 // STL
19 #include <complex>
20 #include <limits>
21 
22 #include <iostream>
23 #include <iomanip>
24 #include <fstream>
25 #include <sstream>
26 
27 #include <algorithm>
28 #include <list>
29 #include <map>
30 #include <queue>
31 #include <set>
32 #include <string>
33 #include <vector>
34 
35 #include <typeinfo>
36 
37 #include <chrono>
38 
39 using namespace std;
40 
41 #include <stdexcept>
42 
43 
45 #include <sys/types.h>
46 #include <sys/stat.h>
47 #include <sys/timeb.h>
48 #include <unistd.h>
49 #include <dirent.h>
50 #include <malloc.h>
51 
52 #ifdef __GNUC__
53 // With this define, GCC_VERSION is 40301 for GCC 4.3.1 and can be conveniently checked (e.g. __WARNING_ON)
54 #define GCC_VERSION ( __GNUC__ * 10000 \
55  + __GNUC_MINOR__ * 100 \
56  + __GNUC_PATCHLEVEL__ )
57 #if (__GNUC__ >= 3) && !defined(_LIBCPP_VERSION)
58 #define HAVE_STDIO_FILEBUF 1
59 #endif
60 #endif
61 
62 #ifdef HAVE_STDIO_FILEBUF
63 #include <ext/stdio_filebuf.h>
64 using namespace __gnu_cxx;
65 #endif
66 
67 #include <stdint.h>
68 
69 // Mechanism to disable and enable warnings
70 // Usage example: WARNING_OFF ( old-style-cast ) and WARNING_ON ( old-style-cast )
71 // Note: Support for diagnostic pragmas was added in GCC 4.2.0.
72 #if ( defined ( __GNUC__ ) ) && ( GCC_VERSION >= 40200 ) && !( defined ( __INTEL_COMPILER ) ) && !( defined ( __NVCC__ ) )
73 #define __PRAGMA(P) _Pragma(#P)
74 #define __WARNING_OFF(WARN) __PRAGMA(GCC diagnostic ignored #WARN)
75 #define __WARNING_ON(WARN) __PRAGMA(GCC diagnostic warning #WARN)
76 #define WARNING_OFF(WARN) __WARNING_OFF(-W ## WARN)
77 #define WARNING_ON(WARN) __WARNING_ON(-W ## WARN)
78 #else
79 #define WARNING_OFF(WARN)
80 #define WARNING_ON(WARN)
81 #endif
82 
83 
84 namespace aol {
85 
86 template <typename _DomainType, typename _RangeType = _DomainType>
87 class Op {
88 
89 public:
90  typedef _DomainType DomainType;
91  typedef _RangeType RangeType;
92 
93  Op() { }
94 
95  // Destroy polymorphic Ops correctly, important!
96  virtual ~Op () {}
97 
98  virtual void apply ( const DomainType &Arg, RangeType &Dest ) const = 0;
99 };
100 
101 
103 namespace color {
104 const string reset = "\033[0;0m";
105 const string invert = "\033[0;7m";
106 const string black = "\033[0;30m";
107 const string red = "\033[0;31m";
108 const string green = "\033[0;32m";
109 const string brown = "\033[0;33m";
110 const string blue = "\033[0;34m";
111 const string purple = "\033[0;35m";
112 const string cyan = "\033[0;36m";
113 const string light_grey = "\033[0;37m";
114 const string dark_grey = "\033[1;30m";
115 const string light_red = "\033[1;31m";
116 const string light_green = "\033[1;32m";
117 const string yellow = "\033[1;33m";
118 const string light_blue = "\033[1;34m";
119 const string pink = "\033[1;35m";
120 const string light_cyan = "\033[1;36m";
121 const string white = "\033[1;37m";
122 const string beep = "\007";
123 const string error = beep + red;
124 const string ok = green;
125 const string residuum = blue;
126 }
127 
128 // Returns minimum/maximium
129 template<class T> inline T Min ( const T a, const T b ) { return ( ( a < b ) ? a : b ); }
130 template<class T> inline T Max ( const T a, const T b ) { return ( ( a < b ) ? b : a ); }
131 // Returns Value clamped into [Min,Max].
132 template<class T> inline T Clamp ( const T Value, const T Min, const T Max ) { return ( aol::Max ( aol::Min ( Value, Max ), Min ) ); }
133 
134 template<class T> inline T Sqr (const T a) { return a * a; }
135 
137 template<class T> inline T signum ( const T x ) {
138  if (x > 0.0) return 1;
139  else if (x == 0.0) return 0;
140  else if (x < 0.0) return -1;
141  return x; // NaN
142 }
143 
145 string strprintf(const char * format, ...);
146 
147 void makeDirectory ( const char *DirectoryName, bool verbose = true );
148 bool fileExists ( std::string filename );
149 
150 
151 } // namespace aol
152 
153 #endif
154 
const string purple
Definition: aol.h:111
const string black
Definition: aol.h:106
const string white
Definition: aol.h:121
const string blue
Definition: aol.h:110
const string beep
Definition: aol.h:122
const string green
Definition: aol.h:108
_DomainType DomainType
Definition: aol.h:90
const string light_grey
Definition: aol.h:113
const string error
Definition: aol.h:123
const string dark_grey
Definition: aol.h:114
const string light_red
Definition: aol.h:115
const string invert
Definition: aol.h:105
virtual ~Op()
Definition: aol.h:96
const string light_blue
Definition: aol.h:118
T signum(const T x)
Signum function template, signum ( 0 ) = 0.
Definition: aol.h:137
const string residuum
Definition: aol.h:125
T Sqr(const T a)
Definition: aol.h:134
T Min(const T a, const T b)
Definition: aol.h:129
const string light_cyan
Definition: aol.h:120
T Clamp(const T Value, const T Min, const T Max)
Definition: aol.h:132
const string reset
Definition: aol.h:104
bool fileExists(std::string filename)
const string red
Definition: aol.h:107
const string ok
Definition: aol.h:124
_RangeType RangeType
Definition: aol.h:91
const string brown
Definition: aol.h:109
string strprintf(const char *format,...)
Give back formatted string, analogously to sprintf, but save the long way &#39;round with char arrays...
Definition: aol.cpp:5
Op()
Definition: aol.h:93
void makeDirectory(const char *DirectoryName, bool verbose)
Definition: aol.cpp:27
T Max(const T a, const T b)
Definition: aol.h:130
const string yellow
Definition: aol.h:117
Definition: aol.cpp:3
const string light_green
Definition: aol.h:116
const string pink
Definition: aol.h:119
const string cyan
Definition: aol.h:112
Definition: aol.h:87