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-2014 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 #include <libxml++/libxml++.h>
30 
32 
33 class CCmdOption;
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, bool required)__attribute__((deprecated));
63 
64  CCmdOption(char short_opt, const char *long_opt, const char *long_help,
65  const char *short_help, CCmdOptionFlags flags);
66 
67 
69  virtual ~CCmdOption();
70 
75  void add_option(CShortoptionMap& sm, CLongoptionMap& lm);
76 
80  size_t get_needed_args() const;
81 
85  void write_value(std::ostream& os) const;
86 
90  void set_value(const char *str_value);
91 
93  const char *get_long_option() const;
94 
96  char get_short_option() const;
97 
101  void print_short_help(std::ostream& os) const;
102 
106  void get_opt_help(std::ostream& os)const;
107 
111  void get_long_help(std::ostream& os)const;
112 
114  const std::string get_value_as_string() const;
115 
117  bool is_required() const;
118 
120  const char *long_help() const;
121 
130  std::string get_long_help_xml(xmlpp::Element& parent, HandlerHelpMap& handler_map) const;
131 
135  void post_set();
136 
143  void add_option_xml(xmlpp::Element& parent, HandlerHelpMap& handler_map) const;
144 protected:
145 
147  void clear_required();
148 
153  virtual void do_get_long_help(std::ostream& os) const;
154 
155  bool has_flag(CCmdOptionFlags test_flags) const;
156 private:
157  std::string get_flag_string() const;
158  const char *get_short_help() const;
159 
160  virtual void do_add_option(CShortoptionMap& sm, CLongoptionMap& lm);
161  virtual void do_print_short_help(std::ostream& os) const;
162  virtual void do_get_opt_help(std::ostream& os) const;
163 
164  virtual bool do_set_value(const char *str_value) = 0;
165  virtual size_t do_get_needed_args() const;
166  virtual void do_write_value(std::ostream& os) const = 0;
167 
168  virtual const std::string do_get_value_as_string() const;
169  virtual void do_post_set();
170 
171  virtual void do_get_long_help_xml(std::ostream& os, xmlpp::Element& parent, HandlerHelpMap& handler_map) const;
172 
173  char m_short_opt;
174  const char *m_long_opt;
175  const char *m_long_help;
176  const char *m_short_help;
177  CCmdOptionFlags m_flags;
178 };
179 
181 typedef std::shared_ptr<CCmdOption > PCmdOption;
182 
184 
185 #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:43
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:36
std::map< std::string, CCmdOption * > CLongoptionMap
Class to provide a maping from long option names to options.
Definition: cmdoption.hh:39
CCmdOptionFlags
bool has_flag(CCmdOptionFlags flags, CCmdOptionFlags test)
std::shared_ptr< CCmdOption > PCmdOption
a shared pointer definition of the Option
Definition: cmdoption.hh:181
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
Definition: defines.hh:110
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:46