247
247
// the map of all configuration items
248
248
typedef std::map< tString, tConfItemBase * > tConfItemMap;
249
249
static tConfItemMap const & GetConfItemMap();
251
252
static tConfItemMap & ConfItemMap();
255
// Lets steal this from 0.4 for now.
257
typedef void callbackFunc(void);
259
callbackFunc *callback;
261
void ExecuteCallback() {if (callback != 0) (*callback)(); }
254
265
// static tConfItemBase* s_ConfItemAnchor;
255
266
//static tConfItemBase* Anchor(){return dynamic_cast<tConfItemBase *>(s_ConfItemAnchor);}
256
267
static bool printChange; //!< if set, setting changes are printed to the console and, if printErrors is set as well, suggestions of typo fixes are given.
257
268
static bool printErrors; //!< if set, unknown settings are pointed out.
259
270
tConfItemBase(const char *title, const tOutput& help);
260
tConfItemBase(const char *title);
271
tConfItemBase(const char *title);
262
273
virtual ~tConfItemBase();
264
275
tString const & GetTitle() const {
268
/*void SetValue(tString newValue)
279
/*void SetValue(tString newValue)
274
285
tAccessLevel GetRequiredLevel() const { return requiredLevel; }
275
286
tAccessLevel GetSetLevel() const { return setLevel; }
276
void SetSetLevel( tAccessLevel level ) { setLevel = level; }
287
void SetSetLevel( tAccessLevel level ) { setLevel = level; }
278
289
static int EatWhitespace(std::istream &s); // eat whitespace from stream; return: first non-whitespace char
280
static void ExportAll();
291
static void ExportAll();
281
292
static void SaveAll(std::ostream &s, bool all=false);
282
293
static void LoadAll(std::istream &s, bool record = false ); //! loads configuration from stream
283
294
static void LoadAll(std::ifstream &s, bool record = false ); //! loads configuration from file
284
295
static void LoadLine(std::istream &s); //! loads one configuration line
285
296
static bool LoadPlayback( bool print = false ); //! loads configuration from playback
286
297
static void DocAll(std::ostream &s);
287
static int AccessLevel(std::istream &s); //! Returns access level needed for command. -1 if command not found.
288
static void WriteAllToFile();
289
static void WriteAllLevelsToFile();
290
static void WriteChangedToFile();
291
static tString FindConfigItem(tString name); //! Returns the config name of the searching string name
292
static void SetAllAccessLevel(int newLevel);
294
static void DownloadSettings_Go(nMessage &m);
295
static void DownloadConfig_Go(nMessage &m);
296
static void DownloadSettings_To(int peer);
298
static int AccessLevel(std::istream &s); //! Returns access level needed for command. -1 if command not found.
299
static void WriteAllToFile();
300
static void WriteAllLevelsToFile();
301
static void WriteChangedToFile();
302
static tString FindConfigItem(tString name); //! Returns the config name of the searching string name
303
static tConfItemBase *FindConfigItem2(tString const &name); // FindConfigitem specifically for the use of "TOGGLE." Gotta replace this. Seems too hacky.
304
static void SetAllAccessLevel(int newLevel);
306
static void DownloadSettings_Go(nMessage &m);
307
static void DownloadConfig_Go(nMessage &m);
308
static void DownloadSettings_To(int peer);
297
309
static void DownloadConfig_To(tString file, int peer);
299
311
// helper functions for files (use these, they manage recording and playback properly)
396
408
tConfItem(T &t):tConfItemBase(""),target(&t), shouldChangeFunc_(NULL) {}
398
410
tConfItem(const char *title,const tOutput& help,T& t)
399
:tConfItemBase(title,help),target(&t), shouldChangeFunc_(NULL) {
400
/*tConfItemMap & confmap = ConfItemMap();
411
:tConfItemBase(title,help),target(&t), shouldChangeFunc_(NULL) {
412
/*tConfItemMap & confmap = ConfItemMap();
401
413
for(tConfItemMap::iterator iter = confmap.begin(); iter != confmap.end() ; ++iter)
403
tConfItemBase * ci = (*iter).second;
404
if (ci->GetTitle() == title)
408
ci->SetValue(newValue);
415
tConfItemBase * ci = (*iter).second;
416
if (ci->GetTitle() == title)
420
ci->SetValue(newValue);
414
426
tConfItem(const char *title,T& t)
415
:tConfItemBase(title),target(&t), shouldChangeFunc_(NULL) {
416
/*tConfItemMap & confmap = ConfItemMap();
427
:tConfItemBase(title),target(&t), shouldChangeFunc_(NULL) {
428
/*tConfItemMap & confmap = ConfItemMap();
417
429
for(tConfItemMap::iterator iter = confmap.begin(); iter != confmap.end() ; ++iter)
419
tConfItemBase * ci = (*iter).second;
420
if (ci->GetTitle() == title)
424
ci->SetValue(newValue);
431
tConfItemBase * ci = (*iter).second;
432
if (ci->GetTitle() == title)
436
ci->SetValue(newValue);
430
442
tConfItem(const char*title, T& t, ShouldChangeFuncT changeFunc)
431
:tConfItemBase(title),target(&t),shouldChangeFunc_(changeFunc) {
432
/*tConfItemMap & confmap = ConfItemMap();
443
:tConfItemBase(title),target(&t),shouldChangeFunc_(changeFunc) {
444
/*tConfItemMap & confmap = ConfItemMap();
433
445
for(tConfItemMap::iterator iter = confmap.begin(); iter != confmap.end() ; ++iter)
435
tConfItemBase * ci = (*iter).second;
436
if (ci->GetTitle() == title)
440
ci->SetValue(newValue);
447
tConfItemBase * ci = (*iter).second;
448
if (ci->GetTitle() == title)
452
ci->SetValue(newValue);
446
458
virtual ~tConfItem(){}
480
492
s << static_cast< typename tTypeToConfig< T >::TOSTREAM >( value );
495
//Stolen from 0.4. Needed for "TOGGLE" function.
496
void SetVal( T const & val )
498
if (!shouldChangeFunc_ || shouldChangeFunc_( val ))
503
o.SetTemplateParameter(1, title);
504
o.SetTemplateParameter(2, *target);
505
o.SetTemplateParameter(3, val);
506
o << "$config_value_changed";
515
con << tOutput("$config_value_not_changed", title, *target, val);
520
const T *GetTarget() const
483
526
virtual void ReadVal(std::istream &s){
484
527
// eat whitepsace
485
528
int c= EatWhitespace(s);
591
634
virtual ~tConfItemFunc();
593
636
virtual void ReadVal(std::istream &s);
594
virtual void WriteVal(std::ostream &s);
637
virtual void WriteVal(std::ostream &s);
595
638
virtual void FetchVal(tString &val);
599
virtual bool CanSave(){
642
virtual bool CanSave(){
604
// includes a single configuration file by name, searches in var and config directories
605
void st_Include( tString const & file );
647
// includes a single configuration file by name, searches in var and config directories
648
void st_Include( tString const & file );
607
650
void st_LoadConfig();
608
void st_SaveConfig();
609
void st_LoadUserConfig();
651
void st_SaveConfig();
652
void st_LoadUserConfig();
610
653
void st_SaveChangedConfig();
612
655
extern bool st_FirstUse;