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
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 #ifndef SettingsManagerH
00070 #define SettingsManagerH
00071
00072
00073 #include <zeusbase/System/ZObject.h>
00074 #include <zeusbase/System/SingleLinkedList.hpp>
00075 #include <zeusbase/System/Interfaces/ISettingsManager.hpp>
00076
00077
00078 #if defined(_MSC_VER)
00079 #include <zeusbase/System/XMLFile.h>
00080 #include <zeusbase/System/Interfaces/IXMLDocument.hpp>
00081 #include <zeusbase/System/Interfaces/IXMLNode.hpp>
00082 #endif
00083
00084 #define SettingsManager TSettingsManager::getInstance()
00085 #define UserData getUserData()
00086
00087 BEGIN_NAMESPACE_Zeus
00088
00089 #ifndef _MSC_VER
00090 class TXMLFile;
00091 class IXMLDocument;
00092 class IXMLNode;
00093 class INotifyObserver;
00094 #endif
00095
00096 class TCriticalSection;
00097
00098
00102
00103 zeusbase_class TSettingsManager : public TZObject, public ISettingsManager
00104 {
00105 public:
00106
00109
00110 zeusbase_class TUserData : public TZObject
00111 {
00112 public:
00113 TUserData();
00114 virtual ~TUserData();
00115
00116 Retval commit();
00117 void getPropertyNamesByNameSpace(const IString& rNameSpace, IStringList& rList) const ;
00118 void getPropertyNamesByNameSpace(const wchar_t* pNameSpace, IStringList& rList) const ;
00119
00120 Retval readBool(const IString& rKey, bool& rValue, bool bDefault = false);
00121 Retval readInt(const IString& rKey, Int& rValue, Int iDefault = 0);
00122 Retval readUint(const IString& rKey, Uint& rValue, Uint uiDefault = 0);
00123 Retval readFloat(const IString& rKey, Float& rValue, Float fDefault = 0.0);
00124 Retval readString(const IString& rKey, IString& rValue, TString strDefault=L"");
00125 inline Retval readBool(const wchar_t* pKey, bool& rValue, bool bDefault = false) { return readBool(TString(pKey), rValue, bDefault); }
00126 inline Retval readInt(const wchar_t* pKey, Int& rValue, Int iDefault = 0) { return readInt(TString(pKey), rValue, iDefault); }
00127 inline Retval readUint(const wchar_t* pKey, Uint& rValue, Uint uiDefault = 0) { return readUint(TString(pKey), rValue, uiDefault); }
00128 inline Retval readFloat(const wchar_t* pKey, Float& rValue, Float fDefault = 0.0) { return readFloat(TString(pKey), rValue, fDefault); }
00129 inline Retval readString(const wchar_t* pKey, IString& rValue, TString strDefault=L"") { return readString(TString(pKey), rValue, strDefault); }
00130
00131 Retval writeBool(const IString& rKey, bool bValue);
00132 Retval writeInt(const IString& rKey, Int iValue);
00133 Retval writeUint(const IString& rKey, Uint uiValue);
00134 Retval writeFloat(const IString& rKey, Float fValue);
00135 Retval writeString(const IString& rKey, const IString& rValue);
00136 inline Retval writeBool(const wchar_t* pKey, bool bValue) { return writeBool(TString(pKey), bValue); }
00137 inline Retval writeInt(const wchar_t* pKey, Int iValue) { return writeInt(TString(pKey), iValue); }
00138 inline Retval writeUint(const wchar_t* pKey, Uint uiValue) { return writeUint(TString(pKey), uiValue); }
00139 inline Retval writeFloat(const wchar_t* pKey, Float fValue) { return writeFloat(TString(pKey), fValue); }
00140 inline Retval writeString(const wchar_t* pKey, const IString& rValue) { return writeString(TString(pKey), rValue); }
00141
00142 Retval getUserDataNode(const IString& rName, IXMLNode*& rpNode);
00143
00144
00145 void setDocument(NAMESPACE_Zeus::IXMLDocument& rDocument);
00146 void releaseDocument();
00147
00148 private:
00150 TAutoPtr<NAMESPACE_Zeus::IXMLDocument> m_ptrDocument;
00152 TAutoPtr<IXMLNode> m_ptrMainNode;
00154 TCriticalSection& m_rLock;
00155
00156 };
00157
00158
00159 static TSettingsManager& getInstance();
00160
00161 TUserData& getUserData();
00162 void setPropertyInterface(IPropertyAccess& rIface);
00163 Retval setUserXMLFile(const IString& rFileName);
00164 Retval setUserXMLFile(TXMLFile& rFile);
00165 void releaseSourceInterfaces();
00166 void releasePropertyInterfaces();
00167 void releaseUserXMLFile();
00168
00169 void releaseDelegationInterface();
00170 void setDelegationInterface(ISettingsManager& rIface);
00171 TString completePathProperty(const TString& strPropName, const TString& strBasePath, bool bCreate = false);
00172
00173
00174 Retval readBoolProperty(const IString& rKey, bool& rValue, bool bDefault = false);
00175 Retval readIntProperty(const IString& rKey, Int& rValue, Int iDefault = 0);
00176 Retval readUintProperty(const IString& rKey, Uint& rValue, Uint uiDefault = 0);
00177 Retval readFloatProperty(const IString& rKey, Float& rValue, Float fDefault = 0.0);
00178 Retval readStringProperty(const IString& rKey, IString& rValue, TString strDefault=L"");
00179 inline Retval readBoolProperty(const wchar_t* pKey, bool& rValue, bool bDefault = false) { return readBoolProperty(TString(pKey), rValue, bDefault); }
00180 inline Retval readIntProperty(const wchar_t* pKey, Int& rValue, Int iDefault = 0) { return readIntProperty(TString(pKey), rValue, iDefault); }
00181 inline Retval readUintProperty(const wchar_t* pKey, Uint& rValue, Uint uiDefault = 0) { return readUintProperty(TString(pKey), rValue, uiDefault); }
00182 inline Retval readFloatProperty(const wchar_t* pKey, Float& rValue, Float fDefault = 0.0) { return readFloatProperty(TString(pKey), rValue, fDefault); }
00183 inline Retval readStringProperty(const wchar_t* pKey, IString& rValue, TString strDefault=L"") { return readStringProperty(TString(pKey), rValue, strDefault); }
00184
00185 Retval writeBoolProperty(const IString& rKey, bool bValue);
00186 Retval writeIntProperty(const IString& rKey, Int iValue);
00187 Retval writeUintProperty(const IString& rKey, Uint uiValue);
00188 Retval writeFloatProperty(const IString& rKey, Float fValue);
00189 Retval writeStringProperty(const IString& rKey, const IString& rValue);
00190 inline Retval writeBoolProperty(const wchar_t* pKey, bool bValue) { return writeBoolProperty(TString(pKey), bValue); }
00191 inline Retval writeIntProperty(const wchar_t* pKey, Int iValue) { return writeIntProperty(TString(pKey), iValue); }
00192 inline Retval writeUintProperty(const wchar_t* pKey, Uint uiValue) { return writeUintProperty(TString(pKey), uiValue); }
00193 inline Retval writeFloatProperty(const wchar_t* pKey, Float fValue) { return writeFloatProperty(TString(pKey), fValue); }
00194 inline Retval writeStringProperty(const wchar_t* pKey, const IString& rValue) { return writeStringProperty(TString(pKey), rValue); }
00195
00196
00197
00198 virtual Retval MQUALIFIER getUserDocument(NAMESPACE_Zeus::IXMLDocument*& rpDocument) const;
00199 virtual void MQUALIFIER notifyObservers();
00200 virtual void MQUALIFIER attach(INotifyObserver& rObserver);
00201 virtual void MQUALIFIER detach(INotifyObserver& rObserver);
00202
00203
00204 virtual Retval MQUALIFIER addProperty(const IString& rName, const IString& rValue);
00205 virtual bool MQUALIFIER existsProperty(const IString& rName)const ;
00206 virtual void MQUALIFIER getPropertyNames(IStringList& rList)const ;
00207 virtual void MQUALIFIER getPropertyNamesByNameSpace(const IString& rNameSpace, IStringList& rList) const ;
00208 virtual Retval MQUALIFIER getPropertyValue(const IString& rName, IString& rValue)const ;
00209 virtual Retval MQUALIFIER setPropertyValue(const IString& rName, const IString& rValue);
00210 virtual Retval MQUALIFIER getPropertyPathValue(const IString& rName, IString& rValue)const;
00211 virtual Retval MQUALIFIER getPropertyFileValue(const IString& rName, IString& rValue)const;
00212
00213
00214 MEMORY_MANAGER_DECL
00215
00216 private:
00217
00219 static TAutoPtr<TSettingsManager> m_ptrInstance;
00221 TAutoPtr<ISettingsManager> m_ptrDelegation;
00223 TAutoPtr<IPropertyAccess> m_ptrSourceInterface;
00225 TAutoPtr<TXMLFile> m_ptrUserFile;
00227 TUserData m_UserData;
00229 TSingleLinkedList<INotifyObserver*> m_lstObservers;
00231 TCriticalSection& m_rLock;
00232
00234
00235 #ifdef _MSC_VER
00236 public:
00237 #endif
00239
00240 TSettingsManager();
00241 virtual ~TSettingsManager();
00242 };
00243
00244
00245
00248
00249 inline TSettingsManager& TSettingsManager::getInstance()
00250 {
00251 return *m_ptrInstance;
00252 }
00253
00254
00257
00258 inline TSettingsManager::TUserData& TSettingsManager::getUserData()
00259 {
00260 return m_UserData;
00261 }
00262
00263
00271
00272 inline Retval TSettingsManager::readBoolProperty(const IString& rKey, bool& rValue, bool bDefault )
00273 {
00274 Int iValue = 0;
00275 Retval retValue = readIntProperty(rKey, iValue, bDefault);
00276 rValue = (iValue == 0 ? false : true);
00277 return retValue;
00278 }
00279
00280
00288
00289 inline Retval TSettingsManager::readIntProperty(const IString& rKey, Int& rValue, Int iDefault )
00290 {
00291 TString strValue;
00292 Retval retValue = readStringProperty(rKey, strValue, TString(iDefault));
00293 rValue = strValue.toInt();
00294 return retValue;
00295 }
00296
00297
00305
00306 inline Retval TSettingsManager::readUintProperty(const IString& rKey, Uint& rValue, Uint uiDefault )
00307 {
00308 TString strValue;
00309 Retval retValue = readStringProperty(rKey, strValue, TString(uiDefault));
00310 rValue = strValue.toUint();
00311 return retValue;
00312 }
00313
00314
00322
00323 inline Retval TSettingsManager::readFloatProperty(const IString& rKey, Float& rValue, Float fDefault )
00324 {
00325 TString strValue;
00326 Retval retValue = readStringProperty(rKey, strValue, TString(fDefault));
00327 rValue = strValue.toFloat();
00328 return retValue;
00329 }
00330
00331
00338
00339 inline Retval TSettingsManager::writeBoolProperty(const IString& rKey, bool bValue)
00340 {
00341 return writeIntProperty(rKey, bValue ? 1 : 0);
00342 }
00343
00344
00351
00352 inline Retval TSettingsManager::writeIntProperty(const IString& rKey, Int iValue)
00353 {
00354 return setPropertyValue(rKey, TString(iValue));
00355 }
00356
00357
00364
00365 inline Retval TSettingsManager::writeUintProperty(const IString& rKey, Uint uiValue)
00366 {
00367 return setPropertyValue(rKey, TString(uiValue));
00368 }
00369
00370
00377
00378 inline Retval TSettingsManager::writeFloatProperty(const IString& rKey, Float fValue)
00379 {
00380 return setPropertyValue(rKey, TString(fValue));
00381 }
00382
00383
00390
00391 inline Retval TSettingsManager::writeStringProperty(const IString& rKey, const IString& rValue)
00392 {
00393 return setPropertyValue(rKey, rValue);
00394 }
00395
00396
00397
00398
00401
00402 inline void TSettingsManager::TUserData::getPropertyNamesByNameSpace(const wchar_t* pNameSpace, IStringList& rList) const
00403 {
00404 getPropertyNamesByNameSpace(TString(pNameSpace), rList);
00405 }
00406
00407
00415
00416 inline Retval TSettingsManager::TUserData::readBool(const IString& rKey, bool& rValue,
00417 bool bDefault )
00418 {
00419 Int iValue = 0;
00420 Retval retValue = readInt(rKey, iValue, bDefault);
00421 rValue = (iValue == 0 ? false : true);
00422 return retValue;
00423 }
00424
00425
00433
00434 inline Retval TSettingsManager::TUserData::readInt(const IString& rKey, Int& rValue, Int iDefault )
00435 {
00436 TString strValue;
00437 Retval retValue = readString(rKey, strValue, TString(iDefault));
00438 rValue = strValue.toInt();
00439 return retValue;
00440 }
00441
00442
00450
00451 inline Retval TSettingsManager::TUserData::readUint(const IString& rKey, Uint& rValue, Uint uiDefault )
00452 {
00453 TString strValue;
00454 Retval retValue = readString(rKey, strValue, TString(uiDefault));
00455 rValue = strValue.toUint();
00456 return retValue;
00457 }
00458
00459
00460
00468
00469 inline Retval TSettingsManager::TUserData::readFloat(const IString& rKey, Float& rValue, Float fDefault )
00470 {
00471 TString strValue;
00472 Retval retValue = readString(rKey, strValue, TString(fDefault));
00473 rValue = strValue.toFloat();
00474 return retValue;
00475 }
00476
00477
00484
00485 inline Retval TSettingsManager::TUserData::writeBool(const IString& rKey, bool bValue)
00486 {
00487 return writeInt(rKey, bValue ? 1 : 0);
00488 }
00489
00490
00497
00498 inline Retval TSettingsManager::TUserData::writeInt(const IString& rKey, Int iValue)
00499 {
00500 return writeString(rKey, TString(iValue));
00501 }
00502
00503
00510
00511 inline Retval TSettingsManager::TUserData::writeUint(const IString& rKey, Uint uiValue)
00512 {
00513 return writeString(rKey, TString(uiValue));
00514 }
00515
00516
00517
00524
00525 inline Retval TSettingsManager::TUserData::writeFloat(const IString& rKey, Float fValue)
00526 {
00527 return writeString(rKey, TString(fValue));
00528 }
00529
00530
00531 END_NAMESPACE_Zeus
00532
00533 #endif