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

Last change on this file since 2898 was 2864, checked in by ansari, 20 years ago

1/ Ajout methode CheckReadability() , retour int pour CheckHandling() ds l'interface FitsHandler et propagation vers handler TArray et DataTable
2/ Correction dans FitsManager et ajout initialiseur de module FitsIOServer (fiosinit.h .cc)
3/ FitsSwapper complete - corrige - full template (suppression de fitsswapper.cc)
4/ MAJ Makefile et objlist.list suite ajout fiosinit.cc et swfitsdtable

Reza , 2 Jan 2006

  • Property svn:executable set to *
File size: 2.4 KB
Line 
1#ifndef FITSHANDLER_H
2#define FITSHANDLER_H
3
4#include "machdefs.h"
5#include <string>
6#include <typeinfo>
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
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*/
43template <class T>
44class FitsHandler : public FitsHandlerInterface {
45
46public :
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
80protected :
81 T * dobj;
82 bool ownobj; // True si dobj obtenu par new
83};
84
85
86
87} // Fin du namespace
88
89#endif
90
Note: See TracBrowser for help on using the repository browser.