source: Sophya/trunk/SophyaExt/FitsIOServer/fitsmanager.cc@ 2844

Last change on this file since 2844 was 2843, checked in by ansari, 20 years ago

debut modifs nouveau fits pour support I/O chaines de caracteres - Reza 18/11/2005

  • Property svn:executable set to *
File size: 2.0 KB
Line 
1#include "machdefs.h"
2#include "sopnamsp.h"
3
4#include <stdio.h>
5#include <string.h>
6#include <iostream>
7#include <typeinfo>
8
9#include "fitsmanager.h"
10#include "fitshandler.h"
11
12struct hand_list_el {
13 FitsHandlerInterface * fhi;
14 string clname;
15};
16
17typedef list<hand_list_el> HandlerList;
18
19static HandlerList * hlistp = NULL;
20
21static inline void ChkHLP()
22{
23 if (hlistp == NULL) hlistp = new HandlerList;
24}
25
26int FitsManager::RegisterHandler(FitsHandlerInterface * fhi, string & clname)
27{
28 if (fhi == NULL)
29 throw NullPtrError("FitsManager::RegisterHandler() fhi=NULL ");
30 HandlerList::iterator it;
31 for(it = hlistp->begin(); it != hlistp->end(); it++) {
32 if (typeid(*((*it).fhi)) == typeid(*fhi))
33 throw DuplicateIdExc("FitsManager::RegisterHandler() Already registered handler");
34 }
35 hand_list_el hle;
36 hle.fhi = fhi;
37 hle.clname = clname;
38 hlistp->push_back(hle);
39 return hlistp->size();
40}
41
42int FitsManager::ListHandlers()
43{
44 int kk=0;
45 cout << "---- FitsManager::ListHandlers() NbHandlers= " << hlistp->size()
46 << endl;
47 HandlerList::iterator it;
48 for(it = hlistp->begin(); it != hlistp->end(); it++) {
49 kk++;
50 cout << kk << "- " << (*it).clname << " : "
51 << typeid(*((*it).fhi)).name() << endl;
52 }
53 return hlistp->size();
54}
55
56FitsHandlerInterface* FitsManager::FindHandler(AnyDataObj & o)
57{
58 FitsHandlerInterface * fhi = NULL;
59 HandlerList::iterator it;
60 for(it = hlistp->begin(); it != hlistp->end(); it++)
61 if ( (*it).fhi->CheckHandling(o) ) {
62 fhi = (*it).fhi; break;
63 }
64 if (fhi == NULL) {
65 string msg = "FitsManager::FindHandler() Handler not found for ";
66 msg += typeid(o).name();
67 throw NotFoundExc(msg);
68 }
69 else return fhi;
70}
71
72void FitsManager::Write(FitsInOutFile& os, AnyDataObj & o)
73{
74 FitsHandlerInterface * fhi2 = FindHandler(o)->Clone();
75 fhi2->SetDataObj(o);
76 fhi2->Write(os);
77 return;
78}
79
80void FitsManager::Read(FitsInOutFile& os, AnyDataObj & o)
81{
82 FitsHandlerInterface * fhi2 = FindHandler(o)->Clone();
83 fhi2->SetDataObj(o);
84 fhi2->Read(os);
85 return;
86}
Note: See TracBrowser for help on using the repository browser.