-
Notifications
You must be signed in to change notification settings - Fork 5
/
configtest.cpp
97 lines (77 loc) · 2.09 KB
/
configtest.cpp
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
#include <iostream>
#include "configdb.h"
#include "hackstream.h"
class MyClassThatNeedsConfigData : public ConfigDB
{
public:
MyClassThatNeedsConfigData(ConfigFile *myfile)
: ConfigDB(Template)
{
new ConfigDBHandler(myfile,"[SectionName]",this);
// (This object is owned by the ConfigFile and will be freed by it.)
}
void MemberFunction()
{
std::cout << "Int value: " << FindInt("AnIntValue") << std::endl;
}
private:
static ConfigTemplate Template[];
};
class MyOtherClass : public ConfigDB
{
public:
MyOtherClass(ConfigFile *myfile)
: ConfigDB(Template)
{
new ConfigDBHandler(myfile,"[SectionName]",this);
}
void MemberFunction()
{
std::cout << "Int value: " << FindInt("AnIntValue") << std::endl;
}
MyOtherClass &operator=(MyClassThatNeedsConfigData &other)
{
this->ConfigDB::operator=(other);
return(*this);
}
private:
static ConfigTemplate Template[];
};
ConfigTemplate MyClassThatNeedsConfigData::Template[]=
{
ConfigTemplate("AnIntValue",int(17)), // Default value is 17
ConfigTemplate("AStringValue","Default"),
ConfigTemplate("AFloatValue",float(3.5)),
ConfigTemplate() // NULL terminated...
};
ConfigTemplate MyOtherClass::Template[]=
{
ConfigTemplate("AnIntValue",int(13)), // Default value is 17
ConfigTemplate("AStringValue","DefString"),
ConfigTemplate("AFloatValue",float(1.3)),
ConfigTemplate() // NULL terminated...
};
int main(int argc,char **argv)
{
if(argc>1)
{
char buf[100];
hack_istream stream(argv[1]);
stream.getline(buf,100);
std::cerr << "First line of file: " << buf << std::endl;
}
ConfigFile myconfig;
MyClassThatNeedsConfigData myclass(&myconfig);
// myconfig.ParseConfigFile("/path/to/myconfigfile");
myclass.MemberFunction();
std::cout << "String value: " << myclass.FindString("AStringValue") << std::endl;
myclass.SetFloat("AFloatValue",1.45);
// myconfig.SaveConfigFile("/path/to/myconfigfile");
ConfigFile dummy;
MyOtherClass otherclass(&dummy);
otherclass.MemberFunction();
std::cout << "Copying data from myclass to otherclass..." << std::endl;
otherclass=myclass;
otherclass.MemberFunction();
return(0);
}