-
Notifications
You must be signed in to change notification settings - Fork 0
/
Account.hpp
86 lines (64 loc) · 2.13 KB
/
Account.hpp
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
#pragma once
#include <cassert>
#include <cstring>
#include <limits>
#include <vector>
#include "common.hpp"
#include "core/SmallString.hpp"
namespace hlcup {
struct Account {
const static constexpr u32 kInvalidOffset = std::numeric_limits<u32>::max();
const static constexpr u32 kInvalidId = std::numeric_limits<u32>::max();
enum Sex : u8 {
kFemale = 0,
kMale = 1,
kInvalidSex = std::numeric_limits<u8>::max(),
};
enum Status : u8 {
kFree = 0,
kComplicated = 1,
kOccupied = 2,
kInvalidStatus = std::numeric_limits<u8>::max(),
};
struct Like {
u32 to_id;
i32 ts;
};
char *string_data;
u32 id;
Sex sex;
Status status;
Timestamp joined;
Timestamp birth;
struct {
Timestamp start, finish;
} premium;
StringRef fname, sname, country, city, phone, email;
std::vector<u32> interests;
std::vector<Like> likes;
inline bool addLike(const Like &like) {
likes.push_back(like);
return true;
}
Account() {
string_data = reinterpret_cast<char *>(::malloc(8192));
assert(string_data != nullptr);
clear();
}
size_t getInterestsCount() const { return interests.size() <= 1 ? 0 : interests.size() - 1; }
StringRef getInterest(size_t idx) const { return StringRef{interests[idx], interests[idx + 1] - interests[idx]}; }
void clear() {
id = kInvalidId;
sex = kInvalidSex;
status = kInvalidStatus;
joined = birth = kInvalidTimestamp;
premium.start = premium.finish = kInvalidTimestamp;
fname.offset = sname.offset = country.offset = city.offset = phone.offset = email.offset = kInvalidOffset;
interests.clear();
likes.clear();
}
~Account() { free(string_data); }
inline std::string_view getView(const StringRef &ref) const { return std::string_view(string_data + ref.offset, ref.size); }
inline std::string getString(const StringRef &ref) const { return std::string(string_data + ref.offset, ref.size); }
};
} // namespace hlcup