My Project
iohandler.hh
Go to the documentation of this file.
1 /* -*- mia-c++ -*-
2  *
3  * This file is part of MIA - a toolbox for medical image analysis
4  * Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
5  *
6  * MIA is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with MIA; if not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #ifndef ph_IOhandler_hh
22 #define ph_IOhandler_hh
23 #include <set>
24 
25 #include <mia/core/handler.hh>
26 #include <mia/core/ioplugin.hh>
28 
30 
43 template <class I>
45 {
46 public:
47 
49  typedef typename I::Data Data;
50 
52  typedef typename std::shared_ptr<Data > PData;
53 
56 
59 
61  typedef std::multimap<std::string, std::string> CSuffixmap;
62 
65 
73  PData load(const std::string& fname) const;
74 
83  DataKey load_to_pool(const std::string& fname) const;
84 
93  bool save(const std::string& fname, const Data& data) const;
94 
100  const Interface *preferred_plugin_ptr(const std::string& fname) const;
101 
109  const Interface& preferred_plugin(const std::string& fname) const;
110 
113 
115  const std::string get_supported_suffixes() const;
116 
118  const std::set<std::string> get_supported_suffix_set() const;
119 
126  std::string get_preferred_suffix(const std::string& type) const;
127 
128 protected:
133 
134 private:
135 
136  void do_initialise();
137  // a map of plugins
138 
139  CSuffixmap m_suffixmap;
140 
141  // list of supported compressd file suffixes
142  std::set<std::string> m_compress_sfx;
143 
144 
145  // print out info about the available plug-ins
146  void do_print_help(std::ostream& os) const;
147 
148  std::string get_handler_type_string_and_help(std::ostream& os) const;
149  std::string do_get_handler_type_string() const;
150  bool do_validate_parameter_string(const std::string& s) const;
151 
152  virtual void check_file_exists(const std::string& fname) const;
153 
157  class EXPORT_HANDLER CDatapoolPlugin : public Interface
158  {
159  public:
160  CDatapoolPlugin();
161  private:
162  PData do_load(const std::string& fname) const;
163  bool do_save(const std::string& fname,
164  const typename Interface::Data& data) const;
165  const std::string do_get_descr() const;
166  const std::string do_get_preferred_suffix() const;
167 
168  };
169  std::shared_ptr<Interface> m_pool_plugin;
170 };
171 
176 #define EXPLICITE_INSTANCEIATE_IO_HANDLER(IOTYPE) \
177  template class TIOPlugin<IOTYPE>; \
178  template class THandlerSingleton<TIOPluginHandler<TIOPlugin<IOTYPE>>>; \
179  template class TIOPluginHandler<TIOPlugin<IOTYPE>>; \
180  template class TPluginHandler<TIOPlugin<IOTYPE>> \
181 
182 
183 
184 template <typename Data>
185 struct IOHandler_of {
187 };
188 
193 template <typename T>
194 T load_image(const std::string& MIA_PARAM_UNUSED(filename))
195 {
196  static_assert(sizeof(T) == 0, "The call to load_image must be resolved to a template specialization");
197 }
198 
200 #endif
A parameter proxy object with a key to identify it.
the singleton that a plug-in handler really is
Definition: handler.hh:159
Template for all plug-in handlers that are responsible for data IO.
Definition: iohandler.hh:45
const Interface * preferred_plugin_ptr(const std::string &fname) const
DataKey load_to_pool(const std::string &fname) const
TPluginHandler< I >::const_iterator const_iterator
an iterator over the available plug-ins
Definition: iohandler.hh:58
TPluginHandler< I >::Interface Interface
the IO interface provided by this handler
Definition: iohandler.hh:55
bool save(const std::string &fname, const Data &data) const
const std::set< std::string > get_supported_suffix_set() const
@ returns a saet containing the supported file type suffixes
const std::string get_supported_suffixes() const
@ returns a string containing the supported file type suffixes
std::multimap< std::string, std::string > CSuffixmap
The map that maps file name suffixes to IO plug-ins.
Definition: iohandler.hh:61
const Interface & preferred_plugin(const std::string &fname) const
const CSuffixmap & get_supported_filetype_map() const
std::string get_preferred_suffix(const std::string &type) const
PData load(const std::string &fname) const
TDelayedParameter< PData > DataKey
The type of the key used for the CDatapool access.
Definition: iohandler.hh:64
I::Data Data
Data type handled by this plug-in.
Definition: iohandler.hh:49
std::shared_ptr< Data > PData
Shared pointer to the data hadnled by this plug-in.
Definition: iohandler.hh:52
The basic template of all plugin handlers.
Definition: handler.hh:57
CPluginMap::const_iterator const_iterator
the iterator to walk over the available plug-ins
Definition: handler.hh:68
I Interface
typedef for the plug-in interface provided by the class
Definition: handler.hh:60
#define EXPORT_HANDLER
Definition: core/cost.hh:32
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36
T load_image(const std::string &filename)
Definition: iohandler.hh:194
THandlerSingleton< TIOPluginHandler< TIOPlugin< Data > > > type
Definition: iohandler.hh:186