ENERGY MONITOR 0.2
Loading...
Searching...
No Matches
core.h
Go to the documentation of this file.
1#pragma once
2
3
9#include <vector>
10
11
12
13#include "data_IO/data_IO.h"
14#include "data_IO/pdfWrapper.h"
15#include <stdlib.h>
16#include <type_traits>
17#include <string>
18#include "settings/setting.h"
19
20
21#define toRad(_deg)((_deg/180) * M_PI)
22#define toDeg(_rad)((_rad/M_PI) * 180)
23
24
25#define positive 1
26#define zero 0
27#define negative -1
28#define sign(c)((c>0) ? positive : ((c<0) ? negative : zero))
29
30
31using namespace std;
32
33extern _settings settings;
34
35
36
37template <typename t>
39
40static inline t to_millis(t v)
41 {
42 if(is_arithmetic<t>::value){
43 return v/1e-3;
44 }
45 else if(is_same_v<t,string>)
46 {
47 return std::to_string(stod(v)/1e-3)+"10^-3";
48 }
49 }
50
51
52static inline t to_micros(t v)
53 {
54 if(is_arithmetic<t>::value){
55 return v/10e-6;
56 }
57 else if(is_same_v<t,string>)
58 {
59 return std::to_string(stod(v)/1e-6)+"10^-6";
60 }
61 }
62
63
64static inline t to_nanos(t v)
65 {
66 if(is_arithmetic<t>::value){
67 return v/10e-9;
68 }
69 else if(is_same_v<t,string>)
70 {
71 return std::to_string(stod(v)/1e-9)+"10^-9";
72 }
73 }
74
75
76static inline t to_kilos(t v)
77 {
78 if(is_arithmetic<t>::value){
79 return v/10e3;
80 }
81 else if(is_same_v<t,string>)
82 {
83 return std::to_string(stod(v)/1e3)+"10^3";
84 }
85 }
86
87
88static inline t to_megas(t v)
89 {
90 if(is_arithmetic<t>::value){
91 return v/10e6;
92 }
93 else if(is_same_v<t,string>)
94 {
95 return std::to_string(stod(v)/1e6)+"10^6";
96 }
97 }
98
99
100static inline t to_gigas(t v)
101 {
102 if(is_arithmetic<t>::value){
103 return v/1e9;
104 }
105 else if(is_same_v<t,string>)
106 {
107 return std::to_string(stod(v)/1e9)+"10^9";
108 }
109 }
110};
111
112
113#define _USE_MATH_DEFINES
114#include <math.h>
115#include <ctime>
116#include <cmath>
117//--------------HELPER METHODS---------------------//
118#define toRad(_deg)((_deg/180) * M_PI)
119#define toDeg(_rad)((_rad/M_PI) * 180)
120
121inline double constrain(double _rad){
122 _rad = fmod(_rad + M_PI , 2 * M_PI);
123 if(_rad < 0)_rad += 2*M_PI;
124 return _rad - M_PI;
125}
126
127
128inline bool isInDomain(double start,double end,double current){
129 if((start <= current)&&(current <= end)){
130 return true;
131 }else{
132 return false;
133 }
134}
135
136inline bool isNear(double v1, double v2, double acc){
137 if( (v1 >= v2*(1 - acc)) && (v1 <= v2*(1 + acc)) ){
138 return true;
139 }else{
140 return false;
141 }
142}
143
144template <typename t>
145inline t roundTo(t num,t n){
146 return round(num/n)*n;
147}
148
149
150
151inline float getCurrentTime(){
152 return float(clock()/CLOCKS_PER_SEC);
153}
154inline void replace_char(char c){
155 cout << "\b" << c << endl;
156}
157
158
160 private:
161
162 float lastPerc = 0;
163 float startTime;
164 bool update_str = false;
165 int char_place_idx = 0;
166
167 public:
168
169 void update_state(float perc,char c,std::string str);
170 void load_string(std::string str);
173};
174
175inline std::string bool_to_string(int v){
176 if(v != 0){
177 return "true";
178 }else{
179 return "false";
180 }
181}
182
183template <typename DATA>
184class mode{
185 private:
186 struct elements{
187 DATA value;
188 unsigned int count;
189 };
190 std::vector<elements> elements_found;
191 public:
192 mode(std::vector<DATA> data_to_mode){
193 //FUNCTION DEFINITION
194 }
195
196};
Definition core.h:184
mode(std::vector< DATA > data_to_mode)
Definition core.h:192
double constrain(double _rad)
Definition core.h:121
bool isNear(double v1, double v2, double acc)
Definition core.h:136
t roundTo(t num, t n)
Definition core.h:145
void replace_char(char c)
Definition core.h:154
std::string bool_to_string(int v)
Definition core.h:175
float getCurrentTime()
Definition core.h:151
_settings settings
Definition core.cpp:3
bool isInDomain(double start, double end, double current)
Definition core.h:128
contains a basic flexible and extensible interface for file imports and exports operations other stru...
THIS FILE WAS PROVIDED BY OMAR_MAGDY_GHAZY EPE2024 As an abstraction for PDFHummus/PDFWriter lib no w...
implements a simple interface for permanent settings across different parts across the program using ...
static t to_micros(t v)
Definition core.h:52
static t to_megas(t v)
Definition core.h:88
static t to_millis(t v)
Definition core.h:40
static t to_kilos(t v)
Definition core.h:76
static t to_nanos(t v)
Definition core.h:64
static t to_gigas(t v)
Definition core.h:100
void load_string(std::string str)
float time_ellapsed()
void update_state(float perc, char c, std::string str)