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

Last change on this file since 3586 was 3493, checked in by ansari, 17 years ago

1/ Ajout methodes FitsArrayHandler<T>::ReadAtOffset() WriteAtOffset() pour lecture/ecriture de tableaux <> HDU IMAGE par morceaux
2/ Ajout entete commentaire avec copyright LAL+DAPNIA dans les fichiers .h

Reza 30/04/2008

  • Property svn:executable set to *
File size: 3.1 KB
RevLine 
[3493]1/*
2 --- SOPHYA software - FitsIOServer module ---
3 R. Ansari, 2005
4 (C) UPS+LAL IN2P3/CNRS (C) DAPNIA-SPP/CEA
5*/
[2820]6#ifndef FITSHANDLER_H
7#define FITSHANDLER_H
8
9#include "machdefs.h"
10#include <string>
[2864]11#include <typeinfo>
[2820]12#include "fitsinoutfile.h"
13
14namespace SOPHYA {
15
16/*!
17 \ingroup FitsIOServer
18 \brief Interface definition for classes handling object storage retrieval in FITS Format
19*/
20class FitsHandlerInterface {
21
22public:
23
24 virtual ~FitsHandlerInterface() {}
25 //! Return the real data object
26 virtual AnyDataObj* DataObj() = 0; // Retourne l'objet reel
[2932]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 */
[2864]38 virtual int CheckHandling(AnyDataObj & o) = 0;
[2820]39 //! Read/write operation will use the object o
40 virtual void SetDataObj(AnyDataObj & o) = 0;
41
[2932]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 */
[2864]53 virtual int CheckReadability(FitsInOutFile& is) = 0;
54
[2820]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*/
68template <class T>
69class FitsHandler : public FitsHandlerInterface {
70
71public :
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); }
[2864]77 virtual int CheckHandling(AnyDataObj & o)
[2820]78 {
[2864]79 if (typeid(o) == typeid(T)) return 2;
[2820]80 T * po = dynamic_cast< T * >(& o);
[2864]81 if (po == NULL) return 0;
82 else return 1;
[2820]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 }
[2864]94
95 virtual int CheckReadability(FitsInOutFile& is);
[2820]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
105protected :
106 T * dobj;
107 bool ownobj; // True si dobj obtenu par new
108};
109
110
111
112} // Fin du namespace
113
114#endif
115
Note: See TracBrowser for help on using the repository browser.