| 1 | #ifndef FITSHANDLER_H
 | 
|---|
| 2 | #define FITSHANDLER_H
 | 
|---|
| 3 | 
 | 
|---|
| 4 | #include "machdefs.h"
 | 
|---|
| 5 | #include <string>
 | 
|---|
| 6 | #include <typeinfo>
 | 
|---|
| 7 | #include "fitsinoutfile.h"
 | 
|---|
| 8 | 
 | 
|---|
| 9 | namespace SOPHYA {
 | 
|---|
| 10 | 
 | 
|---|
| 11 | /*! 
 | 
|---|
| 12 |   \ingroup FitsIOServer
 | 
|---|
| 13 |   \brief Interface definition for classes handling object storage retrieval in FITS Format 
 | 
|---|
| 14 | */
 | 
|---|
| 15 | class FitsHandlerInterface {
 | 
|---|
| 16 | 
 | 
|---|
| 17 | public:
 | 
|---|
| 18 | 
 | 
|---|
| 19 |   virtual ~FitsHandlerInterface() {}
 | 
|---|
| 20 |   //! Return the real data object
 | 
|---|
| 21 |   virtual AnyDataObj* DataObj() = 0;       // Retourne l'objet reel 
 | 
|---|
| 22 |   //! Return a positive value if I/O for object \b o can be handled
 | 
|---|
| 23 |   virtual int         CheckHandling(AnyDataObj & o) = 0;
 | 
|---|
| 24 |   //! Read/write operation will use the object o
 | 
|---|
| 25 |   virtual void        SetDataObj(AnyDataObj & o) = 0;
 | 
|---|
| 26 | 
 | 
|---|
| 27 |   //! Return a positive value if current HDU can be read by the handler
 | 
|---|
| 28 |   virtual int         CheckReadability(FitsInOutFile& is) = 0;
 | 
|---|
| 29 |   
 | 
|---|
| 30 |   //! Clone (duplicate) the handler class
 | 
|---|
| 31 |   virtual FitsHandlerInterface* Clone() = 0;
 | 
|---|
| 32 | 
 | 
|---|
| 33 |   //! Perform the actual write operation to the output fits file
 | 
|---|
| 34 |   virtual void        Write(FitsInOutFile& os) = 0;
 | 
|---|
| 35 |   //! Perform the actual read operation from input fits file
 | 
|---|
| 36 |   virtual void        Read(FitsInOutFile& is) = 0;  
 | 
|---|
| 37 | };
 | 
|---|
| 38 | 
 | 
|---|
| 39 | /*! 
 | 
|---|
| 40 |   \ingroup FitsIOServer
 | 
|---|
| 41 |   \brief Generic implementation of FitsHandlerInterface 
 | 
|---|
| 42 | */
 | 
|---|
| 43 | template <class T>
 | 
|---|
| 44 | class FitsHandler : public FitsHandlerInterface {
 | 
|---|
| 45 | 
 | 
|---|
| 46 | public :
 | 
|---|
| 47 |             FitsHandler() { dobj=NULL; ownobj=true; }
 | 
|---|
| 48 |             FitsHandler(T & obj) { dobj = &obj; ownobj=false; }
 | 
|---|
| 49 |   virtual   ~FitsHandler() { if (ownobj && dobj) delete dobj; }
 | 
|---|
| 50 | 
 | 
|---|
| 51 |   virtual   AnyDataObj* DataObj() { return(dobj); }
 | 
|---|
| 52 |   virtual   int         CheckHandling(AnyDataObj & o) 
 | 
|---|
| 53 |   {  
 | 
|---|
| 54 |     if (typeid(o) == typeid(T)) return 2;
 | 
|---|
| 55 |     T * po = dynamic_cast< T * >(& o); 
 | 
|---|
| 56 |     if (po == NULL) return 0;
 | 
|---|
| 57 |     else return 1;
 | 
|---|
| 58 |   }
 | 
|---|
| 59 |   virtual   void        SetDataObj(AnyDataObj & o) 
 | 
|---|
| 60 |   {  
 | 
|---|
| 61 |     T * po = dynamic_cast< T * >(& o); 
 | 
|---|
| 62 |     if (po == NULL)  {
 | 
|---|
| 63 |       string msg = "FitsHandler<T>::SetDataObj() Wrong object type: " ;
 | 
|---|
| 64 |       msg += typeid(o).name(); 
 | 
|---|
| 65 |       throw TypeMismatchExc(msg);    
 | 
|---|
| 66 |     }
 | 
|---|
| 67 |     if (ownobj && dobj) delete dobj;  dobj = po; ownobj = false; 
 | 
|---|
| 68 |   }
 | 
|---|
| 69 | 
 | 
|---|
| 70 |   virtual int         CheckReadability(FitsInOutFile& is);
 | 
|---|
| 71 |     
 | 
|---|
| 72 |   virtual FitsHandlerInterface* Clone() 
 | 
|---|
| 73 |     { return new FitsHandler<T>() ; }
 | 
|---|
| 74 | 
 | 
|---|
| 75 |   inline operator T&() { return(*dobj); }
 | 
|---|
| 76 | 
 | 
|---|
| 77 |   virtual void        Read(FitsInOutFile& is);
 | 
|---|
| 78 |   virtual void        Write(FitsInOutFile& os);
 | 
|---|
| 79 | 
 | 
|---|
| 80 | protected :
 | 
|---|
| 81 |   T * dobj;
 | 
|---|
| 82 |   bool ownobj;       // True si dobj obtenu par new
 | 
|---|
| 83 | };
 | 
|---|
| 84 | 
 | 
|---|
| 85 | 
 | 
|---|
| 86 | 
 | 
|---|
| 87 | } // Fin du namespace
 | 
|---|
| 88 | 
 | 
|---|
| 89 | #endif
 | 
|---|
| 90 | 
 | 
|---|