handler.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_handler_hh
22 #define ph_handler_hh
23 
24 #include <string>
25 #include <map>
26 #include <set>
27 #include <vector>
28 #include <ostream>
29 #include <boost/any.hpp>
30 
31 #include <mia/core/utils.hh>
32 #include <mia/core/filetools.hh>
33 
34 #include <mia/core/defines.hh>
35 #include <mia/core/module.hh>
36 #include <mia/core/plugin_base.hh>
37 #include <mia/core/handlerbase.hh>
38 
40 
42 
43 
53 template <typename I>
55 public:
57  typedef I Interface;
58 
60  typedef std::map<std::string, Interface*> CPluginMap;
61 
63  typedef typename CPluginMap::const_iterator const_iterator;
64 
65 
69  virtual ~TPluginHandler();
70 
72  size_t size() const;
73 
77  const std::string get_plugin_names() const;
78 
80  const std::set<std::string> get_set() const;
81 
82 
84  const_iterator begin()const;
85 
87  const_iterator end()const;
88 
89 protected:
91 
92 
97  TPluginHandler();
99 
105  typename TPluginHandler<I>::Interface *plugin(const char *plugin) const;
106 
107 
112  void add_plugin(Interface *plugin);
113 
114  void initialise(CPathNameArray searchpath);
115 
116 private:
117  virtual void do_initialise();
118  void global_searchpath(CPathNameArray& searchpath);
119 
120  void do_add_dependend_handlers(HandlerHelpMap& handler_map) const;
121 
122  std::vector<PPluginModule> m_modules;
123  CPluginMap m_plugins;
124 
125  virtual void do_print_short_help(std::ostream& os) const;
126  virtual void do_print_help(std::ostream& os) const;
127  virtual void do_get_xml_help(xmlpp::Element *root) const;
128 
129  static const char * const m_help;
130 
131 };
132 
133 
142 template <typename T>
144 public:
145 
150  static void set_search_path(const CPathNameArray& searchpath);
151 
153  typedef T Instance;
154 
156  typedef typename T::const_iterator const_iterator;
157 
159  typedef typename T::CPluginMap::value_type value_type;
160 
164  static const T& instance();
165 
170  static const T* pointer();
171 protected:
172 
176 
177 private:
178  // the constructor is private because you must not derive the singleton
179  // derive the handler if you need specific funcionality, and then
180  // template the singleton with the derived handler.
182 
183  static const T& do_instance(bool require_initialization);
184 
185  static CPathNameArray m_searchpath;
186  static bool m_is_created;
187  static CMutex m_initialization_mutex;
188  static bool m_is_initialized;
189 
190 };
191 
192 
194 
195 #endif