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

JobCModuleRegistry.h

Go to the documentation of this file.
00001 
00002 // $Id: JobCModuleRegistry.h,v 1.16 2009/02/28 21:46:13 gmieg Exp $
00003 //
00004 // Provide a single registry for all job modules
00005 //
00006 // messier@huhepl.harvard.edu
00008 #ifndef JOBCMODULEREGISTRY_H
00009 #define JOBCMODULEREGISTRY_H
00010 
00011 #include <cassert>
00012 #ifndef LIST
00013 #include <list>
00014 #define LIST
00015 #endif
00016 #ifndef MAP
00017 #include <map>
00018 #define MAP
00019 #endif
00020 #ifndef STRING
00021 #include <string>
00022 #define STRING
00023 #endif
00024 #ifndef JOBCMODULEPROXY_H
00025 #include "JobControl/JobCModuleProxy.h"
00026 #endif
00027 #ifndef __CINT__ // CINT can't possibly understand this. Its C++!
00028 # ifdef SITE_HAS_SIGC // temporary work around
00029 #  ifndef SIGNAL_SYSTEM_H
00030 #   include <sigc++/signal.h>
00031 #   define SIGNAL_SYSTEM_H
00032 #  endif
00033 # endif
00034 #endif
00035 
00036 class JobCModule;
00037 
00038 class JobCModuleRegistry
00039 {
00040   friend std::ostream& operator<<(std::ostream& os, 
00041                                   const JobCModuleRegistry& jcr);
00042 public:
00043   ~JobCModuleRegistry();
00044 
00045   static JobCModuleRegistry& Instance();
00046 
00047   void             Register(JobCModuleProxy *jobcModuleProxy);
00048   JobCModuleProxy* LookUp(const char *name, bool loadlibs=true);
00049 
00050 private:
00051   // Singleton
00052   JobCModuleRegistry();
00053   JobCModuleRegistry(JobCModuleRegistry& /* jcmr */) { abort(); }
00054   JobCModuleRegistry& operator=(const JobCModuleRegistry& /* jcmr */ ) { 
00055     abort(); return *this;
00056   }
00057   int BuildModToLibMap();
00058   int CheckLibMap(const std::string& mod);
00059   struct Cleaner {
00060     void ClassIsUsed() { } // Dummy method to avoid compiler warnings
00061     ~Cleaner() {
00062       if (JobCModuleRegistry::fInstance!=0) {
00063         delete JobCModuleRegistry::fInstance;
00064         JobCModuleRegistry::fInstance = 0;
00065       }
00066     }
00067   };
00068   friend struct Cleaner;
00069 
00070 #ifdef SITE_HAS_SIGC // temporary
00071 # ifndef __CINT__
00072 public:
00073   // Define a signal for when a new module is loaded. Send the
00074   // module's name
00075   SigC::Signal1<void,const char*> SigRegister;
00076 # endif
00077 #endif
00078 
00079 private:
00080   static JobCModuleRegistry*        fInstance;   // The sole instance of class
00081   std::list<JobCModuleProxy*>       fModuleTable;// The set of proxies loaded
00082   std::map<std::string,std::string> fModLibMap;  // Module to library map
00083 };
00084 
00085 
00087 //
00088 // Define a macro to allow users to register their modules
00089 //
00091 #define JOBMODULE(CLASS, NAME, FUNC)                              \
00092 static class gs__Register__##CLASS##__ : public JobCModuleProxy { \
00093 public:                                                           \
00094   gs__Register__##CLASS##__() {                                   \
00095     fName = NAME;                                                 \
00096     fFunc = FUNC;                                                 \
00097     JobCModuleRegistry::Instance().Register(this);                \
00098   }                                                               \
00099   JobCModule *CreateModule()       {                              \
00100     JobCModule* m = new CLASS();                                  \
00101     m->Init(NAME);                                                \
00102     return m;                                                     \
00103   }                                                               \
00104 } gs__module__##CLASS##__proxy__
00105 
00106 #endif // JOBCMODULEREGISTRY_H

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