WSL/SLF GitLab Repository

Commit f3326a77 authored by Mathias Bavay's avatar Mathias Bavay
Browse files

The plugins are now handled by an object factory, removing the need for the...

The plugins are now handled by an object factory, removing the need for the IOPlugin class. Otherwise, small documentation update in GeneratorAlgorithms.
parent aa8234f7
......@@ -28,7 +28,6 @@ ENDIF(DATA_QA)
SET(meteoio_sources
${dataClasses_sources}
IOManager.cc
IOPlugin.cc
MeteoProcessor.cc
ResamplingAlgorithms.cc
ResamplingAlgorithms2D.cc
......
......@@ -255,8 +255,7 @@ class ClearSkyLWGenerator : public GeneratorAlgorithm {
/**
* @class AllSkyLWGenerator
* @brief ILWR all sky parametrization
* HACK: the cloud fraction is currently NOT implemented! This will come shortly...
* Using air temperature (TA) and relative humidity (RH) ands cloud fraction (),
* Using air temperature (TA) and relative humidity (RH) and optionnally cloud fraction (TAU_CLD, but please note that this name is not definitive yet),
* this offers the choice of several all-sky parametrizations:
* - OMSTEDT -- from Omstedt, <i>"A coupled one-dimensional sea ice-ocean model applied to a semi-enclosed basin"</i>,
* Tellus, <b>42 A</b>, 568-582, 1990, DOI:10.1034/j.1600-0870.1990.t01-3-00007.
......
......@@ -133,57 +133,58 @@ namespace mio {
* limitation is that the parameter providing the raw data must be defined for all stations (even if filled with nodata, this is good enough).
*/
void IOHandler::registerPlugins()
IOInterface* IOHandler::getPlugin(const std::string& plugin_name) const
{
//mapPlugins[io.ini KEY]= IOPlugin(library file name, class name, NULL, NULL);
#ifdef PLUGIN_ARCIO
mapPlugins["ARC"] = IOPlugin("ARCIO", NULL, &IOPlugin::createInstance<ARCIO>);
if (plugin_name == "ARC") return new ARCIO(cfg);
#endif
#ifdef PLUGIN_A3DIO
mapPlugins["A3D"] = IOPlugin("A3DIO", NULL, &IOPlugin::createInstance<A3DIO>);
if (plugin_name == "A3D") return new A3DIO(cfg);
#endif
#ifdef PLUGIN_ARPSIO
mapPlugins["ARPS"] = IOPlugin("ARPSIO", NULL, &IOPlugin::createInstance<ARPSIO>);
if (plugin_name == "ARPS") return new ARPSIO(cfg);
#endif
#ifdef PLUGIN_GRASSIO
mapPlugins["GRASS"] = IOPlugin("GrassIO", NULL, &IOPlugin::createInstance<GrassIO>);
if (plugin_name == "GRASS") return new GrassIO(cfg);
#endif
#ifdef PLUGIN_GEOTOPIO
mapPlugins["GEOTOP"] = IOPlugin("GeotopIO", NULL, &IOPlugin::createInstance<GeotopIO>);
if (plugin_name == "GEOTOP") return new GeotopIO(cfg);
#endif
#ifdef PLUGIN_SMETIO
mapPlugins["SMET"] = IOPlugin("SMETIO", NULL, &IOPlugin::createInstance<SMETIO>);
if (plugin_name == "SMET") return new SMETIO(cfg);
#endif
#ifdef PLUGIN_SNIO
mapPlugins["SNOWPACK"] = IOPlugin("SNIO", NULL, &IOPlugin::createInstance<SNIO>);
if (plugin_name == "SNOWPACK") return new SNIO(cfg);
#endif
#ifdef PLUGIN_PGMIO
mapPlugins["PGM"] = IOPlugin("PGMIO", NULL, &IOPlugin::createInstance<PGMIO>);
if (plugin_name == "PGM") return new PGMIO(cfg);
#endif
#ifdef PLUGIN_IMISIO
mapPlugins["IMIS"] = IOPlugin("ImisIO", NULL, &IOPlugin::createInstance<ImisIO>);
if (plugin_name == "IMIS") return new ImisIO(cfg);
#endif
#ifdef PLUGIN_GRIBIO
mapPlugins["GRIB"] = IOPlugin("GRIBIO", NULL, &IOPlugin::createInstance<GRIBIO>);
if (plugin_name == "GRIB") return new GRIBIO(cfg);
#endif
#ifdef PLUGIN_PNGIO
mapPlugins["PNG"] = IOPlugin("PNGIO", NULL, &IOPlugin::createInstance<PNGIO>);
if (plugin_name == "PNG") return new PNGIO(cfg);
#endif
#ifdef PLUGIN_BORMAIO
mapPlugins["BORMA"] = IOPlugin("BormaIO", NULL, &IOPlugin::createInstance<BormaIO>);
if (plugin_name == "BORMA") return new BormaIO(cfg);
#endif
#ifdef PLUGIN_COSMOXMLIO
mapPlugins["COSMOXML"] = IOPlugin("CosmoXMLIO", NULL, &IOPlugin::createInstance<CosmoXMLIO>);
if (plugin_name == "COSMOXML") return new CosmoXMLIO(cfg);
#endif
#ifdef PLUGIN_GSNIO
mapPlugins["GSN"] = IOPlugin("GSNIO", NULL, &IOPlugin::createInstance<GSNIO>);
if (plugin_name == "GSN") return new GSNIO(cfg);
#endif
#ifdef PLUGIN_NETCDFIO
mapPlugins["NETCDF"] = IOPlugin("NetCDFIO", NULL, &IOPlugin::createInstance<NetCDFIO>);
if (plugin_name == "NETCDF") return new NetCDFIO(cfg);
#endif
#ifdef PLUGIN_PSQLIO
mapPlugins["PSQL"] = IOPlugin("PSQLIO", NULL, &IOPlugin::createInstance<PSQLIO>);
if (plugin_name == "PSQL") return new PSQLIO(cfg);
#endif
return NULL; //no plugin found
}
//Copy constructor
......@@ -195,20 +196,15 @@ IOHandler::IOHandler(const IOHandler& aio)
IOHandler::IOHandler(const Config& cfgreader)
: IOInterface(), cfg(cfgreader), mapPlugins(), copy_parameter(), copy_name(), enable_copying(false)
{
registerPlugins();
parse_copy_config();
}
IOHandler::~IOHandler() throw()
{
// Get rid of the objects
std::map<std::string, IOPlugin>::iterator mapit;
for (mapit = mapPlugins.begin(); mapit!=mapPlugins.end(); ++mapit){
IOInterface*& io = (mapit->second).io;
if (io != NULL) {
delete io;
io = NULL;
}
std::map<std::string, IOInterface*>::iterator mapit;
for (mapit = mapPlugins.begin(); mapit!=mapPlugins.end(); ++mapit) {
delete mapit->second;
}
}
......@@ -227,19 +223,13 @@ IOInterface* IOHandler::getPlugin(const std::string& cfgkey, const std::string&
std::string op_src;
cfg.getValue(cfgkey, cfgsection, op_src);
const std::map<std::string, IOPlugin>::iterator mapit = mapPlugins.find(op_src);
if (mapit == mapPlugins.end())
throw IOException("Cannot find plugin " + op_src + " as requested in file " + cfg.getSourceName() + ". Has it been activated through ccmake? Is it registered in IOHandler::registerPlugins?", AT);
if ((mapit->second).io == NULL){
(mapit->second).io = (mapit->second).creator_func(cfg);
}
//Now check if it is correctly loaded
if ((mapit->second).io == NULL) {
throw IOException("Requesting to read/write data with plugin '" + op_src + "', but plugin is not loaded", AT);
if (mapPlugins.find(op_src) == mapPlugins.end()) {
mapPlugins[op_src] = getPlugin(op_src);
if (mapPlugins[op_src]==NULL)
throw IOException("Cannot find plugin " + op_src + " as requested in file " + cfg.getSourceName() + ". Has it been activated through ccmake? Is it registered in IOHandler::registerPlugins?", AT);
}
return (mapit->second).io;
return mapPlugins[op_src];
}
void IOHandler::read2DGrid(Grid2DObject& grid_out, const std::string& i_filename)
......@@ -421,10 +411,9 @@ const std::string IOHandler::toString() const
os << "Config& cfg = " << hex << &cfg << dec << "\n";
os << "<mapPlugins>\n";
os << setw(10) << "Keyword" << " = " << IOPlugin::header << "\n";
std::map<std::string, IOPlugin>::const_iterator it1;
for (it1=mapPlugins.begin(); it1 != mapPlugins.end(); ++it1){
os << setw(10) << it1->first << " = " << it1->second.toString();
std::map<std::string, IOInterface*>::const_iterator it1;
for (it1=mapPlugins.begin(); it1 != mapPlugins.end(); ++it1) {
os << setw(10) << it1->first << " = " << hex << it1->second << dec << "\n";
}
os << "</mapPlugins>\n";
os << "</IOHandler>\n";
......
......@@ -20,7 +20,6 @@
#include <meteoio/IOInterface.h>
#include <meteoio/IOExceptions.h>
#include <meteoio/IOPlugin.h>
#include <map>
#include <string>
......@@ -65,14 +64,14 @@ class IOHandler : public IOInterface {
const std::string toString() const;
private:
void registerPlugins();
IOInterface *getPlugin(const std::string& cfgkey, const std::string& cfgsection="GENERAL");
IOInterface* getPlugin(const std::string& plugin_name) const;
IOInterface* getPlugin(const std::string& cfgkey, const std::string& cfgsection);
void parse_copy_config();
void checkTimestamps(const std::vector<METEO_SET>& vecVecMeteo) const;
void copy_parameters(const size_t& stationindex, std::vector< METEO_SET >& vecMeteo) const;
const Config& cfg;
std::map<std::string, IOPlugin> mapPlugins;
std::map<std::string, IOInterface*> mapPlugins;
std::vector<std::string> copy_parameter, copy_name;
bool enable_copying;
};
......
/***********************************************************************************/
/* Copyright 2010 WSL Institute for Snow and Avalanche Research SLF-DAVOS */
/***********************************************************************************/
/* This file is part of MeteoIO.
MeteoIO is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
MeteoIO is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
*/
#include <meteoio/IOPlugin.h>
namespace mio {
const std::string IOPlugin::header="<IOPlugin> classname, &class, &creator_func</IOPlugin>";
IOPlugin& IOPlugin::operator=(const IOPlugin& source)
{
//since this represents a plugin on a given machine/node, since the pointers point to entry points
//in the compiled code, they should remain valid and therefore can be copied
if(this != &source) {
classname = source.classname;
io = source.io;
creator_func = source.creator_func;
}
return *this;
}
const std::string IOPlugin::toString() const {
std::ostringstream os;
const int pt_w=8;
os << "<IOPlugin>" << std::setw(10) << classname;
os << "," << std::showbase << std::setw(pt_w+2) << io;
os << "," << std::showbase << std::setw(pt_w+2) << creator_func << "</IOPlugin>\n";
return os.str();
}
} //end namespace
/***********************************************************************************/
/* Copyright 2009 WSL Institute for Snow and Avalanche Research SLF-DAVOS */
/***********************************************************************************/
/* This file is part of MeteoIO.
MeteoIO is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
MeteoIO is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __IOPLUGIN_H__
#define __IOPLUGIN_H__
#include <meteoio/IOInterface.h>
namespace mio {
/**
* @class IOPlugin
* @brief A helper class representing a MeteoIO plugin in the context of the dynamic loading as implemented in class
* IOHandler. Each IOPlugin object represents an implementation of IOInterface or in more tangible terms it represents
* an instance of IOInterface in use. The two pointer member variables *io and *dynLibrary represent the opened
* dynamic library and the loaded object (from within that library). These pointers are essential for knowing
* how to deallocate the loaded object and library.
*
* @author Thomas Egger
* @date 2009-08-11
*/
class IOPlugin {
public:
std::string classname; ///< Classname of the object to be loaded from that dynamic library (e.g. "A3DIO")
IOInterface *io; ///< The pointer to the actual dynamically loaded instance of IOInterface
IOInterface* (*creator_func)(const Config&); ///< The function pointer to the instantiation function
/**
* @brief The main constructor for the IOPlugin class
*
* @param i_s2 A std::string that is the classname of the object to be loaded (e.g. "A3DIO", "GSNIO")
* @param p1 A pointer to the loaded object of type IOInterface (or NULL)
* @param p2 A pointer to the loaded dynamic library (or NULL)
*/
IOPlugin(std::string i_s2, IOInterface *p1, IOInterface*(*p2)(const Config&)) : classname(i_s2), io(p1), creator_func(p2){}
IOPlugin() : classname(""), io(NULL), creator_func(NULL){}
IOPlugin(const IOPlugin& c) : classname(c.classname), io(c.io), creator_func(c.creator_func){}
IOPlugin& operator=(const IOPlugin& source);
template<typename T> static IOInterface* createInstance(const Config& cfg) { return new T(cfg); }
const std::string toString() const;
static const std::string header; //to contain a helpful header for understanding the output of <<
};
} //end namespace
#endif
......@@ -53,7 +53,6 @@
#include <meteoio/IOHandler.h>
#include <meteoio/IOInterface.h>
#include <meteoio/IOManager.h>
#include <meteoio/IOPlugin.h>
#include <meteoio/IOUtils.h>
//#include <meteoio/MainPage.h> //only for doxygen
#include <meteoio/MathOptim.h>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment