00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef SettingsManagerH
00033 #define SettingsManagerH
00034
00035 #include <zeusbase/System/ZObject.h>
00036 #include <zeusbase/System/SingleLinkedList.hpp>
00037 #include <zeusbase/System/Interfaces/ISettingsManager.hpp>
00038
00039
00040 #if defined(_MSC_VER)
00041 #include <zeusbase/System/XMLFile.h>
00042 #include <zeusbase/System/Interfaces/IXMLDocument.hpp>
00043 #include <zeusbase/System/Interfaces/IXMLNode.hpp>
00044 #endif
00045
00046 #define SettingsManager TSettingsManager::getInstance()
00047 #define UserData getUserData()
00048
00049 BEGIN_NAMESPACE_Zeus
00050
00051 #ifndef _MSC_VER
00052 class TXMLFile;
00053 class IXMLDocument;
00054 class IXMLNode;
00055 class INotifyObserver;
00056 #endif
00057
00058 class TCriticalSection;
00059
00060
00064
00065 zeusbase_class TSettingsManager : public TZObject, public ISettingsManager
00066 {
00067 public:
00068
00071
00072 zeusbase_class TUserData : public TZObject
00073 {
00074 public:
00075 TUserData();
00076 virtual ~TUserData();
00077
00078 Retval commit();
00079 void getPropertyNamesByNameSpace(const IString& rNameSpace, IStringList& rList) const ;
00080 void getPropertyNamesByNameSpace(const wchar_t* pNameSpace, IStringList& rList) const ;
00081
00082 Retval readBool(const IString& rKey, bool& rValue, bool bDefault = false);
00083 Retval readInt(const IString& rKey, Int& rValue, Int iDefault = 0);
00084 Retval readUint(const IString& rKey, Uint& rValue, Uint uiDefault = 0);
00085 Retval readFloat(const IString& rKey, Float& rValue, Float fDefault = 0.0);
00086 Retval readString(const IString& rKey, IString& rValue, TString strDefault=L"");
00087 inline Retval readBool(const wchar_t* pKey, bool& rValue, bool bDefault = false) { return readBool(TString(pKey), rValue, bDefault); }
00088 inline Retval readInt(const wchar_t* pKey, Int& rValue, Int iDefault = 0) { return readInt(TString(pKey), rValue, iDefault); }
00089 inline Retval readUint(const wchar_t* pKey, Uint& rValue, Uint uiDefault = 0) { return readUint(TString(pKey), rValue, uiDefault); }
00090 inline Retval readFloat(const wchar_t* pKey, Float& rValue, Float fDefault = 0.0) { return readFloat(TString(pKey), rValue, fDefault); }
00091 inline Retval readString(const wchar_t* pKey, IString& rValue, TString strDefault=L"") { return readString(TString(pKey), rValue, strDefault); }
00092
00093 Retval writeBool(const IString& rKey, bool bValue);
00094 Retval writeInt(const IString& rKey, Int iValue);
00095 Retval writeUint(const IString& rKey, Uint uiValue);
00096 Retval writeFloat(const IString& rKey, Float fValue);
00097 Retval writeString(const IString& rKey, const IString& rValue);
00098 inline Retval writeBool(const wchar_t* pKey, bool bValue) { return writeBool(TString(pKey), bValue); }
00099 inline Retval writeInt(const wchar_t* pKey, Int iValue) { return writeInt(TString(pKey), iValue); }
00100 inline Retval writeUint(const wchar_t* pKey, Uint uiValue) { return writeUint(TString(pKey), uiValue); }
00101 inline Retval writeFloat(const wchar_t* pKey, Float fValue) { return writeFloat(TString(pKey), fValue); }
00102 inline Retval writeString(const wchar_t* pKey, const IString& rValue) { return writeString(TString(pKey), rValue); }
00103
00104 Retval getUserDataNode(const IString& rName, IXMLNode*& rpNode);
00105
00106
00107 void setDocument(NAMESPACE_Zeus::IXMLDocument& rDocument);
00108 void releaseDocument();
00109
00110 private:
00112 TAutoPtr<NAMESPACE_Zeus::IXMLDocument> m_ptrDocument;
00114 TAutoPtr<IXMLNode> m_ptrMainNode;
00116 TCriticalSection& m_rLock;
00117
00118 };
00119
00120
00121 static TSettingsManager& getInstance();
00122
00123 TUserData& getUserData();
00124 void setPropertyInterface(IPropertyAccess& rIface);
00125 Retval setUserXMLFile(const IString& rFileName);
00126 Retval setUserXMLFile(TXMLFile& rFile);
00127 void releaseSourceInterfaces();
00128 void releasePropertyInterfaces();
00129 void releaseUserXMLFile();
00130
00131 void releaseDelegationInterface();
00132 void setDelegationInterface(ISettingsManager& rIface);
00133 TString completePathProperty(const TString& strPropName, const TString& strBasePath, bool bCreate = false);
00134
00135
00136 Retval readBoolProperty(const IString& rKey, bool& rValue, bool bDefault = false);
00137 Retval readIntProperty(const IString& rKey, Int& rValue, Int iDefault = 0);
00138 Retval readUintProperty(const IString& rKey, Uint& rValue, Uint uiDefault = 0);
00139 Retval readFloatProperty(const IString& rKey, Float& rValue, Float fDefault = 0.0);
00140 Retval readStringProperty(const IString& rKey, IString& rValue, TString strDefault=L"");
00141 inline Retval readBoolProperty(const wchar_t* pKey, bool& rValue, bool bDefault = false) { return readBoolProperty(TString(pKey), rValue, bDefault); }
00142 inline Retval readIntProperty(const wchar_t* pKey, Int& rValue, Int iDefault = 0) { return readIntProperty(TString(pKey), rValue, iDefault); }
00143 inline Retval readUintProperty(const wchar_t* pKey, Uint& rValue, Uint uiDefault = 0) { return readUintProperty(TString(pKey), rValue, uiDefault); }
00144 inline Retval readFloatProperty(const wchar_t* pKey, Float& rValue, Float fDefault = 0.0) { return readFloatProperty(TString(pKey), rValue, fDefault); }
00145 inline Retval readStringProperty(const wchar_t* pKey, IString& rValue, TString strDefault=L"") { return readStringProperty(TString(pKey), rValue, strDefault); }
00146
00147 Retval writeBoolProperty(const IString& rKey, bool bValue);
00148 Retval writeIntProperty(const IString& rKey, Int iValue);
00149 Retval writeUintProperty(const IString& rKey, Uint uiValue);
00150 Retval writeFloatProperty(const IString& rKey, Float fValue);
00151 Retval writeStringProperty(const IString& rKey, const IString& rValue);
00152 inline Retval writeBoolProperty(const wchar_t* pKey, bool bValue) { return writeBoolProperty(TString(pKey), bValue); }
00153 inline Retval writeIntProperty(const wchar_t* pKey, Int iValue) { return writeIntProperty(TString(pKey), iValue); }
00154 inline Retval writeUintProperty(const wchar_t* pKey, Uint uiValue) { return writeUintProperty(TString(pKey), uiValue); }
00155 inline Retval writeFloatProperty(const wchar_t* pKey, Float fValue) { return writeFloatProperty(TString(pKey), fValue); }
00156 inline Retval writeStringProperty(const wchar_t* pKey, const IString& rValue) { return writeStringProperty(TString(pKey), rValue); }
00157
00158
00159
00160 virtual Retval MQUALIFIER getUserDocument(NAMESPACE_Zeus::IXMLDocument*& rpDocument) const;
00161 virtual void MQUALIFIER notifyObservers();
00162 virtual void MQUALIFIER attach(INotifyObserver& rObserver);
00163 virtual void MQUALIFIER detach(INotifyObserver& rObserver);
00164
00165
00166 virtual Retval MQUALIFIER addProperty(const IString& rName, const IString& rValue);
00167 virtual bool MQUALIFIER existsProperty(const IString& rName)const ;
00168 virtual void MQUALIFIER getPropertyNames(IStringList& rList)const ;
00169 virtual void MQUALIFIER getPropertyNamesByNameSpace(const IString& rNameSpace, IStringList& rList) const ;
00170 virtual Retval MQUALIFIER getPropertyValue(const IString& rName, IString& rValue)const ;
00171 virtual Retval MQUALIFIER setPropertyValue(const IString& rName, const IString& rValue);
00172 virtual Retval MQUALIFIER getPropertyPathValue(const IString& rName, IString& rValue)const;
00173 virtual Retval MQUALIFIER getPropertyFileValue(const IString& rName, IString& rValue)const;
00174
00175
00176 MEMORY_MANAGER_DECL
00177
00178 private:
00179
00181 static TAutoPtr<TSettingsManager> m_ptrInstance;
00183 TAutoPtr<ISettingsManager> m_ptrDelegation;
00185 TAutoPtr<IPropertyAccess> m_ptrSourceInterface;
00187 TAutoPtr<TXMLFile> m_ptrUserFile;
00189 TUserData m_UserData;
00191 TSingleLinkedList<INotifyObserver*> m_lstObservers;
00193 TCriticalSection& m_rLock;
00194
00196
00197 #ifdef _MSC_VER
00198 public:
00199 #endif
00200
00201
00202 TSettingsManager();
00203 virtual ~TSettingsManager();
00204 };
00205
00206
00207
00210
00211 inline TSettingsManager& TSettingsManager::getInstance()
00212 {
00213 return *m_ptrInstance;
00214 }
00215
00216
00219
00220 inline TSettingsManager::TUserData& TSettingsManager::getUserData()
00221 {
00222 return m_UserData;
00223 }
00224
00225
00233
00234 inline Retval TSettingsManager::readBoolProperty(const IString& rKey, bool& rValue, bool bDefault )
00235 {
00236 Int iValue = 0;
00237 Retval retValue = readIntProperty(rKey, iValue, bDefault);
00238 rValue = (iValue == 0 ? false : true);
00239 return retValue;
00240 }
00241
00242
00250
00251 inline Retval TSettingsManager::readIntProperty(const IString& rKey, Int& rValue, Int iDefault )
00252 {
00253 TString strValue;
00254 Retval retValue = readStringProperty(rKey, strValue, TString(iDefault));
00255 rValue = strValue.toInt();
00256 return retValue;
00257 }
00258
00259
00267
00268 inline Retval TSettingsManager::readUintProperty(const IString& rKey, Uint& rValue, Uint uiDefault )
00269 {
00270 TString strValue;
00271 Retval retValue = readStringProperty(rKey, strValue, TString(uiDefault));
00272 rValue = strValue.toUint();
00273 return retValue;
00274 }
00275
00276
00284
00285 inline Retval TSettingsManager::readFloatProperty(const IString& rKey, Float& rValue, Float fDefault )
00286 {
00287 TString strValue;
00288 Retval retValue = readStringProperty(rKey, strValue, TString(fDefault));
00289 rValue = strValue.toFloat();
00290 return retValue;
00291 }
00292
00293
00300
00301 inline Retval TSettingsManager::writeBoolProperty(const IString& rKey, bool bValue)
00302 {
00303 return writeIntProperty(rKey, bValue ? 1 : 0);
00304 }
00305
00306
00313
00314 inline Retval TSettingsManager::writeIntProperty(const IString& rKey, Int iValue)
00315 {
00316 return setPropertyValue(rKey, TString(iValue));
00317 }
00318
00319
00326
00327 inline Retval TSettingsManager::writeUintProperty(const IString& rKey, Uint uiValue)
00328 {
00329 return setPropertyValue(rKey, TString(uiValue));
00330 }
00331
00332
00339
00340 inline Retval TSettingsManager::writeFloatProperty(const IString& rKey, Float fValue)
00341 {
00342 return setPropertyValue(rKey, TString(fValue));
00343 }
00344
00345
00352
00353 inline Retval TSettingsManager::writeStringProperty(const IString& rKey, const IString& rValue)
00354 {
00355 return setPropertyValue(rKey, rValue);
00356 }
00357
00358
00359
00360
00363
00364 inline void TSettingsManager::TUserData::getPropertyNamesByNameSpace(const wchar_t* pNameSpace, IStringList& rList) const
00365 {
00366 getPropertyNamesByNameSpace(TString(pNameSpace), rList);
00367 }
00368
00369
00377
00378 inline Retval TSettingsManager::TUserData::readBool(const IString& rKey, bool& rValue,
00379 bool bDefault )
00380 {
00381 Int iValue = 0;
00382 Retval retValue = readInt(rKey, iValue, bDefault);
00383 rValue = (iValue == 0 ? false : true);
00384 return retValue;
00385 }
00386
00387
00395
00396 inline Retval TSettingsManager::TUserData::readInt(const IString& rKey, Int& rValue, Int iDefault )
00397 {
00398 TString strValue;
00399 Retval retValue = readString(rKey, strValue, TString(iDefault));
00400 rValue = strValue.toInt();
00401 return retValue;
00402 }
00403
00404
00412
00413 inline Retval TSettingsManager::TUserData::readUint(const IString& rKey, Uint& rValue, Uint uiDefault )
00414 {
00415 TString strValue;
00416 Retval retValue = readString(rKey, strValue, TString(uiDefault));
00417 rValue = strValue.toUint();
00418 return retValue;
00419 }
00420
00421
00422
00430
00431 inline Retval TSettingsManager::TUserData::readFloat(const IString& rKey, Float& rValue, Float fDefault )
00432 {
00433 TString strValue;
00434 Retval retValue = readString(rKey, strValue, TString(fDefault));
00435 rValue = strValue.toFloat();
00436 return retValue;
00437 }
00438
00439
00446
00447 inline Retval TSettingsManager::TUserData::writeBool(const IString& rKey, bool bValue)
00448 {
00449 return writeInt(rKey, bValue ? 1 : 0);
00450 }
00451
00452
00459
00460 inline Retval TSettingsManager::TUserData::writeInt(const IString& rKey, Int iValue)
00461 {
00462 return writeString(rKey, TString(iValue));
00463 }
00464
00465
00472
00473 inline Retval TSettingsManager::TUserData::writeUint(const IString& rKey, Uint uiValue)
00474 {
00475 return writeString(rKey, TString(uiValue));
00476 }
00477
00478
00479
00486
00487 inline Retval TSettingsManager::TUserData::writeFloat(const IString& rKey, Float fValue)
00488 {
00489 return writeString(rKey, TString(fValue));
00490 }
00491
00492
00493 END_NAMESPACE_Zeus
00494
00495 #endif