cmdoption.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 mia_core_cmdoption_hh
22 #define mia_core_cmdoption_hh
23 
24 #include <string>
25 #include <memory>
26 #include <iostream>
28 #include <mia/core/handlerbase.hh>
29 
31 
32 class CCmdOption;
33 class CXMLElement;
34 
36 typedef std::map<char, CCmdOption *> CShortoptionMap;
37 
39 typedef std::map<std::string, CCmdOption *> CLongoptionMap;
40 
41 
51 public:
52 
53 
61  CCmdOption(char short_opt, const char *long_opt, const char *long_help,
62  const char *short_help, CCmdOptionFlags flags);
63 
64 
66  virtual ~CCmdOption();
67 
72  void add_option(CShortoptionMap& sm, CLongoptionMap& lm);
73 
77  size_t get_needed_args() const;
78 
82  void write_value(std::ostream& os) const;
83 
87  void set_value(const char *str_value);
88 
90  const char *get_long_option() const;
91 
93  char get_short_option() const;
94 
98  void print_short_help(std::ostream& os) const;
99 
103  void get_opt_help(std::ostream& os)const;
104 
108  void get_long_help(std::ostream& os)const;
109 
111  const std::string get_value_as_string() const;
112 
114  bool is_required() const;
115 
117  const char *long_help() const;
118 
127  std::string get_long_help_xml(CXMLElement& parent, HandlerHelpMap& handler_map) const;
128 
132  void post_set();
133 
140  void add_option_xml(CXMLElement& parent, HandlerHelpMap& handler_map) const;
141 protected:
142 
144  void clear_required();
145 
150  virtual void do_get_long_help(std::ostream& os) const;
151 
152  bool has_flag(CCmdOptionFlags test_flags) const;
153 
154  void xmlhelp_set_attribute(CXMLElement& node, const char *name, const std::string& value) const;
155 private:
156  std::string get_flag_string() const;
157  const char *get_short_help() const;
158 
159  virtual void do_add_option(CShortoptionMap& sm, CLongoptionMap& lm);
160  virtual void do_print_short_help(std::ostream& os) const;
161  virtual void do_get_opt_help(std::ostream& os) const;
162 
163  virtual bool do_set_value(const char *str_value) = 0;
164  virtual size_t do_get_needed_args() const;
165  virtual void do_write_value(std::ostream& os) const = 0;
166 
167  virtual const std::string do_get_value_as_string() const;
168  virtual void do_post_set();
169 
170  virtual void do_get_long_help_xml(std::ostream& os, CXMLElement& parent, HandlerHelpMap& handler_map) const;
171 
172  char m_short_opt;
173  const char *m_long_opt;
174  const char *m_long_help;
175  const char *m_short_help;
176  CCmdOptionFlags m_flags;
177 };
178 
180 typedef std::shared_ptr<CCmdOption > PCmdOption;
181 
183 
184 #endif
The base class for all command line options.
Definition: cmdoption.hh:50
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
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:35
std::map< std::string, CCmdOption * > CLongoptionMap
Class to provide a maping from long option names to options.
Definition: cmdoption.hh:39
CCmdOptionFlags
This class implements a facade for the xml Element.
Definition: xmlinterface.hh:49
std::shared_ptr< CCmdOption > PCmdOption
a shared pointer definition of the Option
Definition: cmdoption.hh:180
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
Definition: defines.hh:101
std::map< char, CCmdOption * > CShortoptionMap
Class to provide a maping from short option names to options.
Definition: cmdoption.hh:33
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36