|
1
2
3
|
#include "segrules.hpp"
#include "../fsa/fsa.hpp"
|
|
4
|
#include "../fsa/const.hpp"
|
|
5
|
#include "../deserializationUtils.hpp"
|
|
6
|
|
|
7
8
|
using namespace std;
|
|
9
|
static inline void skipSeparatorsList(const unsigned char*& ptr) {
|
|
10
|
uint16_t listSize = readInt16(ptr);
|
|
11
12
13
|
ptr += 4 * listSize;
}
|
|
14
|
static inline const unsigned char* getSeparatorsListPtr(const unsigned char* ptr) {
|
|
15
16
|
const unsigned char* additionalDataPtr = ptr
+ FSA_DATA_OFFSET
|
|
17
18
|
+ readInt32Const(ptr + FSA_DATA_SIZE_OFFSET);
const unsigned char* res = additionalDataPtr + readInt32Const(additionalDataPtr) + 4;
|
|
19
20
21
22
23
24
|
return res;
}
static inline const unsigned char* getFSAsMapPtr(const unsigned char* ptr) {
const unsigned char* res = getSeparatorsListPtr(ptr);
skipSeparatorsList(res);
|
|
25
|
return res;
|
|
26
27
28
29
|
}
static inline SegrulesOptions deserializeOptions(const unsigned char*& ptr) {
SegrulesOptions res;
|
|
30
31
32
|
unsigned char optsNum = *ptr;
ptr++;
for (unsigned char i = 0; i < optsNum; i++) {
|
|
33
34
|
string key = readString(ptr);
res[key] = readString(ptr);
|
|
35
|
}
|
|
36
37
38
|
return res;
}
|
|
39
|
static inline SegrulesFSA* deserializeFSA(const unsigned char*& ptr) {
|
|
40
|
uint32_t fsaSize = readInt32(ptr);
|
|
41
42
|
// static SegrulesDeserializer deserializer;
SegrulesFSA* res = new SegrulesFSA(ptr);
|
|
43
44
45
46
|
ptr += fsaSize;
return res;
}
|
|
47
48
|
map<SegrulesOptions, SegrulesFSA*> createSegrulesFSAsMap(const unsigned char* analyzerPtr) {
map<SegrulesOptions, SegrulesFSA*> res;
|
|
49
50
51
52
53
54
|
const unsigned char* fsasMapPtr = getFSAsMapPtr(analyzerPtr);
const unsigned char* currPtr = fsasMapPtr;
unsigned char fsasNum = *currPtr;
currPtr++;
for (unsigned char i = 0; i < fsasNum; i++) {
SegrulesOptions options = deserializeOptions(currPtr);
|
|
55
|
SegrulesFSA* fsa = deserializeFSA(currPtr);
|
|
56
57
58
|
res[options] = fsa;
}
return res;
|
|
59
|
}
|
|
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
SegrulesOptions getDefaultSegrulesOptions(const unsigned char* ptr) {
const unsigned char* fsasMapPtr = getFSAsMapPtr(ptr);
const unsigned char* currPtr = fsasMapPtr;
unsigned char fsasNum = *currPtr;
currPtr++;
for (unsigned char i = 0; i < fsasNum; i++) {
deserializeOptions(currPtr);
deserializeFSA(currPtr);
}
return deserializeOptions(currPtr);
}
SegrulesFSA* getDefaultSegrulesFSA(
const map<SegrulesOptions, SegrulesFSA*>& map,
const unsigned char* ptr) {
SegrulesOptions opts = getDefaultSegrulesOptions(ptr);
return (*(map.find(opts))).second;
}
|
|
80
81
82
|
vector<uint32_t> getSeparatorsList(const unsigned char* ptr) {
ptr = getSeparatorsListPtr(ptr);
vector<uint32_t> res;
|
|
83
|
uint16_t listSize = readInt16(ptr);
|
|
84
|
for (unsigned int i = 0; i < listSize; i++) {
|
|
85
|
res.push_back(readInt32(ptr));
|
|
86
87
88
89
|
}
return res;
}
|
|
90
91
92
93
94
95
96
97
98
99
100
101
|
void debugMap(const map<SegrulesOptions, SegrulesFSA*>& res) {
map<SegrulesOptions, SegrulesFSA*>::const_iterator it = res.begin();
while (it != res.end()) {
SegrulesOptions::const_iterator it1 = it->first.begin();
while (it1 != it->first.end()) {
cerr << it1->first << " --> " << it1->second << endl;
it1++;
}
cerr << it->second << endl;
it++;
}
}
|