-
Notifications
You must be signed in to change notification settings - Fork 8
/
generic_Transaction.h
98 lines (84 loc) · 2.38 KB
/
generic_Transaction.h
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <vector>
#include <iostream> //cout
#include <cstring> //strtok
#include <string>
#include <cstdio> //stdin
#include <cstdlib> //strtoul
#include <charconv> // from_char, to_char
#pragma warning(disable : 4996) //pour Visual C++ (std::strtok)
using namespace std;
template <class T> // T est le type des items (int, long, short);
class Transaction { // itemset
public:
string type(); //ex: (String) "add", "del"
string crc(); //ex: (String) "1ade980c" le crc de la transaction
size_t count(); //nombre d'item dans la trx
void load(char *, const char *, const short); //pour charger une autre trx
void clean();
std::vector<T>* data();
T next();
Transaction(void);
Transaction(char *, const char *, const short); //pointer vers le premier element, 1=avec crc/0=pas de crc a l'index [1]
~Transaction();
private:
std::vector<T> __data;
size_t __index; //index de l'élément pointé pour le next();
string __type;
string __crc;
};
template <class T>
string Transaction<T>::type() {
return __type;
};
template <class T>
string Transaction<T>::crc() {
return __crc;
};
template <class T>
size_t Transaction<T>::count() {
return __data.size();
};
template <class T>
std::vector<T>* Transaction<T>::data() {
return &__data;
};
template <class T>
T Transaction<T>::next() {
return __data.at(__index++); //bound check
};
template <class T>
void Transaction<T>::clean(void) {
__index = 0;
__data.clear();
};
template <class T>
void Transaction<T>::load(char *_s, const char *_delims, const short _withcrc) {
T v = 0;
T oldV = 0;
clean();
char *pch = _s;// std::strtok(_s, _delims);
//__type = std::string(pch); pch = strtok(0, _delims);
//if (_withcrc == 1) { __crc = std::string(pch); pch = strtok(0, _delims); }
while (pch != 0) {
std::from_chars(pch, pch + strlen(pch), v);
//Stupid hack to avoid blank spaces at end of lines
if (v != oldV) {
__data.insert(__data.end(), v);
}
pch = strtok(0, _delims);
oldV = v;
}
};
template <class T>
Transaction<T>::Transaction() {
clean();
}
template <class T>
Transaction<T>::Transaction(char *_s, const char *_delims, const short _crc) {
clean();
load(_s, _delims, _crc);
};
template <class T>
Transaction<T>::~Transaction() {
__data.clear();
};