File: FXSettings.cpp

package info (click to toggle)
gogglesmm 1.2.5-6
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 16,812 kB
  • sloc: cpp: 231,960; ansic: 893; xml: 222; makefile: 33
file content (933 lines) | stat: -rw-r--r-- 27,133 bytes parent folder | download | duplicates (2)
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
/********************************************************************************
*                                                                               *
*                          S e t t i n g s   C l a s s                          *
*                                                                               *
*********************************************************************************
* Copyright (C) 1998,2022 by Jeroen van der Zijp.   All Rights Reserved.        *
*********************************************************************************
* This library is free software; you can redistribute it and/or modify          *
* it under the terms of the GNU Lesser General Public License as published by   *
* the Free Software Foundation; either version 3 of the License, or             *
* (at your option) any later version.                                           *
*                                                                               *
* This library is distributed in the hope that it will be useful,               *
* but WITHOUT ANY WARRANTY; without even the implied warranty of                *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
* GNU Lesser General Public License for more details.                           *
*                                                                               *
* You should have received a copy of the GNU Lesser General Public License      *
* along with this program.  If not, see <http://www.gnu.org/licenses/>          *
********************************************************************************/
#include "xincs.h"
#include "fxver.h"
#include "fxdefs.h"
#include "fxmath.h"
#include "fxascii.h"
#include "FXArray.h"
#include "FXHash.h"
#include "FXStream.h"
#include "FXElement.h"
#include "FXException.h"
#include "FXString.h"
#include "FXColors.h"
#include "FXFile.h"
#include "FXStringDictionary.h"
#include "FXSettings.h"

/*
  Notes:

  - Format for settings database file:

    [SectionKey]
    EntryKey=string-with-no-spaces
    EntryKey="string\nwith a\nnewline in it\n"
    EntryKey=" string with leading and trailing spaces and \"embedded\" in it  "
    EntryKey=string with no leading or trailing spaces

  - EntryKey may is of the form "ali baba", "ali-baba", "ali_baba", or "ali.baba".

  - Leading/trailing spaces are NOT part of the EntryKey.

  - Escape sequences now allow octal (\377) as well as hex (\xff) codes.

  - EntryKey format should be like values.

  - Extensive error checking in unparseFile() to ensure no settings data is
    lost when disk is full.
*/


#define EMPTY     (const_cast<Entry*>((const Entry*)(__settings__empty__+3)))
#define BSHIFT    5

using namespace FX;

/*******************************************************************************/

