Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

JobCPathRegistry.cxx

Go to the documentation of this file.
00001 
00002 // $Id: JobCPathRegistry.cxx,v 1.9 2009/02/28 21:46:13 gmieg Exp $
00003 //
00004 // A class to manage and store job paths
00005 //
00006 // messier@huhepl.harvard.edu
00008 #include "JobControl/JobCPathRegistry.h"
00009 #include "MessageService/MsgService.h"
00010 #include "JobControl/JobCPath.h"
00011 
00012 #include <cassert>
00013 #include <cstring> // strcmp()
00014 
00015 using namespace std;
00016 
00017 CVSID("$Id: JobCPathRegistry.cxx,v 1.9 2009/02/28 21:46:13 gmieg Exp $");
00018 
00019 //......................................................................
00020 
00021 JobCPathRegistry::JobCPathRegistry()
00022 { 
00023   // Initially make room for 10 paths
00024   fPathList.reserve(10);
00025 }
00026 
00027 //......................................................................
00028 
00029 JobCPathRegistry::~JobCPathRegistry() 
00030 {
00031 //======================================================================
00032 // Purpose: Delete the paths held by this class
00033 //======================================================================
00034   std::vector<JobCPath*>::iterator itrPath(fPathList.begin());
00035   std::vector<JobCPath*>::iterator itrEnd(fPathList.end());
00036   for (; itrPath != itrEnd; ++itrPath) {
00037     delete (*itrPath);
00038   }
00039 }
00040 
00041 //......................................................................
00042 
00043 JobCModule* JobCPathRegistry::LookUpModule(const char* module) const 
00044 {
00045 //======================================================================
00046 // Purpose: Look up a named module in all the existing paths
00047 //
00048 // Input:   mod - The name of the module to look up
00049 //
00050 // Returns: Pointer to the specified job module or 0 if a module with
00051 //          this name cannot be found or there are two modules that 
00052 //          match this name.
00053 //======================================================================
00054 
00055   // Require exactly one match to module name
00056   int nmatch = 0;                      // Number of matches found
00057   JobCModule* jmtry;                   // a path that matches
00058   JobCModule* jm;                      // last match in list
00059   
00060   // Loop over paths looking for modules in them
00061   jmtry = 0;
00062   jm    = 0;
00063   vector<JobCPath*>::const_iterator itrPath(fPathList.begin());
00064   vector<JobCPath*>::const_iterator itrEnd(fPathList.end());
00065   for (; itrPath != itrEnd; ++itrPath) {
00066     jmtry = (*itrPath)->GetModule(module);
00067     if (jmtry!=0) {
00068       jm = jmtry;
00069       MSG("JobC",Msg::kVerbose) << 
00070         "Found " << module << " in path " << (*itrPath)->GetName() << "\n";
00071       ++nmatch;
00072     }
00073   }
00074   
00075   // Check return conditions -- search is sucessful if exactly one
00076   // module was found
00077   // Unique match
00078   if (nmatch == 1) {
00079     // Success - return the last (and only) match in the path
00080     return jm;
00081   }
00082   else if (nmatch > 1) {
00083     // Too many matches
00084     MSG("JobC",Msg::kWarning) << 
00085       "Module specification not unique!\n" <<
00086       " '" << module << "' matches " << nmatch << " possible modules.\n" <<
00087       " Please specify the path name for the module you want, eg:\n" <<
00088       " /[path_name]/[module_name]" << endl;
00089     return 0;
00090   }
00091 
00092   // Module not found -- fall through to here
00093   return 0;
00094 }
00095 
00096 //......................................................................
00097 
00098 JobCPath* JobCPathRegistry::LookUpPath(const char* path) const
00099 {
00100 //======================================================================
00101 // Purpose: Loop over existing paths looking for one called "path"
00102 //
00103 // Returns: Pointer to the path if found
00104 //          0 - no matching path found
00105 //======================================================================
00106   // Creation of duplicate path names is not allowed by MakePath, so
00107   // don't bother checking here.
00108   std::vector<JobCPath*>::const_iterator itrPath(fPathList.begin());
00109   std::vector<JobCPath*>::const_iterator itrEnd(fPathList.end());
00110   for (; itrPath != itrEnd; ++itrPath) {
00111     if (strcmp(path,(*itrPath)->GetName())==0) {
00112       return (*itrPath);
00113     }
00114   }
00115   return 0;
00116 }
00117 
00118 //......................................................................
00119 
00120 JobCPath* JobCPathRegistry::MakePath(const char*      name, 
00121                                      MomNavigator*    mom, 
00122                                      JobCInputModule* inp)
00123 {
00124 //======================================================================
00125 // Purpose: Create a named path
00126 //======================================================================
00127   // Don't allow duplicate path names
00128   JobCPath* path(this->LookUpPath(name));
00129   if (path != 0) {
00130     MSG("JobC",Msg::kWarning) << 
00131       " Path '" << name << "' already exists!\n";
00132     return 0;
00133   }
00134 
00135   // Create the path and add it to the list ** Remember this module
00136   // owns the paths and has the responsibility to delete them! **
00137   path = new JobCPath(name,mom,inp);
00138   assert(path);
00139   fPathList.push_back(path);
00140 #ifdef SITE_HAS_SIGC
00141   this->NewPath(path);
00142 #endif
00143   return path;
00144 }
00145 
00146 //......................................................................
00147 
00148 void JobCPathRegistry::DeletePath(const char* path)
00149 {
00150 //======================================================================
00151 // Purpose: Remove a named path from the list of paths
00152 //======================================================================
00153   // Find the path in the table
00154   vector<JobCPath*>::iterator itrPath(fPathList.begin());
00155   vector<JobCPath*>::iterator itrEnd(fPathList.end());
00156   for (; itrPath != itrEnd; ++itrPath) {
00157     if (strcmp(path,(*itrPath)->GetName())==0) {
00158       delete (*itrPath);        // Delete the path pointed to
00159       (*itrPath) = 0;           // Set the path pointer to zero
00160       fPathList.erase(itrPath); // Remove the element from the vector
00161     }
00162   }
00163 }
00164 
00165 //......................................................................
00166 
00167 void JobCPathRegistry::Reset() 
00168 {
00169 //======================================================================
00170 // Delete all active paths
00171 //======================================================================
00172   std::vector<JobCPath*>::iterator itrPath(fPathList.begin());
00173   std::vector<JobCPath*>::iterator itrEnd(fPathList.end());
00174   for (; itrPath != itrEnd; ++itrPath) {
00175     delete (*itrPath); // Delete the path pointed to
00176     (*itrPath) = 0;    // Set the path pointer to zero
00177   }
00178   fPathList.erase(fPathList.begin(),itrEnd);
00179 }
00180 

Generated on Mon Feb 15 11:06:49 2010 for loon by  doxygen 1.3.9.1