[2820] | 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 |
|
---|
| 12 | struct hand_list_el {
|
---|
| 13 | FitsHandlerInterface * fhi;
|
---|
| 14 | string clname;
|
---|
| 15 | };
|
---|
| 16 |
|
---|
| 17 | typedef list<hand_list_el> HandlerList;
|
---|
| 18 |
|
---|
| 19 | static HandlerList * hlistp = NULL;
|
---|
| 20 |
|
---|
| 21 | static inline void ChkHLP()
|
---|
| 22 | {
|
---|
[2843] | 23 | if (hlistp == NULL) hlistp = new HandlerList;
|
---|
[2820] | 24 | }
|
---|
| 25 |
|
---|
| 26 | int 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 |
|
---|
| 42 | int 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 |
|
---|
| 56 | FitsHandlerInterface* 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 |
|
---|
| 72 | void 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 |
|
---|
| 80 | void FitsManager::Read(FitsInOutFile& os, AnyDataObj & o)
|
---|
| 81 | {
|
---|
| 82 | FitsHandlerInterface * fhi2 = FindHandler(o)->Clone();
|
---|
| 83 | fhi2->SetDataObj(o);
|
---|
| 84 | fhi2->Read(os);
|
---|
| 85 | return;
|
---|
| 86 | }
|
---|