-
Notifications
You must be signed in to change notification settings - Fork 10
/
state.h
90 lines (70 loc) · 2.13 KB
/
state.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
//---------------------------------------------------------------------------
#pragma once
#include "mem.h"
#include <stdint.h>
//---------------------------------------------------------------------------
enum class StenoCaseMode : uint8_t {
NORMAL,
LOWER,
UPPER,
TITLE,
LOWER_ONCE,
UPPER_ONCE,
TITLE_ONCE,
UNSPECIFIED,
};
enum class SegmentLookupType : uint8_t {
UNKNOWN,
DIRECT,
AUTO_SUFFIX,
STROKE,
};
//---------------------------------------------------------------------------
struct StenoState {
StenoCaseMode caseMode;
StenoCaseMode overrideCaseMode : 3;
SegmentLookupType lookupType : 2;
bool joinNext : 1;
bool isGlue : 1;
bool isManualStateChange : 1;
bool shouldCombineUndo : 1;
bool isHistoryExtending : 1; // e.g. fingerspelling
bool isSpace : 1; // {^ ^}
bool requestsHistoryExtending : 1; // e.g. =set_value, =retro_transform
bool isSuffix : 1;
uint8_t _reserved : 1;
uint32_t spaceLength : 4;
uint32_t spaceOffset : 6;
static const StenoCaseMode NEXT_WORD_CASE_MODE[];
static const StenoCaseMode NEXT_LETTER_CASE_MODE[];
StenoCaseMode GetNextWordCaseMode() const {
return NEXT_WORD_CASE_MODE[(int)caseMode];
}
void Reset();
bool IsDefinitionStart() const {
return lookupType != SegmentLookupType::UNKNOWN;
}
bool operator==(const StenoState &a) const {
return memcmp(this, &a, sizeof(*this)) == 0;
}
void SetSpace(const char *space);
void CopyTo(StenoState *destination, size_t length) const {
for (size_t i = 0; i < length; ++i) {
destination[i] = this[i];
}
}
struct SpaceBuffer {
static SpaceBuffer instance;
uint8_t count;
char data[64];
};
const char *GetSpace() const {
return SpaceBuffer::instance.data + spaceOffset;
}
};
static_assert(sizeof(StenoState) == 4, "Expect StenoState to fit in 4 bytes");
//---------------------------------------------------------------------------
inline StenoCaseMode GetNextLetterCaseMode(StenoCaseMode caseMode) {
return StenoState::NEXT_LETTER_CASE_MODE[(int)caseMode];
}
//---------------------------------------------------------------------------