source: Sophya/trunk/SophyaExt/FitsIOServer/fitshandler.h@ 3447

Last change on this file since 3447 was 2932, checked in by ansari, 19 years ago

Modifs suggere par Casandjian (suppression espace ds les kw fits et conservation des kw de type STRUCT) et petites corrections, maj commentaires auto-doc - Reza 3/4/2006

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