iohandler.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_IOhandler_hh
#define ph_IOhandler_hh
#include <set>
#include <mia/core/handler.hh>
#include <mia/core/ioplugin.hh>
#include <mia/core/delayedparameter.hh>
NS_MIA_BEGIN
template <class I>
class EXPORT_HANDLER TIOPluginHandler: public TPluginHandler<I>
{
public:
typedef typename I::Data Data;
typedef typename std::shared_ptr<Data > PData;
typedef typename TPluginHandler<I>::Interface Interface;
typedef typename TPluginHandler<I>::const_iterator const_iterator;
typedef std::multimap<std::string, std::string> CSuffixmap;
typedef TDelayedParameter<PData> DataKey;
PData load(const std::string& fname) const;
DataKey load_to_pool(const std::string& fname) const;
bool save(const std::string& fname, const Data& data) const;
const Interface *preferred_plugin_ptr(const std::string& fname) const;
const Interface& preferred_plugin(const std::string& fname) const;
const CSuffixmap& get_supported_filetype_map() const;
const std::string get_supported_suffixes() const;
const std::set<std::string> get_supported_suffix_set() const;
std::string get_preferred_suffix(const std::string& type) const;
protected:
TIOPluginHandler();
private:
void do_initialise();
// a map of plugins
CSuffixmap m_suffixmap;
// list of supported compressd file suffixes
std::set<std::string> m_compress_sfx;
// print out info about the available plug-ins
void do_print_help(std::ostream& os) const;
std::string get_handler_type_string_and_help(std::ostream& os) const;
std::string do_get_handler_type_string() const;
bool do_validate_parameter_string(const std::string& s) const;
virtual void check_file_exists(const std::string& fname) const;
class EXPORT_HANDLER CDatapoolPlugin : public Interface
{
public:
CDatapoolPlugin();
private:
PData do_load(const std::string& fname) const;
bool do_save(const std::string& fname,
const typename Interface::Data& data) const;
const std::string do_get_descr() const;
const std::string do_get_preferred_suffix() const;
};
std::shared_ptr<Interface> m_pool_plugin;
};
#define EXPLICITE_INSTANCEIATE_IO_HANDLER(IOTYPE) \
template class TIOPlugin<IOTYPE>; \
template class THandlerSingleton<TIOPluginHandler<TIOPlugin<IOTYPE>>>; \
template class TIOPluginHandler<TIOPlugin<IOTYPE>>; \
template class TPluginHandler<TIOPlugin<IOTYPE>> \
template <typename Data>
struct IOHandler_of {
typedef THandlerSingleton<TIOPluginHandler<TIOPlugin<Data>>> type;
};
template <typename T>
T load_image(const std::string& MIA_PARAM_UNUSED(filename))
{
static_assert(sizeof(T) == 0, "The call to load_image must be resolved to a template specialization");
}
NS_MIA_END
#endif
type
TDelayedParameter
A parameter proxy object with a key to identify it.
Definition delayedparameter.hh:47
THandlerSingleton
the singleton that a plug-in handler really is
Definition handler.hh:159
TIOPluginHandler::load_to_pool
DataKey load_to_pool(const std::string &fname) const
TIOPluginHandler::const_iterator
TPluginHandler< I >::const_iterator const_iterator
an iterator over the available plug-ins
Definition iohandler.hh:58
TIOPluginHandler::get_supported_filetype_map
const CSuffixmap & get_supported_filetype_map() const
TIOPluginHandler::Interface
TPluginHandler< I >::Interface Interface
the IO interface provided by this handler
Definition iohandler.hh:55
TIOPluginHandler::save
bool save(const std::string &fname, const Data &data) const
TIOPluginHandler::get_supported_suffixes
const std::string get_supported_suffixes() const
@ returns a string containing the supported file type suffixes
TIOPluginHandler::CSuffixmap
std::multimap< std::string, std::string > CSuffixmap
The map that maps file name suffixes to IO plug-ins.
Definition iohandler.hh:61
TIOPluginHandler::TIOPluginHandler
TIOPluginHandler()
TIOPluginHandler::get_preferred_suffix
std::string get_preferred_suffix(const std::string &type) const
TIOPluginHandler::load
PData load(const std::string &fname) const
TIOPluginHandler::DataKey
TDelayedParameter< PData > DataKey
The type of the key used for the CDatapool access.
Definition iohandler.hh:64
TIOPluginHandler::get_supported_suffix_set
const std::set< std::string > get_supported_suffix_set() const
@ returns a saet containing the supported file type suffixes
TIOPluginHandler::Data
I::Data Data
Data type handled by this plug-in.
Definition iohandler.hh:49
TIOPluginHandler::PData
std::shared_ptr< Data > PData
Shared pointer to the data hadnled by this plug-in.
Definition iohandler.hh:52
TIOPluginHandler::preferred_plugin
const Interface & preferred_plugin(const std::string &fname) const
TIOPluginHandler::preferred_plugin_ptr
const Interface * preferred_plugin_ptr(const std::string &fname) const
TPluginHandler::TPluginHandler
TPluginHandler()
Initializes the plugin handler based on the build-in search path.
TPluginHandler::const_iterator
CPluginMap::const_iterator const_iterator
the iterator to walk over the available plug-ins
Definition handler.hh:68
TPluginHandler::Interface
I Interface
typedef for the plug-in interface provided by the class
Definition handler.hh:60
EXPORT_HANDLER
#define EXPORT_HANDLER
Definition core/cost.hh:32
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
delayedparameter.hh
handler.hh
load_image
T load_image(const std::string &filename)
Definition iohandler.hh:194
ioplugin.hh
IOHandler_of
Definition iohandler.hh:185
IOHandler_of::type
THandlerSingleton< TIOPluginHandler< TIOPlugin< Data > > > type
Definition iohandler.hh:186