CMS 3D CMS Logo

IgPluginLoader.cc

Go to the documentation of this file.
00001 //<<<<<< INCLUDES                                                       >>>>>>
00002 
00003 #include "Iguana/Framework/interface/IgPluginLoader.h"
00004 #include "Iguana/Framework/interface/IgExtensionDB.h"
00005 #include "Iguana/Framework/interface/IgCapabilityDB.h"
00006 #include "classlib/utils/DebugAids.h"
00007 #include <algorithm>
00008 #include <cstring>
00009 
00010 //<<<<<< PRIVATE DEFINES                                                >>>>>>
00011 //<<<<<< PRIVATE CONSTANTS                                              >>>>>>
00012 //<<<<<< PRIVATE TYPES                                                  >>>>>>
00013 //<<<<<< PRIVATE VARIABLE DEFINITIONS                                   >>>>>>
00014 //<<<<<< PUBLIC VARIABLE DEFINITIONS                                    >>>>>>
00015 //<<<<<< CLASS STRUCTURE INITIALIZATION                                 >>>>>>
00016 
00017 IG_DEFINE_STATE_ELEMENT (IgPluginLoader, "Services/Global/Plugin Loader");
00018 
00019 //<<<<<< PRIVATE FUNCTION DEFINITIONS                                   >>>>>>
00020 //<<<<<< PUBLIC FUNCTION DEFINITIONS                                    >>>>>>
00021 //<<<<<< MEMBER FUNCTION DEFINITIONS                                    >>>>>>
00022 
00023 IgPluginLoader::IgPluginLoader (IgState *in)
00024     : m_state (in)
00025 {
00026     ASSERT (m_state);
00027     m_state->put (s_key, this);
00028 }
00029 
00030 void
00031 IgPluginLoader::load (const std::string &name, bool prefix /* = false */)
00032 { load (m_state, name, prefix); }
00033 
00034 void
00035 IgPluginLoader::load (IgState *state, const std::string &name,
00036                       bool prefix /* = false */)
00037 
00038 {
00039     IgExtensionDB *edb = IgExtensionDB::get ();
00040     IgCapabilityDB *cdb = IgCapabilityDB::get ();
00041 
00042     // If asked for an exact match, get the element or the capability
00043     // if it doesn't already exist in the state.  This assumes the
00044     // extensions' state key names match their plug-in catalog names.
00045     // For capabilities we don't care since the whole point is to just
00046     // attach the plug-in, and extra load attempts are simply ignored.
00047     if (! prefix && ! state->get (IgStateKey::index (name)))
00048     {
00049         edb->create (name, state);
00050         cdb->load (name);
00051     }
00052 
00053     // Otherwise, if we are looking for a prefix, load all extensions
00054     // and capabilities whose name begins with that prefix.  (FIXME:
00055     // Use regex match instead?)  (FIXME: std::string `compare'
00056     // methods are not very standard so avoid them.)
00057     else if (prefix)
00058     {
00059         const char      *pfx = name.c_str ();
00060         size_t          n = name.length ();
00061 
00062         IgExtensionDB::Iterator ext = edb->begin ();
00063         IgExtensionDB::Iterator lastext = edb->end ();
00064         for ( ; ext != lastext; ++ext)
00065             if (! strncmp ((*ext)->name ().c_str (), pfx, n))
00066                 load (state, (*ext)->name ());
00067 
00068         IgCapabilityDB::Iterator cap = cdb->begin ();
00069         IgCapabilityDB::Iterator lastcap = cdb->end();
00070         for ( ; cap != lastcap; ++cap)
00071             if (! strncmp ((*cap)->name ().c_str (), pfx, n))
00072                 load (state, (*cap)->name ());
00073     }
00074 }

Generated on Tue Jun 9 17:38:29 2009 for CMSSW by  doxygen 1.5.4