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
00072
00073
00074 virtual void Browse(TBrowser*){}
00075
00077 virtual bool ValuesLocked(void) const { return fValuesLocked; }
00078 virtual void LockValues(void) { fValuesLocked = true; }
00079 virtual void UnLockValues(void) { fValuesLocked = false; }
00080
00082 virtual bool KeysLocked(void) const { return fKeysLocked; }
00083 virtual void LockKeys(void) { fKeysLocked = true; }
00084 virtual void UnLockKeys(void) { fKeysLocked = false; }
00085
00090 void SetDirty(bool is_dirty = true) { fDirty = is_dirty; }
00091 bool IsDirty() { return fDirty; }
00092
00093
00094 void SetErrorHandler(ErrorHandler eh) { fErrorHandler = eh; }
00095
00096
00099
00100 bool Get(const char* key, char& c) const;
00101 bool Get(const char* key, const char*& s) const;
00102 bool Get(const char* key, int& i) const;
00103 bool Get(const char* key, double& d) const;
00104 bool Get(const char* key, Registry& r) const;
00105
00108 const type_info& GetType(const char* key) const;
00110 std::string GetTypeAsString(const char* key) const;
00112 std::string GetValueAsString(const char* key) const;
00113
00114
00118
00119 char GetChar(const char* key) const;
00120 const char* GetCharString(const char* key) const;
00121 int GetInt(const char* key) const;
00122 double GetDouble(const char* key) const;
00123 Registry GetRegistry(const char* key) const;
00124
00127
00128 bool Set(const char* key, char c);
00129 bool Set(const char* key, const char* s);
00130 bool Set(const char* key, int i);
00131 bool Set(const char* key, double d);
00132 bool Set(const char* key, Registry r);
00133
00134 class RegistryKey
00135 {
00136
00137 public:
00138 RegistryKey();
00139 RegistryKey(const Registry* r);
00140 virtual ~RegistryKey();
00141
00142 const char* operator()(void);
00143
00144 private:
00145
00146 const Registry* fReg;
00147 std::map<std::string,RegistryItem*>::iterator fIt;
00148 };
00149
00150 RegistryKey Key(void) const;
00151
00152 private:
00153 bool fValuesLocked;
00154 bool fKeysLocked;
00155 ErrorHandler fErrorHandler;
00156 #ifndef __CINT__
00157 friend class RegistryKey;
00158
00159 tRegMap fMap;
00160 #endif
00161 bool fDirty;
00162
00163 ClassDef(Registry,1)
00164 };
00165
00166 inline std::ostream& operator<<(std::ostream& os, const Registry& r) { return r.PrintStream(os); }
00167
00168
00169 #include "Registry/RegistryItemXxx.h"
00170
00171 #endif // REGISTRY_H