#include "ICOMETLog.hxx" #include "IMidasBankProxy.hxx" #include "IMidasBankProxyRegistry.hxx" ClassImp(COMET::IMidasBankProxyRegistry); COMET::IMidasBankProxyRegistry* COMET::IMidasBankProxyRegistry::fInstance = 0; //_____________________________________________________________________________ COMET::IMidasBankProxyRegistry::IMidasBankProxyRegistry() { // Default constructor COMETTrace("IMidasBankProxyRegistry: Default ctor at:" << (void*) this); } //_____________________________________________________________________________ COMET::IMidasBankProxyRegistry::~IMidasBankProxyRegistry() { COMETTrace("COMET::IMidasBankProxyRegistry: dtor at:" << (void*) this); // dtor is NOT responsible for destroying elements of the list; // they are created statically and are thus automagically // destroyed when the process ends } //_____________________________________________________________________________ void COMET::IMidasBankProxyRegistry::Print() { COMETLog("Contents of Singleton IMidasBankProxyRegistry:-"); std::list::iterator itr(fMidasBankProxyTable.begin()), itrEnd(fMidasBankProxyTable.end()); while ( itr != itrEnd ) { IMidasBankProxy& proxy = **itr; COMETLog(" " << proxy.GetMidasBankMasks() << " -> " << proxy.GetName()); ++itr; } } //_____________________________________________________________________________ void COMET::IMidasBankProxyRegistry::Register(IMidasBankProxy *proxy) { const std::string mask = proxy->GetMidasBankMasks(0); // Check that the proxy has not already been registered if (this->LookUp(mask)) { COMETWarn("IMidasBankProxyRegistry:The bank mask '" << mask << "' is already registered!\n" << "Duplicate masks are not allowed!\n"); return; } else { // Do insertions in alphabetical order std::list::iterator itr(fMidasBankProxyTable.begin()), itrEnd(fMidasBankProxyTable.end()); for (; itr != itrEnd; ++itr) if ( mask < (*itr)->GetMidasBankMasks() ) break; fMidasBankProxyTable.insert(itr,proxy); COMETTrace("IMidasBankProxyRegistry: Registered mask " << mask << " proxy @ " << proxy); } } //_____________________________________________________________________________ COMET::IMidasBankProxy* COMET::IMidasBankProxyRegistry::LookUp(const std::string midasBankName) const { // Look up matching proxy in the table. std::list::const_iterator itr(fMidasBankProxyTable.begin()), itrEnd(fMidasBankProxyTable.end()); for (; itr != itrEnd; ++itr) if ((*itr)->MatchesMidasBankName(midasBankName)) return *itr; return 0; } //_____________________________________________________________________________ COMET::IMidasBankProxyRegistry& COMET::IMidasBankProxyRegistry::Instance() { if (fInstance==0) { fInstance = new IMidasBankProxyRegistry(); } return *fInstance; }