emcOMHelper.h

Go to the documentation of this file.
00001 #ifndef __EMCOMHELPER_H__
00002 #define __EMCOMHELPER_H__
00003 
00004 #include "emcObjectManagerRegister.h"
00005 #include "emcObjectManager.h"
00006 #include "emcDataManager.h"
00007 #include "emcDefines.h"
00008 
00013 class emcOMHelper
00014 {
00015 public:
00016 
00017   static emcObjectManager* findOM(emcManageable& object, int to_or_from)
00018   {
00019     emcObjectManager* value = 0 ;
00020 
00021     emcObjectManagerMap cmap =
00022       emcObjectManagerRegister::GetInstance()->GetObjectManagerMap() ;
00023     emcObjectManagerMap::const_iterator it ;
00024 
00025     emcDataManager* dm = emcDataManager::GetInstance();
00026 
00027     if ( to_or_from == 0 )
00028       {
00029         for ( it = cmap.begin() ; it != cmap.end() && value == 0 ; it++)
00030           {
00031             emcObjectManagerMap::value_type entry = *it ;
00032             if (dm->GetVerboseLevel() >= 10)
00033               {
00034                 std::cout << "FindPlugin :"
00035                           << " Trying plugin "
00036                           << entry.second->GetName()
00037                           << std::endl;
00038               }
00039 
00040             if ( entry.second->CanRead(object) )
00041               {
00042                 value = entry.second ;
00043                 if ( dm->GetVerboseLevel() >= 10)
00044                   {
00045                     std::cout << "YES!!" << std::endl;
00046                   }
00047               }
00048             else
00049               {
00050                 if ( dm->GetVerboseLevel() >= 10)
00051                   {
00052                     std::cout << "NOPE" << std::endl;
00053                   }
00054               }
00055           }
00056       }
00057     else if ( to_or_from == 1 )
00058       {
00059         for ( it = cmap.begin() ; it != cmap.end() && value == 0 ; it++)
00060           {
00061             emcObjectManagerMap::value_type entry = *it ;
00062             if ( entry.second->CanWrite(object) )
00063               {
00064                 value = entry.second ;
00065               }
00066           }
00067       }
00068     else
00069       {
00070         std::cerr << EMC_ERROR_MSG << "FindPlugin : invalid "
00071                   << " second parameter = " << to_or_from << ", valid=0=>read "
00072           << " or 1=>write." << std::endl ;
00073       }
00074     
00075     if ( !value)
00076       {
00077         std::cerr << EMC_ERROR_MSG << "FindPlugin : could not "
00078                   << " find a suitable plugin for object name="
00079                   << object.GetName() << " title=" << object.GetTitle()
00080                   << " classname=" << object.GetClassName() << std::endl ;
00081       }
00082     
00083     return value;
00084   }
00085 };
00086 
00087 #endif
00088 
00089