-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathini.h
115 lines (115 loc) · 3.06 KB
/
ini.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
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
#pragma once
#include "vector.h"
#include "strings.h"
#include "Crc32.h"
class FileClass;
class Straw;
class Pipe;
struct INIEntry : public Node<INIEntry *>
{
public:
char* Entry; // 000C
char* Value; // 0010
~INIEntry()
{
delete[] Entry;
Entry = 0;
delete[] Value;
Value = 0;
}
INIEntry(char *entry, char *value) : Entry(entry), Value(value)
{
}
int Index_ID()
{
return CRC_String(Entry,0);
}
}; // 0014
struct INISection : public Node<INISection *>
{
public:
char* Section; // 000C
List<INIEntry *> EntryList; // 0010
IndexClass<int,INIEntry *> EntryIndex; // 002C
~INISection()
{
delete[] Section;
EntryList.Delete();
}
INIEntry *Find_Entry(const char *entry)
{
if (entry)
{
int crc = CRC_String(entry,0);
if (EntryIndex.Is_Present(crc))
{
return EntryIndex[crc];
}
}
return 0;
}
INISection(char *section) : Section(section)
{
}
int Index_ID()
{
return CRC_String(Section,0);
}
}; // 0040
class INIClass {
List<INISection *> *SectionList;
IndexClass<int,INISection *> *SectionIndex;
char *Filename;
public:
static void Strip_Comments(char* buffer);
static int CRC(char *string);
void DuplicateCRCError(const char *function,const char* message,const char* entry);
INIClass();
INIClass(FileClass &file);
void Initialize();
void Shutdown();
bool Clear(char* section,char* entry);
int Get_Int(char const *section,char const *entry,int defaultvalue) const;
uint Get_Color_UInt(char const *section, char const *entry, uint defaultvalue) const;
float Get_Float(char const *section,char const *entry,float defaultvalue) const;
bool Get_Bool(char const *section,char const *entry,bool defaultvalue) const;
int Get_String(char const *section,char const *entry,char const *defaultvalue,char *result,int size) const;
StringClass &Get_String(StringClass &str, const char* section, const char* entry, const char* defaultvalue = 0) const;
bool Put_String(const char* section, const char* entry, const char* string);
bool Put_Int(const char* section, const char* entry, int value, int format);
bool Put_Bool(const char* section, const char* entry, bool value);
bool Put_Float(const char* section, const char* entry, float value);
int Entry_Count(char const *section) const;
const char *Get_Entry(char const *section,int index) const;
INIEntry *Find_Entry(const char* section,const char* entry) const;
INISection *Find_Section(const char* section) const;
virtual ~INIClass();
int Load(Straw& ffile);
int Load(FileClass& file);
int Save(FileClass& file);
int Save(Pipe& pipe);
int Section_Count() const;
bool Is_Present(const char *section,const char *entry) const
{
if (entry)
{
return Find_Entry(section,entry) != 0;
}
else
{
return Find_Section(section) != 0;
}
}
bool Section_Present(const char *section) const
{
return Find_Section(section) != 0;
}
List<INISection *> &Get_Section_List()
{
return *SectionList;
}
IndexClass<int,INISection *>&Get_Section_Index()
{
return *SectionIndex;
}
};