-
Notifications
You must be signed in to change notification settings - Fork 120
/
settings.d
2314 lines (2204 loc) · 72.2 KB
/
settings.d
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Written in the D programming language.
/**
This module contains implementation of settings container.
Similar to JSON, can be written/read to/from JSON.
Difference from usual JSON implementations: map (object) is ordered - will be written in the same order as read (or created).
Has a lot of methods for convenient storing/accessing of settings.
Synopsis:
----
import dlangui.core.settings;
Setting s = new Setting();
----
Copyright: Vadim Lopatin, 2014
License: Boost License 1.0
Authors: Vadim Lopatin, coolreader.org@gmail.com
*/
module dlangui.core.settings;
import dlangui.core.logger;
import dlangui.core.types : parseHexDigit;
public import dlangui.core.parseutils;
import std.range;
//import std.algorithm : clamp, equal;
import std.algorithm : equal;
import std.conv : to;
import std.utf : encode;
import std.math : pow;
import std.file;
import std.path;
import std.datetime : SysTime;
/// setting types - same as in std.json
enum SettingType {
STRING,
INTEGER,
UINTEGER,
FLOAT,
OBJECT,
ARRAY,
TRUE,
FALSE,
NULL
}
/// settings file format
enum SettingsFileFormat {
JSON,
SDL,
}
/// Settings object whith file information
class SettingsFile {
protected Setting _setting;
protected string _filename;
protected SysTime _lastModificationTime;
protected bool _loaded;
protected SettingsFileFormat _format = SettingsFileFormat.JSON;
@property Setting setting() { return _setting; }
@property Setting copySettings() {
return _setting.clone();
}
/// replace setting object
void replaceSetting(Setting s) {
_setting = s;
}
@property void applySettings(Setting settings) {
// TODO copy only changed settings
_setting = settings;
//_setting.apply(settings);
}
/// create settings file object; if filename is provided, attempts to load settings from file
this(string filename = null) {
_setting = new Setting();
_filename = filename;
if (_filename) {
string dir = dirName(_filename);
if (load()) {
// loaded ok
} else {
}
}
}
static int limitInt(long value, int minvalue, int maxvalue) {
if (value < minvalue)
return minvalue;
if (value > maxvalue)
return maxvalue;
return cast(int)value;
// remove clamp to support older compilers
//return clamp(cast(int)value, minvalue, maxvalue);
}
static string limitString(string value, const string[] values)
in { assert(values.length > 0); }
do {
foreach(v; values)
if (v.equal(value))
return value;
return values[0];
}
@property bool loaded() {
return _loaded;
}
/// filename
@property string filename() { return _filename; }
/// filename
@property void filename(string fn) { _filename = fn; }
protected bool updateModificationTime() {
if (_filename is null)
return false;
try {
if (!_filename.exists || !_filename.isFile)
return false;
SysTime accTime;
getTimes(_filename, accTime, _lastModificationTime);
return true;
} catch (Exception e) {
return false;
}
}
/// load settings from file
bool load(string filename = null) {
if (filename !is null)
_filename = filename;
assert(_filename !is null);
if (updateModificationTime()) {
bool res = _setting.load(_filename);
if (res)
_loaded = true;
afterLoad();
return res;
}
return false;
}
/// save settings to file
bool save(string filename = null, bool pretty = true) {
if (filename !is null)
_filename = filename;
assert(_filename);
string dir = dirName(_filename);
if (!dir.exists) {
try {
mkdirRecurse(dir);
} catch (Exception e) {
return false;
}
} else if (!dir.isDir) {
Log.d("", dir, " is file");
return false;
}
bool res = _setting.save(_filename, pretty);
res = updateModificationTime() || res;
afterSave();
return res;
}
/// override to add default values if missing
void updateDefaults() {
}
/// override to do something after loading - e.g. set defaults
void afterLoad() {
}
/// override to do something after saving
void afterSave() {
}
bool merge(string json) {
try {
Setting setting = new Setting();
setting.parseJSON(json);
_setting.apply(setting);
} catch (Exception e) {
Log.e("SettingsFile.merge - failed to parse json", e);
return false;
}
return true;
}
}
/// setting object
final class Setting {
union Store {
string str;
long integer;
ulong uinteger;
double floating;
SettingArray array;
SettingMap * map;
}
private Setting _parent;
private Store _store;
private bool _changed;
private SettingType _type = SettingType.NULL;
this() {
// NULL setting
}
this(long v) {
integer = v;
}
this(ulong v) {
uinteger = v;
}
this(string v) {
str = v;
}
this(double v) {
floating = v;
}
this(bool v) {
boolean = v;
}
this(Setting[] v) {
clear(SettingType.ARRAY);
_store.array.list = v;
}
this(string[] v) {
clear(SettingType.ARRAY);
this.strArray = v;
}
this(string[string] v) {
clear(SettingType.ARRAY);
this.strMap = v;
}
/// returns true if setting has been changed
@property bool changed() {
return _changed;
}
/// sets change flag
@property void changed(bool changed) {
_changed = changed;
}
/// array
private static struct SettingArray {
Setting[] list;
@property bool empty() inout { return list.length == 0; }
Setting set(int index, Setting value, Setting parent = null) {
if (index < 0)
index = cast(int)(list.length);
if (index >= list.length) {
int oldlen = cast(int)list.length;
list.length = index + 1;
foreach(i; oldlen .. index)
list[i] = new Setting(); // insert NULL items in holes
}
list[index] = value;
value.parent = parent;
return value;
}
/// get item by index, returns null if index out of bounds
Setting get(int index) {
if (index < 0 || index >= list.length)
return null;
return list[index];
}
/// remove by index, returns removed value
Setting remove(int index) {
Setting res = get(index);
if (!res)
return null;
foreach(i; index .. list.length - 1)
list[i] = list[i + 1];
list[$ - 1] = null;
list.length--;
return res;
}
@property int length() {
return cast(int)list.length;
}
/// deep copy
void copyFrom(ref SettingArray v) {
list.length = v.list.length;
foreach(i; 0 .. v.list.length) {
list[i] = v.list[i].clone();
}
}
}
/// ordered map
private static struct SettingMap {
Setting[] list;
int[string] map;
@property bool empty() inout { return list.length == 0; }
/// get item by index, returns null if index out of bounds
Setting get(int index) {
if (index < 0 || index >= list.length)
return null;
return list[index];
}
/// get item by key, returns null if key is not found
Setting get(string key) {
auto p = (key in map);
if (!p)
return null;
return list[*p];
}
Setting set(string key, Setting value, Setting parent) {
value.parent = parent;
auto p = (key in map);
if (p) {
// key is found
list[*p] = value;
} else {
// new value
list ~= value;
map[key] = cast(int)list.length - 1;
}
return value;
}
/// remove by index, returns removed value
Setting remove(int index) {
Setting res = get(index);
if (!res)
return null;
foreach(i; index .. list.length - 1)
list[i] = list[i + 1];
list[$ - 1] = null;
list.length--;
string key;
foreach(k, ref v; map) {
if (v == index) {
key = k;
} else if (v > index) {
v--;
}
}
if (key)
map.remove(key);
return res;
}
/// returns key for index
string keyByIndex(int index) {
foreach(k, ref v; map) {
if (v == index) {
return k;
}
}
return null;
}
/// remove by key, returns removed value
Setting remove(string key) {
auto p = (key in map);
if (!p)
return null;
return remove(*p);
}
@property int length() {
return cast(int)list.length;
}
/// deep copy
void copyFrom(SettingMap * v) {
list.length = v.list.length;
foreach(i; 0 .. v.list.length) {
list[i] = v.list[i].clone();
}
destroy(map);
foreach(key, value; v.map)
map[key] = value;
}
}
/// get parent
@property inout(Setting) parent() inout { return _parent; }
/// set parent
@property Setting parent(Setting v) {
_parent = v;
return v;
}
/// returns SettingType of setting
@property SettingType type() const { return _type; }
@property bool isString() { return _type == SettingType.STRING; }
@property bool isInteger() { return _type == SettingType.INTEGER; }
@property bool isUinteger() { return _type == SettingType.UINTEGER; }
@property bool isFloating() { return _type == SettingType.FLOAT; }
@property bool isObject() { return _type == SettingType.OBJECT; }
@property bool isArray() { return _type == SettingType.ARRAY; }
@property bool isBoolean() { return _type == SettingType.TRUE || _type == SettingType.FALSE; }
@property bool isNull() { return _type == SettingType.NULL; }
/// clear value and set new type
void clear(SettingType newType) {
if (newType != _type) {
clear();
_type = newType;
}
clear();
}
/// clear value
void clear() {
final switch(_type) with(SettingType) {
case STRING:
_store.str = null;
break;
case ARRAY:
_store.array = _store.array.init;
break;
case OBJECT:
_store.map = _store.map.init;
break;
case INTEGER:
_store.integer = _store.integer.init;
break;
case UINTEGER:
_store.uinteger = _store.uinteger.init;
break;
case FLOAT:
_store.floating = _store.floating.init;
break;
case TRUE:
case FALSE:
case NULL:
break;
}
}
void apply(Setting settings) {
if (settings.isObject) {
foreach(key, value; settings.map) {
this[key] = value;
}
}
}
/// deep copy of settings
Setting clone() {
Setting res = new Setting();
res.clear(_type);
final switch(_type) with(SettingType) {
case STRING:
res._store.str = _store.str;
break;
case ARRAY:
res._store.array.copyFrom(_store.array);
break;
case OBJECT:
if (_store.map) {
res._store.map = new SettingMap();
res._store.map.copyFrom(_store.map);
}
break;
case INTEGER:
res._store.integer = _store.integer;
break;
case UINTEGER:
res._store.uinteger = _store.uinteger;
break;
case FLOAT:
res._store.floating = _store.floating;
break;
case TRUE:
case FALSE:
case NULL:
break;
}
res._changed = false;
return res;
}
/// read as string value
@property string str() {
final switch(_type) with(SettingType) {
case STRING:
return _store.str;
case INTEGER:
return to!string(_store.integer);
case UINTEGER:
return to!string(_store.uinteger);
case FLOAT:
return to!string(cast(double)_store.floating);
case TRUE:
return "true";
case FALSE:
return "false";
case NULL:
case ARRAY:
case OBJECT:
return null;
}
}
/// read as string value
inout (string) strDef(inout (string) defValue) {
final switch(_type) with(SettingType) {
case STRING:
return _store.str;
case INTEGER:
return to!string(_store.integer);
case UINTEGER:
return to!string(_store.uinteger);
case FLOAT:
return to!string(cast(double)_store.floating);
case TRUE:
return "true";
case FALSE:
return "false";
case NULL:
case ARRAY:
case OBJECT:
return defValue;
}
}
/// set string value for object
@property string str(string v) {
if (_type != SettingType.STRING)
clear(SettingType.STRING);
_store.str = v;
return v;
}
/// returns items as string array
@property string[] strArray() {
final switch(_type) with(SettingType) {
case STRING:
return [_store.str];
case INTEGER:
return [to!string(_store.integer)];
case UINTEGER:
return [to!string(_store.uinteger)];
case FLOAT:
return [to!string(_store.floating)];
case TRUE:
return ["true"];
case FALSE:
return ["false"];
case NULL:
return null;
case ARRAY:
case OBJECT:
string[] res;
foreach(i; 0 .. length)
res ~= this[i].str;
return res;
}
}
/// sets string array
@property string[] strArray(string[] list) {
clear(SettingType.ARRAY);
foreach(s; list) {
this[length] = new Setting(s);
}
return list;
}
/// returns items as int array
@property int[] intArray() {
final switch(_type) with(SettingType) {
case STRING:
case INTEGER:
case UINTEGER:
case FLOAT:
case TRUE:
case FALSE:
return [cast(int)integer];
case NULL:
return null;
case ARRAY:
case OBJECT:
int[] res;
foreach(i; 0 .. length)
res ~= cast(int)this[i].integer;
return res;
}
}
/// sets int array
@property int[] intArray(int[] list) {
clear(SettingType.ARRAY);
foreach(s; list) {
this[length] = new Setting(cast(long)s);
}
return list;
}
/// returns items as Setting array
@property Setting[] array() {
final switch(_type) with(SettingType) {
case STRING:
case INTEGER:
case UINTEGER:
case FLOAT:
case TRUE:
case FALSE:
return [this];
case NULL:
return null;
case ARRAY:
case OBJECT:
Setting[] res;
foreach(i; 0 .. length)
res ~= this[i];
return res;
}
}
/// sets Setting array
@property Setting[] array(Setting[] list) {
clear(SettingType.ARRAY);
foreach(s; list) {
this[length] = s;
}
return list;
}
/// returns items as string[string] map
@property string[string] strMap() {
final switch(_type) with(SettingType) {
case STRING:
case INTEGER:
case UINTEGER:
case FLOAT:
case TRUE:
case FALSE:
case NULL:
case ARRAY:
return null;
case OBJECT:
string[string] res;
if (_store.map) {
foreach(key, value; _store.map.map) {
Setting v = _store.map.get(value);
res[key] = v ? v.str : null;
}
}
return res;
}
}
/// sets string[string] map
@property string[string] strMap(string[string] list) {
clear(SettingType.OBJECT);
foreach(key, value; list) {
this[key] = new Setting(value);
}
return list;
}
/// returns items as int[string] map
@property int[string] intMap() {
final switch(_type) with(SettingType) {
case STRING:
case INTEGER:
case UINTEGER:
case FLOAT:
case TRUE:
case FALSE:
case NULL:
case ARRAY:
return null;
case OBJECT:
int[string] res;
foreach(key, value; _store.map.map)
res[key] = cast(int)this[value].integer;
return res;
}
}
/// sets int[string] map
@property int[string] intMap(int[string] list) {
clear(SettingType.OBJECT);
foreach(key, value; list) {
this[key] = new Setting(cast(long)value);
}
return list;
}
/// returns items as Setting[string] map
@property Setting[string] map() {
final switch(_type) with(SettingType) {
case STRING:
case INTEGER:
case UINTEGER:
case FLOAT:
case TRUE:
case FALSE:
case NULL:
case ARRAY:
return null;
case OBJECT:
Setting[string] res;
foreach(key, value; _store.map.map)
res[key] = this[value];
return res;
}
}
/// sets Setting[string] map
@property Setting[string] map(Setting[string] list) {
clear(SettingType.OBJECT);
foreach(key, value; list) {
this[key] = value;
}
return list;
}
/// to iterate using foreach
int opApply(int delegate(ref Setting)dg) {
int result = 0;
if (_type == SettingType.ARRAY) {
for(int i = 0; i < _store.array.list.length; i++) {
result = dg(_store.array.list[i]);
if (result)
break;
}
} else if (_type == SettingType.OBJECT) {
for(int i = 0; i < _store.map.list.length; i++) {
result = dg(_store.map.list[i]);
if (result)
break;
}
}
return result;
}
/// to iterate over OBJECT using foreach(key, value; map)
int opApply(int delegate(ref string, ref Setting)dg) {
int result = 0;
if (_type == SettingType.OBJECT) {
for(int i = 0; i < _store.map.list.length; i++) {
string key = _store.map.keyByIndex(i);
result = dg(key, _store.map.list[i]);
if (result)
break;
}
}
return result;
}
/// to iterate using foreach_reverse
int opApplyReverse(int delegate(ref Setting)dg) {
int result = 0;
if (_type == SettingType.ARRAY) {
for(int i = cast(int)_store.array.list.length - 1; i >= 0; i--) {
result = dg(_store.array.list[i]);
if (result)
break;
}
} else if (_type == SettingType.OBJECT) {
for(int i = cast(int)_store.map.list.length - 1; i >= 0; i--) {
result = dg(_store.map.list[i]);
if (result)
break;
}
}
return result;
}
/// read as long value
@property inout(long) integer() inout {
final switch(_type) with(SettingType) {
case STRING:
return parseLong(_store.str);
case INTEGER:
return _store.integer;
case UINTEGER:
return cast(long)_store.uinteger;
case FLOAT:
return cast(long)_store.floating;
case TRUE:
return 1;
case FALSE:
case NULL:
case ARRAY:
case OBJECT:
return 0;
}
}
/// read as long value
inout(long) integerDef(long defValue) inout {
final switch(_type) with(SettingType) {
case STRING:
return parseLong(_store.str, defValue);
case INTEGER:
return _store.integer;
case UINTEGER:
return cast(long)_store.uinteger;
case FLOAT:
return cast(long)_store.floating;
case TRUE:
return 1;
case FALSE:
return 0;
case NULL:
case ARRAY:
case OBJECT:
return defValue;
}
}
/// set long value for object
@property long integer(long v) {
if (_type != SettingType.INTEGER)
clear(SettingType.INTEGER);
_store.integer = v;
return v;
}
/// read as ulong value
@property inout(long) uinteger() inout {
final switch(_type) with(SettingType) {
case STRING:
return parseULong(_store.str);
case INTEGER:
return cast(ulong)_store.integer;
case UINTEGER:
return _store.uinteger;
case FLOAT:
return cast(ulong)_store.floating;
case TRUE:
return 1;
case FALSE:
case NULL:
case ARRAY:
case OBJECT:
return 0;
}
}
/// read as ulong value
inout(long) uintegerDef(ulong defValue) inout {
final switch(_type) with(SettingType) {
case STRING:
return parseULong(_store.str, defValue);
case INTEGER:
return cast(ulong)_store.integer;
case UINTEGER:
return _store.uinteger;
case FLOAT:
return cast(ulong)_store.floating;
case TRUE:
return 1;
case FALSE:
return 0;
case NULL:
case ARRAY:
case OBJECT:
return defValue;
}
}
/// set ulong value for object
@property ulong uinteger(ulong v) {
if (_type != SettingType.UINTEGER)
clear(SettingType.UINTEGER);
_store.uinteger = v;
return v;
}
/// read as double value
@property inout(double) floating() inout {
final switch(_type) with(SettingType) {
case STRING:
return 0; //parseULong(_store.str);
case INTEGER:
return cast(double)_store.integer;
case UINTEGER:
return cast(double)_store.uinteger;
case FLOAT:
return _store.floating;
case TRUE:
return 1;
case FALSE:
case NULL:
case ARRAY:
case OBJECT:
return 0;
}
}
/// read as double value with default
inout(double) floatingDef(double defValue) inout {
final switch(_type) with(SettingType) {
case STRING:
return defValue; //parseULong(_store.str);
case INTEGER:
return cast(double)_store.integer;
case UINTEGER:
return cast(double)_store.uinteger;
case FLOAT:
return _store.floating;
case TRUE:
return 1;
case FALSE:
return 0;
case NULL:
case ARRAY:
case OBJECT:
return defValue;
}
}
/// set ulong value for object
@property double floating(double v) {
if (_type != SettingType.FLOAT)
clear(SettingType.FLOAT);
_store.floating = v;
return v;
}
/// parse string as boolean; supports 1, 0, y, n, yes, no, t, f, true, false; returns defValue if cannot be parsed
static bool parseBool(inout string v, bool defValue = false) {
int len = cast(int)v.length;
if (len == 0)
return defValue;
char ch = v[0];
if (len == 1) {
if (ch == '1' || ch == 'y' || ch == 't')
return true;
if (ch == '1' || ch == 'y' || ch == 't')
return false;
return defValue;
}
if (v.equal("yes") || v.equal("true"))
return true;
if (v.equal("no") || v.equal("false"))
return false;
return defValue;
}
/// read as boolean value
@property inout(bool) boolean() inout {
final switch(_type) with(SettingType) {
case STRING:
return parseBool(_store.str);
case INTEGER:
return _store.integer != 0;
case UINTEGER:
return _store.uinteger != 0;
case FLOAT:
return _store.floating != 0;
case TRUE:
return true;
case FALSE:
case NULL:
return false;
case ARRAY:
return !_store.array.empty;
case OBJECT:
return _store.map && !_store.map.empty;
}
}
/// read as boolean value
inout(bool) booleanDef(bool defValue) inout {
final switch(_type) with(SettingType) {
case STRING:
return parseBool(_store.str, defValue);
case INTEGER:
return _store.integer != 0;
case UINTEGER:
return _store.uinteger != 0;
case FLOAT:
return _store.floating != 0;
case TRUE:
return true;
case FALSE:
case NULL:
return false;
case ARRAY:
return defValue;
case OBJECT:
return defValue;
}
}
/// set bool value for object
@property bool boolean(bool v) {
if (_type == SettingType.TRUE) {
if (!v) _type = SettingType.FALSE;
} else if (_type == SettingType.FALSE) {
if (v) _type = SettingType.TRUE;
} else {
clear(v ? SettingType.TRUE : SettingType.FALSE);
}
return v;
}
/// get number of elements for array or map, returns 0 for other types
int length() inout {
if (_type == SettingType.ARRAY) {
return cast(int)_store.array.list.length;
} else if (_type == SettingType.OBJECT) {