-
Notifications
You must be signed in to change notification settings - Fork 2
/
UniSettings_NodeUInt8.pas
229 lines (179 loc) · 6.91 KB
/
UniSettings_NodeUInt8.pas
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
{$IFNDEF UNS_Included}
unit UniSettings_NodeUInt8;
{$INCLUDE '.\UniSettings_defs.inc'}
{$DEFINE UNS_NodeUInt8}
interface
uses
Classes, IniFiles, Registry,
AuxTypes, MemoryBuffer, IniFileEx,
UniSettings_Common, UniSettings_NodeBase, UniSettings_NodeLeaf;
type
TUNSNodeValueType = UInt8;
TUNSNodeValueTypeBin = UInt8;
TUNSNodeValueTypePtr = PUInt8;
TUNSNodeUInt8 = class(TUNSNodeLeaf)
{$DEFINE UNS_NodeInclude_Declaration}
{$INCLUDE '.\UniSettings_Node.inc'}
{$UNDEF UNS_NodeInclude_Declaration}
end;
implementation
uses
SysUtils,
BinaryStreaming,
UniSettings_Exceptions;
type
TUNSNodeClassType = TUNSNodeUInt8;
var
UNS_StreamWriteFunction:
Function(Stream: TStream; Value: UInt8; Advance: Boolean = True): TMemSize
= BinaryStreaming.Stream_WriteUInt8;
UNS_StreamReadFunction:
Function(Stream: TStream; Advance: Boolean = True): UInt8
= BinaryStreaming.Stream_ReadUInt8;
UNS_BufferWriteFunction:
Function(Dest: Pointer; Value: UInt8): TMemSize
= BinaryStreaming.Ptr_WriteUInt8;
UNS_BufferReadFunction:
Function(Dest: Pointer): UInt8
= BinaryStreaming.Ptr_ReadUInt8;
//==============================================================================
class Function TUNSNodeClassType.GetValueType: TUNSValueType;
begin
Result := vtUInt8;
end;
//------------------------------------------------------------------------------
Function TUNSNodeClassType.ConvToStr(const Value: TUNSNodeValueType): String;
begin
If ValueFormatSettings.HexIntegers then
Result := '$' + IntToHex(Value,2)
else
Result := IntToStr(Value);
end;
//------------------------------------------------------------------------------
Function TUNSNodeClassType.ConvFromStr(const Str: String): TUNSNodeValueType;
begin
Result := TUNSNodeValueType(StrToInt(Str));
end;
//==============================================================================
constructor TUNSNodeClassType.Create(const Name: String; ParentNode: TUNSNodeBase);
begin
inherited Create(Name,ParentNode);
fValue := 0;
fSavedValue := 0;
fDefaultValue := 0;
end;
//------------------------------------------------------------------------------
procedure TUNSNodeClassType.SaveTo(Ini: TIniFile; const Section,Key: String);
begin
Ini.WriteInteger(Section,Key,fValue);
end;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
procedure TUNSNodeClassType.SaveTo(Ini: TIniFileEx; const Section,Key: String);
begin
Ini.WriteUInt8(Section,Key,fValue);
end;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
procedure TUNSNodeClassType.SaveTo(Reg: TRegistry; const Value: String);
begin
Reg.WriteInteger(Value,fValue);
end;
//------------------------------------------------------------------------------
procedure TUNSNodeClassType.LoadFrom(Ini: TIniFile; const Section,Key: String);
begin
SetValue(UInt8(Ini.ReadInteger(Section,Key,fValue)));
end;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
procedure TUNSNodeClassType.LoadFrom(Ini: TIniFileEx; const Section,Key: String);
begin
SetValue(Ini.ReadInt8(Section,Key,fValue));
end;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
procedure TUNSNodeClassType.LoadFrom(Reg: TRegistry; const Value: String);
begin
SetValue(UInt8(Reg.ReadInteger(Value)));
end;
//------------------------------------------------------------------------------
{$DEFINE UNS_NodeInclude_Implementation}
{$INCLUDE '.\UniSettings_Node.inc'}
{$UNDEF UNS_NodeInclude_Implementation}
{$WARNINGS OFF} // supresses warnings on lines after the final end
end.
{$ELSE UNS_Included}
{$WARNINGS ON}
{$IFDEF UNS_Include_Declaration}
Function UInt8ValueGetNoLock(const ValueName: String; ValueKind: TUNSValueKind = vkActual): UInt8; virtual;
procedure UInt8ValueSetNoLock(const ValueName: String; NewValue: UInt8; ValueKind: TUNSValueKind = vkActual); virtual;
Function UInt8ValueGet(const ValueName: String; ValueKind: TUNSValueKind = vkActual): UInt8; virtual;
procedure UInt8ValueSet(const ValueName: String; NewValue: UInt8; ValueKind: TUNSValueKind = vkActual); virtual;
{$ENDIF UNS_Include_Declaration}
//==============================================================================
{$IFDEF UNS_Include_Implementation}
Function TUniSettings.UInt8ValueGetNoLock(const ValueName: String; ValueKind: TUNSValueKind = vkActual): UInt8;
var
TempNode: TUNSNodeLeaf;
TempValueKind: TUNSValueKind;
TempIndex: Integer;
begin
If AccessLeafNodeTypeIsArray(ValueName,vtUInt8,'UInt8ValueGetNoLock',TempNode,TempValueKind,TempIndex) then
case TempValueKind of
vkActual: Result := TUNSNodeAoUInt8(TempNode).Items[TempIndex];
vkSaved: Result := TUNSNodeAoUInt8(TempNode).SavedItems[TempIndex];
vkDefault: Result := TUNSNodeAoUInt8(TempNode).DefaultItems[TempIndex];
else
raise EUNSInvalidValueKindException.Create(TempValueKind,Self,'UInt8ValueGetNoLock');
end
else
case ValueKind of
vkActual: Result := TUNSNodeUInt8(TempNode).Value;
vkSaved: Result := TUNSNodeUInt8(TempNode).SavedValue;
vkDefault: Result := TUNSNodeUInt8(TempNode).DefaultValue;
else
raise EUNSInvalidValueKindException.Create(TempValueKind,Self,'UInt8ValueGetNoLock');
end;
end;
//------------------------------------------------------------------------------
procedure TUniSettings.UInt8ValueSetNoLock(const ValueName: String; NewValue: UInt8; ValueKind: TUNSValueKind = vkActual);
var
TempNode: TUNSNodeLeaf;
TempValueKind: TUNSValueKind;
TempIndex: Integer;
begin
If AccessLeafNodeTypeIsArray(ValueName,vtBool,'UInt8ValueSetNoLock',TempNode,TempValueKind,TempIndex) then
case TempValueKind of
vkActual: TUNSNodeAoUInt8(TempNode).Items[TempIndex] := NewValue;
vkSaved: TUNSNodeAoUInt8(TempNode).SavedItems[TempIndex] := NewValue;
vkDefault: TUNSNodeAoUInt8(TempNode).DefaultItems[TempIndex] := NewValue;
else
raise EUNSInvalidValueKindException.Create(TempValueKind,Self,'UInt8ValueSetNoLock');
end
else
case ValueKind of
vkActual: TUNSNodeUInt8(TempNode).Value := NewValue;
vkSaved: TUNSNodeUInt8(TempNode).SavedValue := NewValue;
vkDefault: TUNSNodeUInt8(TempNode).DefaultValue := NewValue;
else
raise EUNSInvalidValueKindException.Create(ValueKind,Self,'UInt8ValueSetNoLock');
end;
end;
//------------------------------------------------------------------------------
Function TUniSettings.UInt8ValueGet(const ValueName: String; ValueKind: TUNSValueKind = vkActual): UInt8;
begin
ReadLock;
try
Result := UInt8ValueGetNoLock(ValueName,ValueKind);
finally
ReadUnlock;
end;
end;
//------------------------------------------------------------------------------
procedure TUniSettings.UInt8ValueSet(const ValueName: String; NewValue: UInt8; ValueKind: TUNSValueKind = vkActual);
begin
WriteLock;
try
UInt8ValueSetNoLock(ValueName,NewValue,ValueKind);
finally
WriteUnlock;
end;
end;
{$ENDIF UNS_Include_Implementation}
{$ENDIF UNS_Included}