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