Options: Fix modifying or deleting of value returned by getenv
[roofball.git] / src / optionsfile.h
blob7167130abb37a756eddcdc546504ef9e608b626f
1 #ifndef OPTIONSFILE_H
2 #define OPTIONSFILE_H
4 #include <fstream>
5 #include <cstring>
6 using namespace std;
8 typedef unsigned long long int UIntT;
9 typedef signed long long int SIntT;
10 typedef long double FloatT;
11 typedef const char *StringT;
13 class OptionsFile : private fstream {
14 OptionsFile(const OptionsFile &);
15 OptionsFile &operator=(const OptionsFile &);
17 public:
18 OptionsFile(const char *file, bool load = true, bool saveOnDel = false);
19 ~OptionsFile();
21 void Load();
22 void Save();
23 inline bool IsSaved() const;
25 void Clear();
26 bool IsClear() const;
28 void SetUInt(const char *sect, const char *key, UIntT val);
29 void SetUIntHex(const char *sect, const char *key, UIntT val);
30 void SetSInt(const char *sect, const char *key, SIntT val);
31 void SetFloat(const char *sect, const char *key, FloatT val);
32 void SetString(const char *sect, const char *key, StringT ptr);
34 UIntT GetUInt(const char *sect, const char *key) const;
35 SIntT GetSInt(const char *sect, const char *key) const;
36 FloatT GetFloat(const char *sect, const char *key) const;
37 StringT GetString(const char *sect, const char *key) const;
39 void Unset(const char *sect, const char *key);
40 bool Has(const char *sect, const char *key) const { return (GetString(sect, key) != NULL); }
42 private:
43 class StrList {
44 StrList(const StrList &);
45 StrList &operator=(const StrList &);
47 public:
48 StrList();
49 ~StrList();
51 void Clear();
52 bool IsClear() const;
54 void Set(const char *key, const char *val);
55 char *Get(const char *key) const;
56 void Unset(const char *key);
58 void StartPoll();
59 int PollNext(char **, char **);
61 private:
62 struct Node {
63 char *keyword;
64 char *value;
65 Node *next;
66 } *head, *cur;
67 } opts;
68 char *fileName;
69 bool autoSave, isSaved;
71 void Set(const char *sect, const char *key, const char *val);
72 char *Get(const char *sect, const char *key) const;
73 char *CreateKeyword(const char *sect, const char *key) const;
74 void SeparateKeyword(const char *keyword, char **sect, char **key) const;
75 int NextSignificant();
76 void AddChar(char *, char, size_t);
77 void ParseString(char *, size_t);
80 bool OptionsFile::IsSaved() const {
81 return isSaved;
84 #endif // OPTIONSFILE_H