-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrecord_array.h
123 lines (110 loc) · 2.77 KB
/
record_array.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#ifndef RECORD_ARRAY_H
#define RECORD_ARRAY_H
#include <sys/types.h>
#include <string.h>
#include <string>
#include "heap_safe.h"
using namespace std;
#define EQ_STR(str1, str2) ((!(str1) || !*(str1)) && (!(str2) || !*(str2)) ? true : (!(str1) || !*(str1)) || (!(str2) || !*(str2)) ? false : !strcasecmp(str1, str2))
#define CMP_STR(str1, str2) ((!(str1) || !*(str1)) && (!(str2) || !*(str2)) ? 0 : (!(str1) || !*(str1)) ? -1 : (!(str2) || !*(str2)) ? 1 : strcasecmp(str1, str2))
struct RecordArrayField {
enum eTypeField {
tf_na,
tf_int,
tf_time,
tf_string
};
RecordArrayField() {
tf = tf_na;
i = 0;
s = NULL;
}
void free() {
if(s) {
delete [] s;
s = NULL;
}
}
void set(u_int64_t i, eTypeField tf = tf_int) {
this->tf = tf;
this->i = i;
}
void set(const char *s) {
tf = tf_string;
if(s && *s) {
this->s = new FILE_LINE(19001) char[strlen(s) + 1];
strcpy(this->s, s);
} else {
this->s = NULL;
}
this->i = 0;
}
string getJson();
bool operator == (const RecordArrayField& other) const {
return(i == other.i &&
EQ_STR(s, other.s));
}
bool operator < (const RecordArrayField& other) const {
return(i < other.i ? 1 : i > other.i ? 0 :
CMP_STR(s, other.s) < 0);
}
bool operator > (const RecordArrayField& other) const {
return(!(*this < other || *this == other));
}
eTypeField tf;
u_int64_t i;
char *s;
};
struct RecordArrayField2 : public RecordArrayField {
RecordArrayField2(RecordArrayField *other) : RecordArrayField() {
if(other) {
this->tf = other->tf;
this->i = other->i;
if(other->s && *other->s) {
this->s = new FILE_LINE(19002) char[strlen(other->s) + 1];
strcpy(this->s, other->s);
}
}
}
RecordArrayField2(const RecordArrayField2 &other) {
this->tf = other.tf;
this->i = other.i;
if(other.s && *other.s) {
this->s = new FILE_LINE(19003) char[strlen(other.s) + 1];
strcpy(this->s, other.s);
} else {
this->s = NULL;
}
}
~RecordArrayField2() {
free();
}
RecordArrayField2& operator = (const RecordArrayField2& other) {
free();
this->tf = other.tf;
this->i = other.i;
if(other.s && *other.s) {
this->s = new FILE_LINE(19004) char[strlen(other.s) + 1];
strcpy(this->s, other.s);
}
return(*this);
}
};
struct RecordArray {
RecordArray(unsigned max_fields);
void free();
string getJson();
bool operator == (const RecordArray& other) const {
return(fields[sortBy] == other.fields[sortBy] &&
fields[sortBy2] == other.fields[sortBy2]);
}
bool operator < (const RecordArray& other) const {
return(fields[sortBy] < other.fields[sortBy] ? 1 : fields[sortBy] > other.fields[sortBy] ? 0 :
fields[sortBy2] < other.fields[sortBy2]);
}
unsigned max_fields;
RecordArrayField *fields;
unsigned sortBy;
unsigned sortBy2;
};
#endif