RAPIDO
Repeatable Analysis Programming for Interpretability, Durability, and Organization
Loading...
Searching...
No Matches
utilities.h
1#ifndef UTILITIES_H
2#define UTILITIES_H
3
4#include <fstream>
5#include <iostream>
6#include <functional>
7#include <vector>
8#include <string>
9#include <map>
10#include <cmath>
11
12namespace Utilities
13{
21 {
22 private:
24 int n_values;
26 float summed_values;
28 float max_value;
30 float min_value;
32 float new_M;
34 float old_M;
36 float new_S;
38 float old_S;
39 public:
50 void push(float value);
55 int size();
60 float sum();
65 float max();
70 float min();
75 float mean();
80 float variance();
85 float stddev();
86 };
87
91 class CSVFile
92 {
93 public:
95 std::ofstream& ofstream;
97 std::string name;
99 std::vector<std::string> headers;
101 std::vector<std::string> buffer;
102
110 CSVFile(std::ofstream& new_ofstream, std::string new_name,
111 std::vector<std::string> new_headers);
116 virtual ~CSVFile();
122 CSVFile clone(std::string new_name);
129 template<typename Type>
130 void pushCol(Type value);
136 void writeRow(bool append = true);
137 };
138 typedef std::vector<CSVFile> CSVFiles;
139
144 {
145 public:
150 virtual ~Dynamic();
151 };
152
157 template<typename Type>
158 class Variable : public Dynamic
159 {
160 protected:
162 Type value;
165 public:
176 Variable(Type new_reset_value);
181 virtual ~Variable();
186 Type getValue();
197 void setValue(Type new_value);
204 void setResetValue(Type new_reset_value);
210 };
211
216 {
217 protected:
219 std::map<std::string, Dynamic*> variables;
221 std::map<std::string, std::function<void()>> resetters;
228 template<typename Type>
229 Variable<Type>* getVar(std::string name);
230 public:
240 virtual ~Variables();
247 template<typename Type>
248 void newVar(std::string new_name);
256 template<typename Type>
257 void newVar(std::string new_name, Type new_reset_value);
264 template<typename Type>
265 Type getVal(std::string name);
272 template<typename Type>
273 Type& getRef(std::string name);
281 template<typename Type>
282 void setVal(std::string name, Type new_value);
289 template<typename Type>
290 void resetVal(std::string name);
301 void resetVars();
302 };
303}
304
305#include "utilities.icc"
306
307#endif
Definition utilities.h:92
std::vector< std::string > headers
Definition utilities.h:99
std::string name
Definition utilities.h:97
CSVFile(std::ofstream &new_ofstream, std::string new_name, std::vector< std::string > new_headers)
std::ofstream & ofstream
Definition utilities.h:95
void writeRow(bool append=true)
CSVFile clone(std::string new_name)
std::vector< std::string > buffer
Definition utilities.h:101
void pushCol(Type value)
Definition utilities.h:144
Definition utilities.h:21
void push(float value)
Definition utilities.h:159
void setResetValue(Type new_reset_value)
Variable(Type new_reset_value)
Type value
Definition utilities.h:162
Type reset_value
Definition utilities.h:164
void setValue(Type new_value)
Definition utilities.h:216
void setVal(std::string name, Type new_value)
void resetVal(std::string name)
Type getVal(std::string name)
Type & getRef(std::string name)
void newVar(std::string new_name)
Variable< Type > * getVar(std::string name)
std::map< std::string, std::function< void()> > resetters
Definition utilities.h:221
std::map< std::string, Dynamic * > variables
Definition utilities.h:219
void newVar(std::string new_name, Type new_reset_value)