TTK
Loading...
Searching...
No Matches
Os.h
Go to the documentation of this file.
1
7
8#pragma once
9
10#ifdef _WIN32
11#ifndef _USE_MATH_DEFINES
12#define _USE_MATH_DEFINES
13#endif
14
15#define drand48() (double(rand()) / RAND_MAX)
16// #define isnan(x) _isnan(x)
17#define srand48(seed) srand(seed)
18#endif // _WIN32
19
20#include <cfloat>
21#include <climits>
22#include <cmath>
23#include <cstdlib>
24#include <iomanip>
25#include <string>
26#include <vector>
27
28//#define SINGLE_PRECISION
29
30#ifdef SINGLE_PRECISION
31#define REAL_TYPE float
32#define REAL_TYPE_STRING "float"
33#define REAL_MAX FLT_MAX
34#else
35#define REAL_TYPE double
36#define REAL_TYPE_STRING "double"
37#define REAL_MAX DBL_MAX
38#endif
39
40#define DBL_SIGNIFICANT_DIGITS 14
41#define FLT_SIGNIFICANT_DIGITS 7
42
43#ifdef SINGLE_PRECISION
44#define REAL_SIGNIFICANT_DIGITS FLT_SIGNIFICANT_DIGITS
45#else
46#define REAL_SIGNIFICANT_DIGITS DBL_SIGNIFICANT_DIGITS
47#endif
48
49#ifndef __APPLE__
50#define M_PI 3.14159265358979323846
51#endif
52
53namespace ttk {
54
55#ifdef SINGLE_PRECISION
56 using real = float;
57#else
58 using real = double;
59#endif
60
61 class OsCall {
62 public:
63 static int getCurrentDirectory(std::string &directoryPath);
64
65 static float getMemoryInstantUsage();
66
67 static float getTotalMemoryUsage();
68
69 static int getNumberOfCores();
70
71 static std::vector<std::string>
72 listFilesInDirectory(const std::string &directoryName,
73 const std::string &extension);
74
75 static int mkDir(const std::string &directoryName);
76
77 static int nearbyint(const double &x);
78
79 static int rmDir(const std::string &directoryName);
80
81 static int rmFile(const std::string &fileName);
82
83 int static roundToNearestInt(const double &val);
84 };
85
86 inline int OsCall::roundToNearestInt(const double &val) {
87 const double upperBound = ceil(val);
88 const double lowerBound = floor(val);
89
90 if(upperBound - val <= val - lowerBound) {
91 return (int)upperBound;
92 } else {
93 return (int)lowerBound;
94 }
95 }
96
97 class Memory {
98
99 public:
102 }
103
104 inline float getInitialMemoryUsage() {
105 return initialMemory_;
106 }
107
108 inline float getInstantUsage() {
110 }
111
112 inline float getElapsedUsage() {
114 }
115
116 inline float getTotalUsage() {
118 }
119
120 protected:
122 };
123
124} // namespace ttk
Definition: Os.h:97
float getInitialMemoryUsage()
Definition: Os.h:104
float getElapsedUsage()
Definition: Os.h:112
float getTotalUsage()
Definition: Os.h:116
float getInstantUsage()
Definition: Os.h:108
float initialMemory_
Definition: Os.h:121
Memory()
Definition: Os.h:100
Os-specifics.
Definition: Os.h:61
static float getTotalMemoryUsage()
Definition: Os.cpp:65
static int getCurrentDirectory(std::string &directoryPath)
Definition: Os.cpp:34
static std::vector< std::string > listFilesInDirectory(const std::string &directoryName, const std::string &extension)
Definition: Os.cpp:95
static float getMemoryInstantUsage()
Definition: Os.cpp:47
static int nearbyint(const double &x)
Definition: Os.cpp:216
static int rmDir(const std::string &directoryName)
Definition: Os.cpp:226
static int roundToNearestInt(const double &val)
Definition: Os.h:86
static int mkDir(const std::string &directoryName)
Definition: Os.cpp:207
static int getNumberOfCores()
Definition: Os.cpp:87
static int rmFile(const std::string &fileName)
Definition: Os.cpp:230
The Topology ToolKit.
double real
Definition: Os.h:58