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-2013 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 public:
46 
48  typedef typename I::Data Data;
49 
51  typedef typename std::shared_ptr<Data > PData;
52 
55 
58 
60  typedef std::multimap<std::string, std::string> CSuffixmap;
61 
64 
72  PData load(const std::string& fname) const;
73 
82  DataKey load_to_pool(const std::string& fname) const;
83 
92  bool save(const std::string& fname, const Data& data) const;
93 
99  const Interface *preferred_plugin_ptr(const std::string& fname) const;
100 
108  const Interface& preferred_plugin(const std::string& fname) const;
109 
111  const CSuffixmap& get_supported_filetype_map() const;
112 
114  const std::string get_supported_suffixes() const;
115 
117  const std::set<std::string> get_supported_suffix_set() const;
118 
125  std::string get_preferred_suffix(const std::string& type) const;
126 
127 protected:
131  TIOPluginHandler();
132 
133 private:
134 
135  void do_initialise();
136  // a map of plugins
137 
138  CSuffixmap m_suffixmap;
139 
140  // list of supported compressd file suffixes
141  std::set<std::string> m_compress_sfx;
142 
143 
144  // print out info about the available plug-ins
145  void do_print_help(std::ostream& os) const;
146 
147  std::string get_handler_type_string_and_help(std::ostream& os) const;
148  std::string do_get_handler_type_string() const;
149 
153  class EXPORT_HANDLER CDatapoolPlugin : public Interface {
154  public:
155  CDatapoolPlugin();
156  private:
157  PData do_load(const std::string& fname) const;
158  bool do_save(const std::string& fname,
159  const typename Interface::Data& data) const;
160  const std::string do_get_descr() const;
161  std::string do_get_preferred_suffix() const;
162 
163  };
164  CDatapoolPlugin *m_pool_plugin;
165 };
166 
171 #define EXPLICITE_INSTANCEIATE_IO_HANDLER(IOTYPE) \
172  template class TIOPlugin<IOTYPE>; \
173  template class THandlerSingleton<TIOPluginHandler<TIOPlugin<IOTYPE>>>; \
174  template class TIOPluginHandler<TIOPlugin<IOTYPE>>; \
175  template class TPluginHandler<TIOPlugin<IOTYPE>> \
176 
177 
182 template <typename T>
183 T load_image(const std::string& MIA_PARAM_UNUSED(filename))
184 {
185  static_assert(sizeof(T) == 0, "The call to load_image must be resolved to a template specialization");
186 
187 }
188 
190 #endif