openModeller
Version 1.4.0
|
00001 00028 #ifndef _ALGORITHM_FACTORYHH_ 00029 #define _ALGORITHM_FACTORYHH_ 00030 00031 #include <openmodeller/os_specific.hh> 00032 #include <openmodeller/AlgMetadata.hh> 00033 #include <openmodeller/Sampler.hh> 00034 #include <openmodeller/Algorithm.hh> 00035 00036 #include <openmodeller/Configuration.hh> 00037 00038 #include <string> 00039 #include <list> 00040 00041 class AlgParameter; 00042 00043 /****************************************************************/ 00044 /*********************** Algorithm Factory **********************/ 00045 00055 class dllexp AlgorithmFactory 00056 { 00057 00058 public: 00059 00060 ~AlgorithmFactory(); 00061 00065 static void setDefaultAlgDir( std::string const dir ); 00066 00070 static std::string getDefaultAlgDir(); 00071 00078 static int searchDefaultDirs(); 00079 00084 static int addDir( const std::string& dirs ); 00085 00090 static bool addDll( const std::string& file ); 00091 00108 static AlgMetadata const**availableAlgorithms(); 00109 00116 static int numAvailableAlgorithms(); 00117 00123 static AlgMetadata const *algorithmMetadata( std::string const algorithm_id ); 00124 00132 static AlgorithmPtr newAlgorithm( std::string const id ); 00133 00134 static AlgorithmPtr newAlgorithm( const ConstConfigurationPtr& ); 00135 00136 /* 00137 * Method to serialize the available algorithms 00138 * 00139 * Note that this class does not implement "Configurable" 00140 * because it cannot be instantiated from outside (singleton 00141 * pattern). Also the counterpart setConfiguration method is not 00142 * implemented in this case because it makes no sense to load 00143 * algorithms from XML - they can only be dynamically loaded 00144 * from the respective libraries. 00145 */ 00146 static ConfigurationPtr getConfiguration(); 00147 00155 static std::string const getCurrentId( std::string const algorithm_id ); 00156 00157 private: 00158 00159 AlgorithmFactory(); 00160 00161 static AlgorithmFactory& getInstance(); 00162 00163 // Default directory to search for algorithms 00164 std::string _default_alg_dir; 00165 00166 friend class testDLLId; 00167 class DLL; 00168 typedef ReferenceCountedPointer<DLL> DLLPtr; 00169 typedef std::list<DLLPtr> ListDLL; 00170 typedef std::list<std::string> PluginPath; 00171 00172 ListDLL _dlls; 00173 PluginPath _pluginpath; 00174 00179 int p_addDir( const std::string& dir ); 00180 00185 bool p_addDll( const std::string& file ); 00186 00188 class DLL : private ReferenceCountedObject 00189 { 00190 friend class ReferenceCountedPointer<DLL>; 00191 public: 00192 DLL(); 00193 DLL( const std::string& file ); 00194 ~DLL(); 00195 00196 operator bool() const; 00197 00199 AlgorithmPtr newAlgorithm(); 00200 00201 AlgMetadata const *getMetadata(); 00202 00203 private: 00204 DLLHandle _handle; 00205 TAlgFactory _factory; 00206 TAlgMetadata _metadata; 00207 std::string _file; 00208 }; 00209 00210 00211 }; 00212 00213 00214 #endif