emcObjectFillerRegistry.C

Go to the documentation of this file.
00001 #include "emcObjectFillerRegistry.h"
00002 #include "emcObjectFiller.h"
00003 #include <iostream>
00004 
00005 using namespace std;
00006 
00007 //_____________________________________________________________________________
00008 void
00009 emcObjectFillerRegistry::add(emcObjectFiller* oc)
00010 {
00011   fillers()->push_back(oc);
00012 }
00013 
00014 //_____________________________________________________________________________
00015 void
00016 emcObjectFillerRegistry::remove(emcObjectFiller* oc)
00017 {
00018   fillers()->remove(oc);
00019 }
00020 
00021 //_____________________________________________________________________________
00022 emcObjectFiller*
00023 emcObjectFillerRegistry::findFiller(PHCompositeNode* topNode, PHObject& dest,
00024                                    int verbose)
00025 {
00026   if ( fillers()->empty() ) 
00027     {
00028       cerr << "emcObjectFillerRegistry::findFiller : not a single filler "
00029            << "available at this time! Sorry."
00030            << endl;
00031       return 0;
00032     }
00033 
00034   list<emcObjectFiller*>::iterator it;
00035 
00036   list<emcObjectFiller*>* thelist = fillers();
00037 
00038   emcObjectFiller* filler = 0;
00039 
00040   for ( it = thelist->begin(); it != thelist->end(); it++ ) 
00041     {
00042       if ( (*it)->canFill(topNode,dest,verbose) )
00043         {
00044           if ( filler==0 ) 
00045             {
00046               filler = *it;
00047             }
00048           else
00049             {
00050               cerr << "emcObjectFillerRegistery::findFiller : "
00051                    << " More than one suitable Filler found !"
00052                    << endl
00053                    << "Do you really expect ME to decide which one to "
00054                    << " use ? No way. " 
00055                    << endl;
00056               filler = 0;
00057               break;
00058             }
00059         }
00060     }
00061 
00062   return filler;
00063 
00064 }
00065 
00066 //_____________________________________________________________________________
00067 emcObjectFiller*
00068 emcObjectFillerRegistry::findFiller(PHObject& dest,
00069                                    int verbose)
00070 {
00071   list<emcObjectFiller*>::iterator it;
00072   list<emcObjectFiller*>* thelist = fillers();
00073 
00074   emcObjectFiller* filler = 0;
00075 
00076   for ( it = thelist->begin(); it != thelist->end(); it++ ) 
00077     {
00078       if ( (*it)->canFill(dest,verbose) )
00079         {
00080           if ( filler==0 ) 
00081             {
00082               filler = *it;
00083             }
00084           else
00085             {
00086               cerr << "emcObjectFillerRegistery::findFiller : "
00087                    << " More than one suitable Filler found !"
00088                    << endl
00089                    << "Do you really expect ME to decide which one to "
00090                    << " use ? No way. " 
00091                    << endl;
00092               filler = 0;
00093               break;
00094             }
00095         }
00096     }
00097   return filler;
00098 }
00099 
00100 
00101 //_____________________________________________________________________________
00102 list<emcObjectFiller*>*
00103 emcObjectFillerRegistry::fillers(void)
00104 {
00105   static list<emcObjectFiller*> thelist;
00106   return &thelist;
00107 }
00108 
00109 //_____________________________________________________________________________
00110 void
00111 emcObjectFillerRegistry::print(ostream& out)
00112 {
00113   out << "emcObjectFillerRegistry : here are my ObjectFillers :"
00114       << endl;
00115 
00116   list<emcObjectFiller*>::iterator it;
00117 
00118   list<emcObjectFiller*>* thelist = fillers();
00119 
00120   for ( it = thelist->begin(); it != thelist->end(); it++ ) 
00121     {
00122       (*it)->identify(out);
00123     }
00124 }