Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

SettingsStore.cpp

Go to the documentation of this file.
00001 // SettingsStore.cpp
00002 //
00004 //
00005 // Copyright (c) 2002 Iain Murray
00006 //
00008 
00009 
00010 
00011 
00012 #include "SettingsStore.h"
00013 
00014 using namespace std;
00015 
00016 /* TODO: Consider using Template functions to make this neater. */
00017 
00018 
00019 CSettingsStore::~CSettingsStore()
00020 {
00021 }
00022 
00023 
00024 bool CSettingsStore::GetBoolOption(const string& Key)
00025 {
00026         if (BoolMap.find(Key)==BoolMap.end()) {
00027                 bool Value = false;
00028                 LoadSetting(Key, &Value);
00029                 BoolMap[Key] = Value;
00030         }
00031         
00032         return BoolMap[Key];
00033 }
00034 
00035 
00036 long CSettingsStore::GetLongOption(const string& Key)
00037 {
00038         if (LongMap.find(Key)==LongMap.end()) {
00039                 long Value = 0l;
00040                 LoadSetting(Key, &Value);
00041                 LongMap[Key] = Value;
00042         }
00043         
00044         return LongMap[Key];
00045 }
00046 
00047 
00048 string& CSettingsStore::GetStringOption(const string& Key)
00049 {
00050         if (StringMap.find(Key)==StringMap.end()) {
00051                 string Value = "";
00052                 LoadSetting(Key, &Value);
00053                 StringMap[Key] = Value;
00054         }
00055         
00056         return StringMap[Key];
00057 }
00058 
00059 
00060 void CSettingsStore::SetBoolOption(const string& Key, bool Value)
00061 {
00062         BoolMap[Key] = Value;
00063         SaveSetting(Key, Value);
00064 }
00065 
00066 
00067 void CSettingsStore::SetLongOption(const string& Key, long Value)
00068 {
00069         LongMap[Key] = Value;
00070         SaveSetting(Key, Value);
00071 }
00072 
00073 
00074 void CSettingsStore::SetStringOption(const string& Key, const string& Value)
00075 {
00076         StringMap[Key] = Value;
00077         SaveSetting(Key, Value);
00078 }
00079 
00080 
00081 void CSettingsStore::SetBoolDefault(const string& Key, bool Value)
00082 {
00083         bool TmpValue;
00084         if ( (BoolMap.find(Key)==BoolMap.end()) && (!LoadSetting(Key, &TmpValue)) )
00085                 SetBoolOption(Key, Value);
00086 }
00087 
00088 
00089 void CSettingsStore::SetLongDefault(const string& Key, long Value)
00090 {
00091         long TmpValue;
00092         if ( (LongMap.find(Key)==LongMap.end()) && (!LoadSetting(Key, &TmpValue)) )
00093                 SetLongOption(Key, Value);
00094 }
00095 
00096 
00097 void CSettingsStore::SetStringDefault(const string& Key, const string& Value)
00098 {
00099         string TmpValue;
00100         if ( (StringMap.find(Key)==StringMap.end()) && (!LoadSetting(Key, &TmpValue)) )
00101                 SetStringOption(Key, Value);
00102 }
00103 
00104 
00105 /* Private functions -- Settings are not saved between sessions unless these
00106 functions are over-ridden.
00107 --------------------------------------------------------------------------*/
00108 
00109 
00110 bool CSettingsStore::LoadSetting(const string& , bool* )
00111 {
00112         return false;
00113 }
00114 
00115 
00116 bool CSettingsStore::LoadSetting(const string& , long* )
00117 {
00118         return false;
00119 }
00120 
00121 
00122 bool CSettingsStore::LoadSetting(const string& , string* )
00123 {
00124         return false;
00125 }
00126 
00127 
00128 void CSettingsStore::SaveSetting(const string& , bool )
00129 {
00130 }
00131 
00132 
00133 void CSettingsStore::SaveSetting(const string& , long )
00134 {
00135 }
00136 
00137 
00138 void CSettingsStore::SaveSetting(const string& , const string& )
00139 {
00140 }

Generated on Sat Nov 5 16:16:00 2005 for OPIE by  doxygen 1.4.2