00001
00017 #ifndef REGISTRY_H
00018 #define REGISTRY_H
00019
00020 #include <iostream>
00021 #include <map>
00022 #include <string>
00023
00024 #include <TNamed.h>
00025
00026 class RegistryItem;
00027 class type_info;
00028
00029 class Registry : public TNamed
00030 {
00031 public:
00032 typedef std::map<std::string,RegistryItem*> tRegMap;
00033 typedef void (*ErrorHandler)(void);
00034
00038 explicit Registry(bool readonly = true);
00039
00041 Registry(const Registry& rhs);
00042
00043 virtual ~Registry();
00044
00046 Registry& operator=(const Registry& rhs);
00047
00049 void Merge(const Registry& rhs);
00050
00052 unsigned int Size() const { return fMap.size(); }
00053
00055 bool KeyExists(const char* key) const;
00056 void RemoveKey(const char* key);
00057
00059 void Clear(Option_t *option="");
00060
00062 void Dump(void) const;
00063
00065 virtual std::ostream& PrintStream(std::ostream& os) const;
00066 virtual std::istream& ReadStream(std::istream& is);
00067
00068
00069 virtual void Print(Option_t *option="") const;
00070 virtual std::ostream& PrettyPrint(std::ostream& os) const;
00071
00073 virtual bool ValuesLocked(void) const { return fValuesLocked; }
00074 virtual void LockValues(void) { fValuesLocked = true; }
00075 virtual void UnLockValues(void) { fValuesLocked = false; }
00076
00078 virtual bool KeysLocked(void) const { return fKeysLocked; }
00079 virtual void LockKeys(void) { fKeysLocked = true; }
00080 virtual void UnLockKeys(void) { fKeysLocked = false; }
00081
00086 void SetDirty(bool is_dirty = true) { fDirty = is_dirty; }
00087 bool IsDirty() { return fDirty; }
00088
00089
00090 void SetErrorHandler(ErrorHandler eh) { fErrorHandler = eh; }
00091
00092
00095
00096 bool Get(const char* key, char& c) const;
00097 bool Get(const char* key, const char*& s) const;
00098 bool Get(const char* key, int& i) const;
00099 bool Get(const char* key, double& d) const;
00100 bool Get(const char* key, Registry& r) const;
00101
00104 const type_info& GetType(const char* key) const;
00106 std::string GetTypeAsString(const char* key) const;
00108 std::string GetValueAsString(const char* key) const;
00109
00110
00114
00115 char GetChar(const char* key) const;
00116 const char* GetCharString(const char* key) const;
00117 int GetInt(const char* key) const;
00118 double GetDouble(const char* key) const;
00119 Registry GetRegistry(const char* key) const;
00120
00123
00124 bool Set(const char* key, char c);
00125 bool Set(const char* key, const char* s);
00126 bool Set(const char* key, int i);
00127 bool Set(const char* key, double d);
00128 bool Set(const char* key, Registry r);
00129
00130 class RegistryKey
00131 {
00132
00133 public:
00134 RegistryKey();
00135 RegistryKey(const Registry* r);
00136 virtual ~RegistryKey();
00137
00138 const char* operator()(void);
00139
00140 private:
00141
00142 const Registry* fReg;
00143 std::map<std::string,RegistryItem*>::iterator fIt;
00144 };
00145
00146 RegistryKey Key(void) const;
00147
00148 private:
00149 bool fValuesLocked;
00150 bool fKeysLocked;
00151 ErrorHandler fErrorHandler;
00152 #ifndef __CINT__
00153 friend class RegistryKey;
00154
00155 tRegMap fMap;
00156 #endif
00157 bool fDirty;
00158
00159 ClassDef(Registry,1)
00160 };
00161
00162 inline std::ostream& operator<<(std::ostream& os, const Registry& r) { return r.PrintStream(os); }
00163
00164
00165 #include "Registry/RegistryItemXxx.h"
00166
00167 #endif // REGISTRY_H