handler.hh
Go to the documentation of this file.
/* -*- mia-c++ -*-
*
* This file is part of MIA - a toolbox for medical image analysis
* Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
*
* MIA is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MIA; if not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef ph_handler_hh
#define ph_handler_hh
#include <string>
#include <map>
#include <set>
#include <vector>
#include <ostream>
#include <atomic>
#include <boost/any.hpp>
#include <mia/core/utils.hh>
#include <mia/core/filetools.hh>
#include <mia/core/defines.hh>
#include <mia/core/parallel.hh>
#include <mia/core/module.hh>
#include <mia/core/plugin_base.hh>
#include <mia/core/handlerbase.hh>
#include <mia/core/searchpath.hh>
#include <mia/core/import_handler.hh>
NS_MIA_BEGIN
template <typename I>
class EXPORT_HANDLER TPluginHandler: public CPluginHandlerBase
{
public:
typedef I Interface;
typedef std::shared_ptr<I> PInterface;
typedef std::map<std::string, PInterface> CPluginMap;
typedef typename CPluginMap::const_iterator const_iterator;
virtual ~TPluginHandler();
size_t size() const;
const std::string get_plugin_names() const;
const std::set<std::string> get_set() const;
const_iterator begin()const;
const_iterator end()const;
bool add_plugin(PInterface plugin);
protected:
void add_plugin_internal(PInterface plugin);
TPluginHandler();
typename TPluginHandler<I>::Interface *plugin(const char *plugin) const;
void initialise(const CPluginSearchpath& searchpath);
private:
virtual void do_initialise();
void do_add_dependend_handlers(HandlerHelpMap& handler_map) const;
std::vector<PPluginModule> m_modules;
CPluginMap m_plugins;
virtual void do_print_short_help(std::ostream& os) const;
virtual void do_print_help(std::ostream& os) const;
virtual void do_get_xml_help(CXMLElement& root) const;
static const char *const m_help;
};
template <typename T>
class EXPORT_HANDLER THandlerSingleton : public T
{
public:
static void set_search_path(const CPluginSearchpath& searchpath);
typedef T Instance;
typedef typename T::const_iterator const_iterator;
typedef typename T::CPluginMap::value_type value_type;
static const T& instance();
static bool add_plugin(typename T::PInterface p);
static const T *pointer();
protected:
static CMutex m_creation_mutex;
private:
// the constructor is private because you must not derive the singleton
// derive the handler if you need specific funcionality, and then
// template the singleton with the derived handler.
THandlerSingleton();
static T& do_instance(bool require_initialization);
static CPluginSearchpath m_searchpath;
static bool m_is_created;
static CMutex m_initialization_mutex;
static std::atomic<bool> m_is_initialized;
};
NS_MIA_END
#endif
CPluginHandlerBase::CPluginHandlerBase
CPluginHandlerBase(const char *data_descr, const char *type_descr)
CPluginSearchpath
Definition searchpath.hh:35
CXMLElement
This class implements a facade for the xml Element.
Definition xmlinterface.hh:50
THandlerSingleton::instance
static const T & instance()
THandlerSingleton::set_search_path
static void set_search_path(const CPluginSearchpath &searchpath)
THandlerSingleton::pointer
static const T * pointer()
THandlerSingleton< TFactoryPluginHandler< CSplineBoundaryConditionPlugin > >::m_creation_mutex
static CMutex m_creation_mutex
Definition handler.hh:193
THandlerSingleton< TFactoryPluginHandler< CSplineBoundaryConditionPlugin > >::value_type
TFactoryPluginHandler< CSplineBoundaryConditionPlugin >::CPluginMap::value_type value_type
Definition handler.hh:175
THandlerSingleton< TFactoryPluginHandler< CSplineBoundaryConditionPlugin > >::const_iterator
TFactoryPluginHandler< CSplineBoundaryConditionPlugin >::const_iterator const_iterator
Definition handler.hh:172
THandlerSingleton::add_plugin
static bool add_plugin(typename T::PInterface p)
THandlerSingleton< TFactoryPluginHandler< CSplineBoundaryConditionPlugin > >::Instance
TFactoryPluginHandler< CSplineBoundaryConditionPlugin > Instance
Definition handler.hh:169
TPluginHandler::get_set
const std::set< std::string > get_set() const
TPluginHandler::CPluginMap
std::map< std::string, PInterface > CPluginMap
a map containing the names and the available plug-ins
Definition handler.hh:65
TPluginHandler::end
const_iterator end() const
TPluginHandler::TPluginHandler
TPluginHandler()
Initializes the plugin handler based on the build-in search path.
TPluginHandler::initialise
void initialise(const CPluginSearchpath &searchpath)
TPluginHandler::add_plugin
bool add_plugin(PInterface plugin)
TPluginHandler::add_plugin_internal
void add_plugin_internal(PInterface plugin)
TPluginHandler::const_iterator
CPluginMap::const_iterator const_iterator
the iterator to walk over the available plug-ins
Definition handler.hh:68
TPluginHandler::PInterface
std::shared_ptr< I > PInterface
Definition handler.hh:62
TPluginHandler::get_plugin_names
const std::string get_plugin_names() const
TPluginHandler::Interface
I Interface
typedef for the plug-in interface provided by the class
Definition handler.hh:60
TPluginHandler::size
size_t size() const
TPluginHandler::~TPluginHandler
virtual ~TPluginHandler()
TPluginHandler::begin
const_iterator begin() const
Interface::plugin
TPluginHandler< I >::Interface * plugin(const char *plugin) const
EXPORT_HANDLER
#define EXPORT_HANDLER
Definition core/cost.hh:32
defines.hh
NS_MIA_BEGIN
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition defines.hh:33
NS_MIA_END
#define NS_MIA_END
conveniance define to end the mia namespace
Definition defines.hh:36
filetools.hh
HandlerHelpMap
std::map< std::string, const CPluginHandlerBase * > HandlerHelpMap
A map that is used to collect the plug-in handlers used in a program.
Definition handlerbase.hh:45
handlerbase.hh
import_handler.hh
module.hh
parallel.hh
CMutex
std::mutex CMutex
Definition parallelcxx11.hh:34
plugin_base.hh
searchpath.hh
utils.hh