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

Last change on this file since 2824 was 2820, checked in by ansari, 20 years ago

1/ Ajout classes FitsInOutFile / FitsTypes / FitsIOException d'enrobage lib cfitsio
2/ Ajout classes FitsBlockRW<T> pour lecture/ecriture sur IMGHDU et Tables
3/ Ajout classes gestionnaire FITS FitsHandler<T> et FitsManager
4/ Ajout classe gestionnaires pour TArray<T> FitsArrayHandler<T>
5/ Ajout classe gestionnaire pour DataTable FitsHandler<BaseDataTable>

Reza 12 octobre 2006

  • Property svn:executable set to *
File size: 2.2 KB
Line 
1#ifndef FITSHANDLER_H
2#define FITSHANDLER_H
3
4#include "machdefs.h"
5#include <string>
6#include "fitsinoutfile.h"
7
8namespace SOPHYA {
9
10/*!
11 \ingroup FitsIOServer
12 \brief Interface definition for classes handling object storage retrieval in FITS Format
13*/
14class FitsHandlerInterface {
15
16public:
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*/
39template <class T>
40class FitsHandler : public FitsHandlerInterface {
41
42public :
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
73protected :
74 T * dobj;
75 bool ownobj; // True si dobj obtenu par new
76};
77
78
79
80} // Fin du namespace
81
82#endif
83
Note: See TracBrowser for help on using the repository browser.