namespace FX {


// Empty string dictionary table value
extern const FXint __string__empty__[];
extern const FXival __stringdictionary__empty__[];
extern const FXival __settings__empty__[];
const FXival __settings__empty__[6]={1,0,1,(FXival)(__string__empty__+1),(FXival)(__stringdictionary__empty__+3),0};


// Adjust the size of the table
FXbool FXSettings::no(FXival n){
  FXival m=no();
  if(__likely(m!=n)){
    Entry* elbat;
    void*  p;

    // Release old table
    if(1<m){
      destructElms(table,m);
      ::free(((FXival*)table)-3);
      table=EMPTY;
      }

    // Allocate new table
    if(1<n){
      if(__unlikely((p=::calloc(sizeof(FXival)*3+sizeof(Entry)*n,1))==nullptr)) return false;
      elbat=(Entry*)(((FXival*)p)+3);
      ((FXival*)elbat)[-3]=n;
      ((FXival*)elbat)[-2]=0;
      ((FXival*)elbat)[-1]=n;
      constructElms(elbat,n);
      table=elbat;
      }
    }
  return true;
  }


// Resize the table to the given size; the size must be a power of two
FXbool FXSettings::resize(FXival n){
  FXSettings elbat;
  FXASSERT((n&(n-1))==0);       // Power of 2
  FXASSERT((n-used())>0);       // At least one free slot
  if(elbat.no(n)){
    if(1<elbat.no() && 1<no()){
      FXuval p,b,h,x; FXival i;
      for(i=0; i<no(); ++i){                  // Hash existing entries into new table
        if(!table[i].key.empty()){
          p=b=h=table[i].hash;
          while(elbat.table[x=p&(n-1)].hash){ // Locate slot
            p=(p<<2)+p+b+1;
            b>>=BSHIFT;
            }
          elbat.table[x].key.adopt(table[i].key);       // Steal the string buffers
          elbat.table[x].data.adopt(table[i].data);
          elbat.table[x].hash=(FXuint)h;                // And copy the hash value
          }
        }
      elbat.free(n-used());     // All non-empty slots now free
      elbat.used(used());       // Used slots not changed
      elbat.setModified(isModified());
      }
    adopt(elbat);
    return true;
    }
  return false;
  }


// Construct settings database
FXSettings::FXSettings():table(EMPTY),modified(false){
  FXASSERT(sizeof(Entry)<=sizeof(FXival)*3);
  }


// Construct from another settings database
FXSettings::FXSettings(const FXSettings& other):table(EMPTY),modified(other.modified){
  FXASSERT(sizeof(Entry)<=sizeof(FXival)*3);
  if(1<other.no()){
    if(__unlikely(!no(other.no()))){ throw FXMemoryException("FXSettings::FXSettings: out of memory\n"); }
    copyElms(table,other.table,no());
    free(other.free());
    used(other.used());
    }
  }


// Assignment operator
FXSettings& FXSettings::operator=(const FXSettings& other){
  if(__likely(table!=other.table)){
    if(1<other.no()){
      if(__unlikely(!no(other.no()))){ throw FXMemoryException("FXSettings::operator=: out of memory\n"); }
      copyElms(table,other.table,no());
      free(other.free());
      used(other.used());
      }
    else{
      no(1);
      }
    modified=true;
    }
  return *this;
  }


// Adopt settings database from another
FXSettings& FXSettings::adopt(FXSettings& other){
  if(__likely(table!=other.table)){
    swap(table,other.table);
    other.clear();
    other.modified=true;
    modified=true;
    }
  return *this;
  }


// Find position of given key
FXival FXSettings::find(const FXchar* ky) const {
  if(__unlikely(!ky || !*ky)){ throw FXRangeException("FXSettings::find: null or empty key\n"); }
  if(__likely(!empty())){
    FXuval p,b,x,h;
    p=b=h=FXString::hash(ky);
    FXASSERT(h);
    while(table[x=p&(no()-1)].hash){
      if(table[x].hash==h && table[x].key==ky) return x;
      p=(p<<2)+p+b+1;
      b>>=BSHIFT;
      }
    }
  return -1;
  }


// Return reference to string dictionary assocated with key
FXStringDictionary& FXSettings::at(const FXchar* ky){
  FXuval p,b,h,x;
  if(__unlikely(!ky || !*ky)){ throw FXRangeException("FXSettings::at: null or empty key\n"); }
  p=b=h=FXString::hash(ky);
  FXASSERT(h);
  while(table[x=p&(no()-1)].hash){
    if(table[x].hash==h && table[x].key==ky) goto x;   // Return existing slot
    p=(p<<2)+p+b+1;
    b>>=BSHIFT;
    }
  if(__unlikely(free()<=1+(no()>>2)) && __unlikely(!resize(no()<<1))){ throw FXMemoryException("FXSettings::at: out of memory\n"); }
  p=b=h;
  while(table[x=p&(no()-1)].hash){
    if(table[x].key.empty()) goto y;                    // Return voided slot
    p=(p<<2)+p+b+1;
    b>>=BSHIFT;
    }
  free(free()-1);                                       // Put into empty slot
y:used(used()+1);
  table[x].key=ky;
  table[x].hash=(FXuint)h;
x:modified=true;                                        // Assume its to be written
  return table[x].data;
  }


// Return constant reference to string dictionary assocated with key
const FXStringDictionary& FXSettings::at(const FXchar* ky) const {
  if(__unlikely(!ky || !*ky)){ throw FXRangeException("FXSettings::at: null or empty key\n"); }
  if(__likely(!empty())){
    FXuval p,b,x,h;
    p=b=h=FXString::hash(ky);
    FXASSERT(h);
    while(table[x=p&(no()-1)].hash){
      if(table[x].hash==h && table[x].key==ky) return table[x].data;
      p=(p<<2)+p+b+1;
      b>>=BSHIFT;
      }
    }
  return EMPTY[0].data;
  }


// Parse filename
FXbool FXSettings::parseFile(const FXString& filename,FXbool mrk){
  FXTRACE((100,"FXSettings::parseFile(%s,%d)\n",filename.text(),mrk));
  FXFile file(filename,FXFile::Reading);
  if(file.isOpen()){
    FXString string;
    string.length(file.size());
    if(file.readBlock(string.text(),string.length())==string.length()){
      return parse(string,mrk);
      }
    }
  return false;
  }


// Unparse registry file
FXbool FXSettings::unparseFile(const FXString& filename){
  FXTRACE((100,"FXSettings::unparseFile(%s)\n",filename.text()));
  FXFile file(filename,FXFile::Writing);
  if(file.isOpen()){
    FXString string;
    if(unparse(string)){
      return file.writeBlock(string.text(),string.length())==string.length();
      }
    }
  return false;
  }


// Parse single string to populate settings
FXbool FXSettings::parse(const FXString& str,FXbool mrk){
  FXint lineno=1,p=0,b,e;
  FXString section,name,value;

  // Skip over byte-order mark
  if(str[p]=='\xef' && str[p+1]=='\xbb' && str[p+2]=='\xbf') p+=3;

  // Parse one line at a time
  while(str[p]){

    // Skip leading blanks
    while(Ascii::isBlank(str[p])) ++p;

    // Parse section name
    if(str[p]=='['){

      b=++p;

      // Scan over section name
      while(str[p] && str[p]!=']' && str[p]!='\r' && str[p]!='\n'){
        if(Ascii::isControl(str[p])){ fxwarning("%d: control character in section name.\n",lineno); goto nxt; }
        ++p;
        }

      // Check errors
      if(str[p]!=']'){ fxwarning("%d: expected ']' to close section name.\n",lineno); goto nxt; }

      e=p++;

      // Grab name
      section=str.mid(b,e-b);
      }

    // Parse name-value pair
    else if(str[p]!='#' && str[p]!=';' && str[p]!='\r' && str[p]!='\n'){

      // Should have seen section prior to this
      if(section.empty()){ fxwarning("%d: entry should follow a section.\n",lineno); goto nxt; }

      b=p;

      // Scan key name
      while(str[p] && str[p]!='=' && str[p]!='\r' && str[p]!='\n'){
        if(Ascii::isControl(str[p])){ fxwarning("%d: control character in entry name.\n",lineno); goto nxt; }
        ++p;
        }

      // Check errors
      if(str[p]!='='){ fxwarning("%d: expected '=' to follow entry name.\n",lineno); goto nxt; }

      e=p++;

      // Remove trailing spaces after name
      while(b<e && Ascii::isBlank(str[e-1])) e--;

      // Grab name
      name=str.mid(b,e-b);

      // Skip leading spaces
      while(Ascii::isBlank(str[p])) p++;

      // Mark value
      b=p;

      // Scan value
      while(str[p] && str[p]!='\n' && str[p]!='\r'){
        if(Ascii::isControl(str[p])){ fxwarning("%d: control character in entry value.\n",lineno); goto nxt; }
        ++p;
        }

      e=p;

      // Remove trailing spaces after value
      while(b<e && Ascii::isBlank(str[e-1])) e--;

      // Grab the unescaped value
      value=FXString::unescape(str.mid(b,e-b),'"','"');

      // Add entry to current section
      at(section).at(name,mrk)=value;
      }

    // Skip to end of line
nxt:while(str[p]){
      if(str[p++]=='\n'){ lineno++; break; }
      }
    }
  return true;
  }


// Unparse settings to a single string
FXbool FXSettings::unparse(FXString& str) const {
  FXival sec,ent,flg;

  // Clear output
  str.clear();

  // Any keys at all?
  if(!empty()){

    // Loop over all sections
    for(sec=0; sec<no(); ++sec){

      // Get group, if any
      if(!empty(sec)){

        // Loop over all entries
        for(ent=flg=0; ent<data(sec).no(); ++ent){

          // Is key-value pair marked?
          if(!data(sec).empty(ent) && data(sec).mark(ent)){

            // Write section name if not written yet
            if(!flg){
              str.append("[");
              str.append(key(sec));      // FIXME should escape group
              str.append("]" ENDLINE);
              flg=1;
              }

            // Write marked key-value pairs only
            str.append(data(sec).key(ent));
            str.append("=");
            if(FXString::shouldEscape(data(sec).data(ent),'"','"')){
              str.append(FXString::escape(data(sec).data(ent),'"','"'));
              }
            else{
              str.append(data(sec).data(ent));
              }
            str.append(ENDLINE);
            }
          }

        // Blank line after end
        if(flg){
          str.append(ENDLINE);
          }
        }
      }
    }
  return true;
  }


// Read a formatted registry entry
FXint FXSettings::readFormatEntry(const FXchar* section,const FXchar* name,const FXchar* fmt,...) const {
  const FXString& value=at(section).at(name);
  FXint result=0;
  if(!value.empty()){
    va_list args;
    va_start(args,fmt);
    result=value.vscan(fmt,args);
    va_end(args);
    }
  return result;
  }


// Read a formatted registry entry
FXint FXSettings::readFormatEntry(const FXString& section,const FXchar* name,const FXchar* fmt,...) const {
  const FXString& value=at(section).at(name);
  FXint result=0;
  if(!value.empty()){
    va_list args;
    va_start(args,fmt);
    result=value.vscan(fmt,args);
    va_end(args);
    }
  return result;
  }


// Read a formatted registry entry
FXint FXSettings::readFormatEntry(const FXString& section,const FXString& name,const FXchar* fmt,...) const {
  const FXString& value=at(section).at(name);
  FXint result=0;
  if(!value.empty()){
    va_list args;
    va_start(args,fmt);
    result=value.vscan(fmt,args);
    va_end(args);
    }
  return result;
  }


// Write a formatted registry entry
FXint FXSettings::writeFormatEntry(const FXchar* section,const FXchar* name,const FXchar* fmt,...){
  FXint result;
  va_list args;
  va_start(args,fmt);
  result=at(section).at(name,true).vformat(fmt,args);
  va_end(args);
  return result;
  }


// Write a formatted registry entry
FXint FXSettings::writeFormatEntry(const FXString& section,const FXchar* name,const FXchar* fmt,...){
  FXint result;
  va_list args;
  va_start(args,fmt);
  result=at(section).at(name,true).vformat(fmt,args);
  va_end(args);
  return result;
  }


// Write a formatted registry entry
FXint FXSettings::writeFormatEntry(const FXString& section,const FXString& name,const FXchar* fmt,...){
  FXint result;
  va_list args;
  va_start(args,fmt);
  result=at(section).at(name,true).vformat(fmt,args);
  va_end(args);
  return result;
  }


// Read a string-valued registry entry
const FXchar* FXSettings::readStringEntry(const FXchar* section,const FXchar* name,const FXchar* def) const {
  const FXStringDictionary& dict=at(section);
  FXival slot=dict.find(name);
  if(0<=slot){
    return dict.data(slot).text();      // Use value at slot even if value was empty string!
    }
  return def;
  }


// Read a string-valued registry entry
const FXchar* FXSettings::readStringEntry(const FXString& section,const FXchar* name,const FXchar* def) const {
  return readStringEntry(section.text(),name,def);
  }


// Read a string-valued registry entry
const FXchar* FXSettings::readStringEntry(const FXString& section,const FXString& name,const FXchar* def) const {
  return readStringEntry(section.text(),name.text(),def);
  }


// Write a string-valued registry entry
FXbool FXSettings::writeStringEntry(const FXchar* section,const FXchar* name,const FXchar* val){
  at(section).at(name,true)=val;
  return true;
  }


// Write a string-valued registry entry
FXbool FXSettings::writeStringEntry(const FXString& section,const FXchar* name,const FXchar* val){
  return writeStringEntry(section.text(),name,val);
  }


// Write a string-valued registry entry
FXbool FXSettings::writeStringEntry(const FXString& section,const FXString& name,const FXchar* val){
  return writeStringEntry(section.text(),name.text(),val);
  }


// Read a int-valued registry entry
FXint FXSettings::readIntEntry(const FXchar* section,const FXchar* name,FXint def) const {
  const FXString& value=at(section).at(name);
  if(!value.empty()){
    FXint result;
    FXbool ok;
    result=value.toInt(10,&ok);
    if(ok) return result;
    }
  return def;
  }


// Read a int-valued registry entry
FXint FXSettings::readIntEntry(const FXString& section,const FXchar* name,FXint def) const {
  return readIntEntry(section.text(),name,def);
  }


// Read a int-valued registry entry
FXint FXSettings::readIntEntry(const FXString& section,const FXString& name,FXint def) const {
  return readIntEntry(section.text(),name.text(),def);
  }


// Write a int-valued registry entry
FXbool FXSettings::writeIntEntry(const FXchar* section,const FXchar* name,FXint val){
  at(section).at(name,true).fromInt(val);
  return true;
  }


// Write a int-valued registry entry
FXbool FXSettings::writeIntEntry(const FXString& section,const FXchar* name,FXint val){
  return writeIntEntry(section.text(),name,val);
  }


// Write a int-valued registry entry
FXbool FXSettings::writeIntEntry(const FXString& section,const FXString& name,FXint val){
  return writeIntEntry(section.text(),name.text(),val);
  }


// Read a unsigned int-valued registry entry
FXuint FXSettings::readUIntEntry(const FXchar* section,const FXchar* name,FXuint def) const {
  const FXString& value=at(section).at(name);
  if(!value.empty()){
    FXuint result;
    FXbool ok;
    result=value.toUInt(10,&ok);
    if(ok) return result;
    }
  return def;
  }


// Read a unsigned int-valued registry entry
FXuint FXSettings::readUIntEntry(const FXString& section,const FXchar* name,FXuint def) const {
  return readUIntEntry(section.text(),name,def);
  }


// Read a unsigned int-valued registry entry
FXuint FXSettings::readUIntEntry(const FXString& section,const FXString& name,FXuint def) const {
  return readUIntEntry(section.text(),name.text(),def);
  }


// Write a unsigned int-valued registry entry
FXbool FXSettings::writeUIntEntry(const FXchar* section,const FXchar* name,FXuint val){
  at(section).at(name,true).fromUInt(val);
  return true;
  }

// Write a unsigned int-valued registry entry
FXbool FXSettings::writeUIntEntry(const FXString& section,const FXchar* name,FXuint val){
  return writeUIntEntry(section.text(),name,val);
  }


// Write a unsigned int-valued registry entry
FXbool FXSettings::writeUIntEntry(const FXString& section,const FXString& name,FXuint val){
  return writeUIntEntry(section.text(),name.text(),val);
  }


// Read a 64-bit long integer registry entry
FXlong FXSettings::readLongEntry(const FXchar* section,const FXchar* name,FXlong def) const {
  const FXString& value=at(section).at(name);
  if(!value.empty()){
    FXlong result;
    FXbool ok;
    result=value.toLong(10,&ok);
    if(ok) return result;
    }
  return def;
  }


// Read a 64-bit long integer registry entry
FXlong FXSettings::readLongEntry(const FXString& section,const FXchar* name,FXlong def) const {
  return readLongEntry(section.text(),name,def);
  }


// Read a 64-bit long integer registry entry
FXlong FXSettings::readLongEntry(const FXString& section,const FXString& name,FXlong def) const {
  return readLongEntry(section.text(),name.text(),def);
  }


// Write a 64-bit long integer registry entry
FXbool FXSettings::writeLongEntry(const FXchar* section,const FXchar* name,FXlong val){
  at(section).at(name,true).fromLong(val);
  return true;
  }


// Write a 64-bit long integer registry entry
FXbool FXSettings::writeLongEntry(const FXString& section,const FXchar* name,FXlong val){
  return writeLongEntry(section.text(),name,val);
  }


// Write a 64-bit long integer registry entry
FXbool FXSettings::writeLongEntry(const FXString& section,const FXString& name,FXlong val){
  return writeLongEntry(section.text(),name.text(),val);
  }


// Read a 64-bit unsigned long integer registry entry
FXulong FXSettings::readULongEntry(const FXchar* section,const FXchar* name,FXulong def) const {
  const FXString& value=at(section).at(name);
  if(!value.empty()){
    FXulong result;
    FXbool ok;
    result=value.toULong(10,&ok);
    if(ok) return result;
    }
  return def;
  }


// Read a 64-bit unsigned long integer registry entry
FXulong FXSettings::readULongEntry(const FXString& section,const FXchar* name,FXulong def) const {
  return readULongEntry(section.text(),name,def);
  }


// Read a 64-bit unsigned long integer registry entry
FXulong FXSettings::readULongEntry(const FXString& section,const FXString& name,FXulong def) const {
  return readULongEntry(section.text(),name.text(),def);
  }


// Write a 64-bit long integer registry entry
FXbool FXSettings::writeULongEntry(const FXchar* section,const FXchar* name,FXulong val){
  at(section).at(name,true).fromULong(val);
  return true;
  }


// Write a 64-bit long integer registry entry
FXbool FXSettings::writeULongEntry(const FXString& section,const FXchar* name,FXulong val){
  return writeULongEntry(section.text(),name,val);
  }


// Write a 64-bit long integer registry entry
FXbool FXSettings::writeULongEntry(const FXString& section,const FXString& name,FXulong val){
  return writeULongEntry(section.text(),name.text(),val);
  }


// Read a double-valued registry entry
FXdouble FXSettings::readRealEntry(const FXchar* section,const FXchar* name,FXdouble def) const {
  const FXString& value=at(section).at(name);
  if(!value.empty()){
    FXdouble result;
    FXbool ok;
    result=value.toDouble(&ok);
    if(ok) return result;
    }
  return def;
  }

// Read a double-valued registry entry
FXdouble FXSettings::readRealEntry(const FXString& section,const FXchar* name,FXdouble def) const {
  return readRealEntry(section.text(),name,def);
  }


// Read a double-valued registry entry
FXdouble FXSettings::readRealEntry(const FXString& section,const FXString& name,FXdouble def) const {
  return readRealEntry(section.text(),name.text(),def);
  }


// Write a double-valued registry entry
FXbool FXSettings::writeRealEntry(const FXchar* section,const FXchar* name,FXdouble val){
  at(section).at(name,true).fromDouble(val,16,2);
  return true;
  }


// Write a double-valued registry entry
FXbool FXSettings::writeRealEntry(const FXString& section,const FXchar* name,FXdouble val){
  return writeRealEntry(section.text(),name,val);
  }


// Write a double-valued registry entry
FXbool FXSettings::writeRealEntry(const FXString& section,const FXString& name,FXdouble val){
  return writeRealEntry(section.text(),name.text(),val);
  }


// Read a color registry entry
FXColor FXSettings::readColorEntry(const FXchar* section,const FXchar* name,FXColor def) const {
  const FXString& value=at(section).at(name);
  if(!value.empty()){
    return colorFromName(value);
    }
  return def;
  }


// Read a color registry entry
FXColor FXSettings::readColorEntry(const FXString& section,const FXchar* name,FXColor def) const {
  return readColorEntry(section.text(),name,def);
  }


// Read a color registry entry
FXColor FXSettings::readColorEntry(const FXString& section,const FXString& name,FXColor def) const {
  return readColorEntry(section.text(),name.text(),def);
  }


// Write a color registry entry
FXbool FXSettings::writeColorEntry(const FXchar* section,const FXchar* name,FXColor val){
  at(section).at(name,true)=nameFromColor(val);
  return true;
  }


// Write a color registry entry
FXbool FXSettings::writeColorEntry(const FXString& section,const FXchar* name,FXColor val){
  return writeColorEntry(section.text(),name,val);
  }


// Write a color registry entry
FXbool FXSettings::writeColorEntry(const FXString& section,const FXString& name,FXColor val){
  return writeColorEntry(section.text(),name.text(),val);
  }


// Read a boolean registry entry
FXbool FXSettings::readBoolEntry(const FXchar* section,const FXchar* name,FXbool def) const {
  const FXString& value=at(section).at(name);
  if(!value.empty()){
    if(FXString::comparecase(value,"true")==0) return true;
    if(FXString::comparecase(value,"false")==0) return false;
    if(FXString::comparecase(value,"yes")==0) return true;
    if(FXString::comparecase(value,"no")==0) return false;
    if(FXString::comparecase(value,"on")==0) return true;
    if(FXString::comparecase(value,"off")==0) return false;
    if(FXString::comparecase(value,"1")==0) return true;
    if(FXString::comparecase(value,"0")==0) return false;
    }
  return def;
  }


// Read a boolean registry entry
FXbool FXSettings::readBoolEntry(const FXString& section,const FXchar* name,FXbool def) const {
  return readBoolEntry(section.text(),name,def);
  }


// Read a boolean registry entry
FXbool FXSettings::readBoolEntry(const FXString& section,const FXString& name,FXbool def) const {
  return readBoolEntry(section.text(),name.text(),def);
  }


// Write a boolean registry entry
FXbool FXSettings::writeBoolEntry(const FXchar* section,const FXchar* name,FXbool val){
  at(section).at(name,true)=val?"true":"false";
  return true;
  }


// Write a boolean registry entry
FXbool FXSettings::writeBoolEntry(const FXString& section,const FXchar* name,FXbool val){
  return writeBoolEntry(section.text(),name,val);
  }


// Write a boolean registry entry
FXbool FXSettings::writeBoolEntry(const FXString& section,const FXString& name,FXbool val){
  return writeBoolEntry(section.text(),name.text(),val);
  }


// See if entry exists
FXbool FXSettings::existingEntry(const FXchar* section,const FXchar* name) const {
  return 0<=at(section).find(name);
  }


// See if entry exists
FXbool FXSettings::existingEntry(const FXString& section,const FXchar* name) const {
  return existingEntry(section.text(),name);
  }


// See if entry exists
FXbool FXSettings::existingEntry(const FXString& section,const FXString& name) const {
  return existingEntry(section.text(),name.text());
  }


// See if section exists
FXbool FXSettings::existingSection(const FXchar* section) const {
  return 0<=find(section);
  }


// See if section exists
FXbool FXSettings::existingSection(const FXString& section) const {
  return existingSection(section.text());
  }


// Delete a registry entry
void FXSettings::deleteEntry(const FXchar* section,const FXchar* name){
  at(section).remove(name);
  }


// Delete a registry entry
void FXSettings::deleteEntry(const FXString& section,const FXchar* name){
  deleteEntry(section.text(),name);
  }


// Delete a registry entry
void FXSettings::deleteEntry(const FXString& section,const FXString& name){
  deleteEntry(section.text(),name.text());
  }


// Delete section
void FXSettings::deleteSection(const FXchar* section){
  if(__unlikely(!section || !*section)){ throw FXRangeException("FXSettings::deleteSection: null or empty key\n"); }
  if(__likely(!empty())){
    FXuval p,b,h,x;
    p=b=h=FXString::hash(section);
    FXASSERT(h);
    while(table[x=p&(no()-1)].hash!=h || table[x].key!=section){
      if(!table[x].hash) return;
      p=(p<<2)+p+b+1;
      b>>=BSHIFT;
      }
    table[x].key.clear();                                 // Void the slot (not empty!)
    table[x].data.clear();
    used(used()-1);
    modified=true;
    if(__unlikely(used()<=(no()>>2))) resize(no()>>1);
    }
  }


// Delete section
void FXSettings::deleteSection(const FXString& section){
  deleteSection(section.text());
  }


// Clear all sections
void FXSettings::clear(){
  modified=true;
  no(1);
  }


// Clean up
FXSettings::~FXSettings(){
  clear();
  }

}