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-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 mia_core_cmdoption_hh
22 #define mia_core_cmdoption_hh
23 
24 #include <string>
25 #include <memory>
26 #include <iostream>
27 #include <mia/core/defines.hh>
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 
54  static const bool not_required;
55 
57  static const bool required;
58 
66  CCmdOption(char short_opt, const char *long_opt, const char *long_help,
67  const char *short_help, bool required);
68 
70  virtual ~CCmdOption();
71 
76  void add_option(CShortoptionMap& sm, CLongoptionMap& lm);
77 
81  size_t get_needed_args() const;
82 
86  void write_value(std::ostream& os) const;
87 
91  void set_value(const char *str_value);
92 
94  const char *get_long_option() const;
95 
97  char get_short_option() const;
98 
102  void print_short_help(std::ostream& os) const;
103 
107  void get_opt_help(std::ostream& os)const;
108 
112  void get_long_help(std::ostream& os)const;
113 
115  const std::string get_value_as_string() const;
116 
118  bool is_required() const;
119 
121  const char *long_help() const;
122 
131  std::string get_long_help_xml(xmlpp::Element& parent, HandlerHelpMap& handler_map) const;
132 
136  void post_set();
137 protected:
138 
140  void clear_required();
141 
146  virtual void do_get_long_help(std::ostream& os) const;
147 private:
148  const char *get_short_help() const;
149 
150  virtual void do_add_option(CShortoptionMap& sm, CLongoptionMap& lm);
151  virtual void do_print_short_help(std::ostream& os) const;
152  virtual void do_get_opt_help(std::ostream& os) const;
153 
154  virtual bool do_set_value(const char *str_value) = 0;
155  virtual size_t do_get_needed_args() const;
156  virtual void do_write_value(std::ostream& os) const = 0;
157 
158  virtual const std::string do_get_value_as_string() const;
159  virtual void do_post_set();
160 
161  virtual void do_get_long_help_xml(std::ostream& os, xmlpp::Element& parent, HandlerHelpMap& handler_map) const;
162 
163  char m_short_opt;
164  const char *m_long_opt;
165  const char *m_long_help;
166  const char *m_short_help;
167  bool m_flags;
168 };
169 
171 typedef std::shared_ptr<CCmdOption > PCmdOption;
172 
174 
175 #endif