00001 #ifndef _Q_GLOBAL_READER_HH_ 00002 #define _Q_GLOBAL_READER_HH_ 00003 00028 #include "QCuore.hh" 00029 #include "QNamed.hh" 00030 #include "QError.hh" 00031 #include "QMessage.hh" 00032 #include <string> 00033 #include "QGeneralFactory.hh" 00034 00035 class TObject; 00036 namespace Cuore {class QObject;} 00037 using namespace Cuore; 00038 00039 00040 class QGlobalReader : public QNamed 00041 { 00042 public: 00044 QGlobalReader(const std::string& name) : QNamed(name) {} 00045 00047 virtual ~QGlobalReader() {} 00048 00050 virtual const QObject* GetQObject(const std::string& name) const; 00051 00053 virtual const TObject* GetTObject(const std::string& name) const; 00054 00056 virtual double GetDouble(const std::string& name) const; 00057 00059 virtual int GetInt(const std::string& name) const; 00060 00062 virtual float GetFloat(const std::string& name) const; 00063 00065 virtual bool GetBool(const std::string& name) const; 00066 00068 virtual std::string GetString(const std::string& name) const; 00069 00070 protected: 00071 00073 virtual QError Open(const std::string& filename, const std::string& opt = "") = 0; 00074 00076 virtual QError Close() = 0; 00077 00078 friend class QGlobalReaderDispatcher; 00079 00080 }; 00081 00087 class QGlobalReaderFactory { 00088 public: 00089 QGlobalReaderFactory(const std::string& name, const std::string& ext) {fName = name; fExt = ext;} 00090 const std::string& GetName() const { return fName;} 00091 const std::string& GetExt() const { return fExt;} 00092 virtual ~QGlobalReaderFactory() {}; 00093 private: 00094 virtual QGlobalReader* Create() = 0; 00095 std::string fName; 00096 std::string fExt; 00097 friend class QGeneralFactory; 00098 }; 00099 00100 00101 #define CREATE_GOLBAL_READER_IMPL(clazz,ext) \ 00102 class clazz ## Factory: public QGlobalReaderFactory{\ 00103 public:\ 00104 clazz ## Factory() : QGlobalReaderFactory(#clazz,ext) {}\ 00105 QGlobalReader *Create(){ return new clazz; }\ 00106 }; 00107 00108 #define REGISTER_GLOBAL_READER(clazz, ext) \ 00109 CREATE_GOLBAL_READER_IMPL(clazz, ext);\ 00110 extern "C" void registerInFactory ## clazz() {\ 00111 QGlobalReaderFactory* pt = new clazz ## Factory;\ 00112 QGeneralFactory::GetInstance().RegisterGlobalReader(pt);\ 00113 } 00114 00115 #endif