30 #define _SCL_SECURE_NO_DEPRECATE
53 return !strcmp(
id.c_str(), dll->getMetadata()->id.c_str() );
98 Log::instance()->
warn(
"Algorithm %s is not openModeller compatible! (TAlgFactory mismatch)\n", file.c_str() );
108 Log::instance()->
warn(
"Algorithm %s is not openModeller compatible! (TAlgMetadata mismatch)\n", file.c_str() );
128 Log::instance()->
debug(
"- Unloading: %s ...currently, dlls are not closed.\n", _file.c_str() );
136 AlgorithmFactory::DLL::operator bool()
const
138 return ( _handle != 0 );
156 return (*_metadata)();
218 int dll_count = af.
_dlls.size();
226 if ( dll_count > 0 ) {
229 ListDLL::iterator dll = af.
_dlls.begin();
231 *metadata = (*dll)->getMetadata();
248 int dll_count = af.
_dlls.size();
259 if ( 0 ==
id.size() ) {
261 string msg =
"Algorithm id not specified.\n";
273 ListDLL::iterator dll = find_if( af.
_dlls.begin(), af.
_dlls.end(), test );
275 if ( dll != af.
_dlls.end() ) {
277 return (*dll)->getMetadata();
280 string msg(
"Algorithm ");
296 int dll_count = af.
_dlls.size();
298 if ( dll_count == 0 ) {
300 string msg =
"No algorithms loaded.\n";
311 ListDLL::iterator dll = find_if( af.
_dlls.begin(), af.
_dlls.end(), test );
313 if ( dll != af.
_dlls.end() ) {
315 return (*dll)->newAlgorithm();
318 string msg(
"Algorithm ");
332 string id = config->getAttribute(
"Id" );
343 alg->setConfiguration( config );
354 vector<string>::iterator it = entries.begin();
356 while( it != entries.end() ) {
378 if ( dir.length() ) {
382 if ( entries.empty() ) {
388 vector<string>::const_iterator it = entries.begin();
390 while( it != entries.end() ) {
427 _dlls.push_back( dll );
441 int dll_count = af.
_dlls.size();
444 if ( dll_count > 0 ) {
447 ListDLL::iterator dll = af.
_dlls.begin();
449 for ( ; dll != af.
_dlls.end(); ++dll ) {
453 AlgMetadata const *algMetadata = (*dll)->getMetadata();
455 alg_meta_config->addNameValue(
"Id", algMetadata->
id );
456 alg_meta_config->addNameValue(
"Version", algMetadata->
version );
459 alg_name_config->setValue( algMetadata->
name );
460 alg_meta_config->addSubsection( alg_name_config );
463 alg_overview_config->setValue( algMetadata->
overview );
464 alg_meta_config->addSubsection( alg_overview_config );
467 alg_description_config->setValue( algMetadata->
description );
468 alg_meta_config->addSubsection( alg_description_config );
472 alg_designer_config->addNameValue(
"Name", algMetadata->
author );
473 alg_designers_config->addSubsection( alg_designer_config );
474 alg_meta_config->addSubsection( alg_designers_config );
477 alg_bibliography_config->setValue( algMetadata->
biblio );
478 alg_meta_config->addSubsection( alg_bibliography_config );
482 alg_developer_config->addNameValue(
"Name", algMetadata->
code_author );
483 alg_developer_config->addNameValue(
"Contact", algMetadata->
contact );
484 alg_developers_config->addSubsection( alg_developer_config );
485 alg_meta_config->addSubsection( alg_developers_config );
488 char const *accepts_categorical = ( algMetadata->
categorical ) ?
"1" :
"0";
489 alg_categorical_config->setValue( accepts_categorical );
490 alg_meta_config->addSubsection( alg_categorical_config );
493 char const *requires_absences = ( algMetadata->
absence ) ?
"1" :
"0";
494 alg_absences_config->setValue( requires_absences );
495 alg_meta_config->addSubsection( alg_absences_config );
502 for (
int i=0 ; i < algMetadata->
nparam; param++, i++ ) {
506 param_config->addNameValue(
"Id", param->
id );
509 param_name_config->setValue( param->
name );
510 param_config->addSubsection( param_name_config );
512 string datatype(
"?");
516 datatype =
"Integer";
528 param_type_config->setValue( datatype.c_str() );
529 param_config->addSubsection( param_type_config );
532 param_overview_config->setValue( param->
overview );
533 param_config->addSubsection( param_overview_config );
536 param_description_config->setValue( param->
description );
537 param_config->addSubsection( param_description_config );
545 param_range_config->addNameValue(
"Min", param->
min_val );
549 param_range_config->addNameValue(
"Max", param->
max_val );
552 param_config->addSubsection( param_range_config );
556 param_default_config->setValue( param->
typical );
557 param_config->addSubsection( param_default_config );
559 params_config->addSubsection( param_config );
562 alg_meta_config->addSubsection( params_config );
564 config->addSubsection( alg_meta_config );
577 if ( algorithm_id ==
"EnvironmentalDistance" ) {
579 return string(
"ENVDIST" );
581 else if ( algorithm_id ==
"Bioclim") {
583 return string(
"BIOCLIM" );
585 else if ( algorithm_id ==
"EnvelopeScore" ) {
587 return string(
"ENVSCORE" );
589 else if ( algorithm_id ==
"AquaMaps" ) {
591 return string(
"AQUAMAPS" );
vector< string > scanDirectory(string dir)
static AlgorithmFactory & getInstance()
void warn(const char *format,...)
'Warn' level.
testDLLId(string const id)
AlgorithmPtr newAlgorithm()
static AlgorithmPtr newAlgorithm(std::string const id)
void * dllFunction(DLLHandle handle, char const *function_name)
static AlgMetadata const ** availableAlgorithms()
AlgMetadata const * getMetadata()
static std::string getDefaultAlgDir()
int dllClose(DLLHandle handle)
static Log * instance()
Returns the instance pointer, creating the object on the first call.
AlgorithmImpl *(* TAlgFactory)()
ReferenceCountedPointer< AlgorithmImpl > AlgorithmPtr
void error(const char *format,...)
'Error' level.
int p_addDir(const std::string &dir)
static ConfigurationPtr getConfiguration()
static void setDefaultAlgDir(std::string const dir)
bool operator()(const AlgorithmFactory::DLLPtr &dll)
std::string _default_alg_dir
static int searchDefaultDirs()
static bool addDll(const std::string &file)
vector< string > initialPluginPath()
static int numAvailableAlgorithms()
bool p_addDll(const std::string &file)
static AlgMetadata const * algorithmMetadata(std::string const algorithm_id)
static std::string const getCurrentId(std::string const algorithm_id)
AlgMetadata *(* TAlgMetadata)()
DLLHandle dllOpen(char const *dll_file_name)
static int addDir(const std::string &dirs)
void debug(const char *format,...)
'Debug' level.
const char * dllError(DLLHandle)