-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.h
More file actions
63 lines (51 loc) · 1.5 KB
/
Copy pathutils.h
File metadata and controls
63 lines (51 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef UTILS
#define UTILS
#include <iostream>
#include <typeinfo>
#include <cxxabi.h>
#include <limits>
//#define type2name(o) std::string(typeid(o).name())
//#define type2name(o) std::string(abi::__cxa_demangle(typeid(o).name(),nullptr,nullptr,nullptr))
using longInt = signed long long int;
namespace std {
static inline void strReplaceAll(string &str, const string& from, const string& to) {
size_t start_pos = 0;
while((start_pos = str.find(from, start_pos)) != std::string::npos) {
str.replace(start_pos, from.length(), to);
start_pos += to.length();
}
}
template <class T>
static inline const string type2name(T o) {
string s = string(abi::__cxa_demangle(typeid(o).name(),nullptr,nullptr,nullptr));
strReplaceAll(s, string("std::"), string("")); // Remove std:: from output
strReplaceAll(s, string("Cryptography::"), string("")); // Remove Cryptography:: from output
return s;
}
}
namespace alloc {
/**
* Overloaded methods to allocate an array of T of size x, y, z.
*/
template <class T>
static T* allocVar() {
return new T();
}
template <class T>
static T* allocArray(size_t x) {
return new T[x]();
}
template <class T>
static T** allocArray(size_t x, size_t y) {
T **arr = new T*[x];
for(size_t i = 0; i < x; i++) arr[i] = alloc::allocArray<T>(y);
return arr;
}
template <class T>
static T*** allocArray(size_t x, size_t y, size_t z) {
T ***arr = new T**[x];
for(size_t i = 0; i < x; i++) arr[i] = alloc::allocArray<T>(y, z);
return arr;
}
}
#endif // UTILS