1 | /*
|
---|
2 | --- SOPHYA software - FitsIOServer module ---
|
---|
3 | R. Ansari, 2005
|
---|
4 | (C) UPS+LAL IN2P3/CNRS (C) DAPNIA-SPP/CEA
|
---|
5 | */
|
---|
6 | #ifndef FITSHANDLER_H
|
---|
7 | #define FITSHANDLER_H
|
---|
8 |
|
---|
9 | #include "machdefs.h"
|
---|
10 | #include <string>
|
---|
11 | #include <typeinfo>
|
---|
12 | #include "fitsinoutfile.h"
|
---|
13 |
|
---|
14 | namespace SOPHYA {
|
---|
15 |
|
---|
16 | /*!
|
---|
17 | \ingroup FitsIOServer
|
---|
18 | \brief Interface definition for classes handling object storage retrieval in FITS Format
|
---|
19 | */
|
---|
20 | class FitsHandlerInterface {
|
---|
21 |
|
---|
22 | public:
|
---|
23 |
|
---|
24 | virtual ~FitsHandlerInterface() {}
|
---|
25 | //! Return the real data object
|
---|
26 | virtual AnyDataObj* DataObj() = 0; // Retourne l'objet reel
|
---|
27 |
|
---|
28 | /*!
|
---|
29 | \brief Return a positive value if I/O for object \b o can be handled
|
---|
30 |
|
---|
31 | - Rc= 0 -> Can NOT handle fits I/O operations for the object \b o
|
---|
32 | - Rc= 1 -> Can handle fits I/O operations for the object \b o
|
---|
33 | - Rc= 2 -> This is a specific handler for object \b o
|
---|
34 | - Rc > 2 -> Higher Rc values can be returned if needed
|
---|
35 | (for subclasses with specific handlers)
|
---|
36 |
|
---|
37 | */
|
---|
38 | virtual int CheckHandling(AnyDataObj & o) = 0;
|
---|
39 | //! Read/write operation will use the object o
|
---|
40 | virtual void SetDataObj(AnyDataObj & o) = 0;
|
---|
41 |
|
---|
42 | //!
|
---|
43 | /*!
|
---|
44 | \brief Return a positive value if current HDU can be read by the handler
|
---|
45 |
|
---|
46 | - Rc= 0 -> Can NOT read the current HDU
|
---|
47 | - Rc= 1 -> Can read the current HDU (generic reader)
|
---|
48 | - Rc= 2 -> Can read the current HDU, as a specific reader
|
---|
49 | - Rc > 2 -> Higher Rc values can be returned if needed
|
---|
50 | (when multiple specific handlers are registered)
|
---|
51 |
|
---|
52 | */
|
---|
53 | virtual int CheckReadability(FitsInOutFile& is) = 0;
|
---|
54 |
|
---|
55 | //! Clone (duplicate) the handler class
|
---|
56 | virtual FitsHandlerInterface* Clone() = 0;
|
---|
57 |
|
---|
58 | //! Perform the actual write operation to the output fits file
|
---|
59 | virtual void Write(FitsInOutFile& os) = 0;
|
---|
60 | //! Perform the actual read operation from input fits file
|
---|
61 | virtual void Read(FitsInOutFile& is) = 0;
|
---|
62 | };
|
---|
63 |
|
---|
64 | /*!
|
---|
65 | \ingroup FitsIOServer
|
---|
66 | \brief Generic implementation of FitsHandlerInterface
|
---|
67 | */
|
---|
68 | template <class T>
|
---|
69 | class FitsHandler : public FitsHandlerInterface {
|
---|
70 |
|
---|
71 | public :
|
---|
72 | FitsHandler() { dobj=NULL; ownobj=true; }
|
---|
73 | FitsHandler(T & obj) { dobj = &obj; ownobj=false; }
|
---|
74 | virtual ~FitsHandler() { if (ownobj && dobj) delete dobj; }
|
---|
75 |
|
---|
76 | virtual AnyDataObj* DataObj() { return(dobj); }
|
---|
77 | virtual int CheckHandling(AnyDataObj & o)
|
---|
78 | {
|
---|
79 | if (typeid(o) == typeid(T)) return 2;
|
---|
80 | T * po = dynamic_cast< T * >(& o);
|
---|
81 | if (po == NULL) return 0;
|
---|
82 | else return 1;
|
---|
83 | }
|
---|
84 | virtual void SetDataObj(AnyDataObj & o)
|
---|
85 | {
|
---|
86 | T * po = dynamic_cast< T * >(& o);
|
---|
87 | if (po == NULL) {
|
---|
88 | string msg = "FitsHandler<T>::SetDataObj() Wrong object type: " ;
|
---|
89 | msg += typeid(o).name();
|
---|
90 | throw TypeMismatchExc(msg);
|
---|
91 | }
|
---|
92 | if (ownobj && dobj) delete dobj; dobj = po; ownobj = false;
|
---|
93 | }
|
---|
94 |
|
---|
95 | virtual int CheckReadability(FitsInOutFile& is);
|
---|
96 |
|
---|
97 | virtual FitsHandlerInterface* Clone()
|
---|
98 | { return new FitsHandler<T>() ; }
|
---|
99 |
|
---|
100 | inline operator T&() { return(*dobj); }
|
---|
101 |
|
---|
102 | virtual void Read(FitsInOutFile& is);
|
---|
103 | virtual void Write(FitsInOutFile& os);
|
---|
104 |
|
---|
105 | protected :
|
---|
106 | T * dobj;
|
---|
107 | bool ownobj; // True si dobj obtenu par new
|
---|
108 | };
|
---|
109 |
|
---|
110 |
|
---|
111 |
|
---|
112 | } // Fin du namespace
|
---|
113 |
|
---|
114 | #endif
|
---|
115 |
|
---|