@@ -64,17 +64,7 @@ namespace spades {
64
64
if (it == items.end ()){
65
65
Item *item = new Item ();
66
66
item->name = name;
67
-
68
- char buf[2048 ];
69
- buf[2047 ] = 0 ;
70
- SPAssert (pref != NULL );
71
- pref->get (name.c_str (), buf, def.c_str (), 2047 );
72
- SPAssert (buf);
73
-
74
- item->string = buf;
75
-
76
- item->value = static_cast <float >(atof (item->string .c_str ()));
77
- item->intValue = atoi (item->string .c_str ());
67
+ item->loaded = false ;
78
68
79
69
item->desc = desc;
80
70
item->defaultValue = def;
@@ -85,14 +75,35 @@ namespace spades {
85
75
return it->second ;
86
76
}
87
77
78
+ void Settings::Item::Load () {
79
+ if (this ->loaded ){
80
+ return ;
81
+ }
82
+
83
+ char buf[2048 ];
84
+ buf[2047 ] = 0 ;
85
+ SPAssert (pref != NULL );
86
+ pref->get (name.c_str (), buf, defaultValue.c_str (), 2047 );
87
+ SPAssert (buf);
88
+
89
+ this ->string = buf;
90
+
91
+ this ->value = static_cast <float >(atof (this ->string .c_str ()));
92
+ this ->intValue = atoi (this ->string .c_str ());
93
+
94
+ this ->loaded = true ;
95
+ }
96
+
88
97
void Settings::Item::Set (const std::string &str) {
89
98
string = str;
90
99
value = static_cast <float >(atof (str.c_str ()));
91
100
intValue = atoi (str.c_str ());
92
101
93
102
pref->set (name.c_str (), string.c_str ());
103
+ loaded = true ;
94
104
}
95
105
106
+
96
107
void Settings::Item::Set (int v) {
97
108
char buf[256 ];
98
109
sprintf (buf, " %d" , v);
@@ -101,6 +112,7 @@ namespace spades {
101
112
value = (float )v;
102
113
103
114
pref->set (name.c_str (), string.c_str ());
115
+ loaded = true ;
104
116
}
105
117
106
118
void Settings::Item::Set (float v){
@@ -111,6 +123,8 @@ namespace spades {
111
123
value = v;
112
124
113
125
pref->set (name.c_str (), string.c_str ());
126
+
127
+ loaded = true ;
114
128
}
115
129
116
130
Settings::ItemHandle::ItemHandle (const std::string& name,
@@ -139,18 +153,23 @@ namespace spades {
139
153
item->Set (value);
140
154
}
141
155
Settings::ItemHandle::operator std::string () {
156
+ item->Load ();
142
157
return item->string ;
143
158
}
144
159
Settings::ItemHandle::operator int () {
160
+ item->Load ();
145
161
return item->intValue ;
146
162
}
147
163
Settings::ItemHandle::operator float () {
164
+ item->Load ();
148
165
return item->value ;
149
166
}
150
167
Settings::ItemHandle::operator bool () {
168
+ item->Load ();
151
169
return item->intValue != 0 ;
152
170
}
153
171
const char *Settings::ItemHandle::CString () {
172
+ item->Load ();
154
173
return item->string .c_str ();
155
174
}
156
175
std::string Settings::ItemHandle::GetDescription () {
0 commit comments