csutil/cfgmgr.h Source File (Crystal Space 2.0 Public API Reference)

| ## Public API Reference

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

csutil/cfgmgr.h
Go to the documentation of this file.

    00001 /*
    00002     Copyright (C) 2001 by Martin Geisse <mgeisse@gmx.net>
    00003
    00004     This library is free software; you can redistribute it and/or
    00005     modify it under the terms of the GNU Library General Public
    00006     License as published by the Free Software Foundation; either
    00007     version 2 of the License, or (at your option) any later version.
    00008
    00009     This library is distributed in the hope that it will be useful,
    00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00012     Library General Public License for more details.
    00013
    00014     You should have received a copy of the GNU Library General Public
    00015     License along with this library; if not, write to the Free
    00016     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    00017 */
    00018
    00019 #ifndef __CS_CFGMGR_H__
    00020 #define __CS_CFGMGR_H__
    00021
    00026 #include "csextern.h"
    00027 #include "csutil/array.h"
    00028 #include "csutil/refarr.h"
    00029 #include "csutil/scf_implementation.h"
    00030 #include "iutil/cfgmgr.h"
    00031 #include "iutil/cfgnotifier.h"
    00032
    00033
    00034 class csConfigManagerIterator;
    00035
    00041 class CS_CRYSTALSPACE_EXPORT csConfigManager
    00042   : public scfImplementation3<csConfigManager,
    00043                               iConfigManager,
    00044                               scfFakeInterface<iConfigFile>,
    00045                               iConfigNotifier>
    00046 {
    00047 public:
    00048
    00062   csConfigManager(iConfigFile *DynamicDomain = 0, bool Optimize = false);
    00064   virtual ~csConfigManager();
    00065
    00070   virtual void AddDomain(iConfigFile*, int priority);
    00080   virtual iConfigFile* AddDomain(char const* path, iVFS*, int priority);
    00088   virtual void RemoveDomain(iConfigFile*);
    00090   virtual void RemoveDomain(char const* path);
    00095   virtual iConfigFile* LookupDomain(char const* path) const;
    00097   virtual void SetDomainPriority(char const* path, int priority);
    00102   virtual void SetDomainPriority(iConfigFile*, int priority);
    00107   virtual int GetDomainPriority(char const* path) const;
    00112   virtual int GetDomainPriority(iConfigFile*) const;
    00113
    00119   virtual bool SetDynamicDomain(iConfigFile*);
    00125   virtual iConfigFile *GetDynamicDomain() const;
    00127   virtual void SetDynamicDomainPriority(int priority);
    00129   virtual int GetDynamicDomainPriority() const;
    00130
    00132   virtual void FlushRemoved();
    00133
    00138   virtual const char* GetFileName () const;
    00139
    00144   virtual iVFS* GetVFS () const;
    00145
    00152   virtual void SetFileName (const char*, iVFS*);
    00153
    00170   virtual bool Load (const char* iFileName, iVFS* = 0, bool Merge = false,
    00171     bool NewWins = true);
    00172
    00177   virtual bool Save ();
    00178
    00185   virtual bool Save (const char *iFileName, iVFS* = 0);
    00186
    00188   virtual void Clear ();
    00189
    00191   void CleanUp ();
    00192
    00199   virtual csPtr<iConfigIterator> Enumerate(const char *Subsection = 0);
    00200
    00202   virtual bool KeyExists(const char *Key) const;
    00204   virtual bool SubsectionExists(const char *Subsection) const;
    00205
    00207   virtual int GetInt(const char *Key, int Def = 0) const;
    00209   virtual float GetFloat(const char *Key, float Def = 0.0) const;
    00211   virtual const char *GetStr(const char *Key, const char *Def = "") const;
    00213   virtual bool GetBool(const char *Key, bool Def = false) const;
    00215   virtual csPtr<iStringArray> GetTuple(const char *Key) const;
    00217   virtual const char *GetComment(const char *Key) const;
    00218
    00220   virtual void SetStr (const char *Key, const char *Val);
    00222   virtual void SetInt (const char *Key, int Value);
    00224   virtual void SetFloat (const char *Key, float Value);
    00226   virtual void SetBool (const char *Key, bool Value);
    00228   virtual void SetTuple (const char *Key, iStringArray* Value);
    00235   virtual bool SetComment (const char *Key, const char *Text);
    00237   virtual void DeleteKey(const char *Key);
    00239   virtual const char *GetEOFComment() const;
    00241   virtual void SetEOFComment(const char *Text);
    00242
    00246   virtual void AddListener (iConfigListener*);
    00247
    00251   virtual void RemoveListener (iConfigListener*);
    00252
    00253 private:
    00254   friend class csConfigManagerIterator;
    00256   bool Optimize;
    00258   class csConfigDomain *DynamicDomain;
    00260   class csConfigDomain *FirstDomain, *LastDomain;
    00262   csRefArray<iConfigFile> Removed;
    00264   csArray<iConfigIterator*> Iterators;
    00265
    00266   csConfigDomain *FindConfig(iConfigFile *cfg) const;
    00267   csConfigDomain *FindConfig(const char *name) const;
    00268   void ClearKeyAboveDynamic(const char *Key);
    00269   void RemoveIterator(csConfigManagerIterator *it);
    00270   void FlushRemoved(size_t n);
    00271   size_t FindRemoved(const char *Filename) const;
    00272   void RemoveDomain(class csConfigDomain *cfg);
    00273
    00274   csRefArray<iConfigListener> listeners;
    00275
    00276   template<typename T>
    00277   void NotifyListeners(const char* key, T value)
    00278   {
    00279     for (size_t i = 0; i < listeners.GetSize(); i++)
    00280       listeners.Get(i)->Set(key, value);
    00281   }
    00282 };
    00283
    00284 #endif // __CS_CFGMGR_H__