My Project
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>
29
31
32class CCmdOption;
33class CXMLElement;
34
36typedef std::map<char, CCmdOption *> CShortoptionMap;
37
39typedef std::map<std::string, CCmdOption *> CLongoptionMap;
40
41
51{
52public:
53
54
62 CCmdOption(char short_opt, const char *long_opt, const char *long_help,
63 const char *short_help, CCmdOptionFlags flags);
64
65
67 virtual ~CCmdOption();
68
74
78 size_t get_needed_args() const;
79
83 void write_value(std::ostream& os) const;
84
88 void set_value(const char *str_value);
89
91 const char *get_long_option() const;
92
94 char get_short_option() const;
95
99 void print_short_help(std::ostream& os) const;
100
104 void get_opt_help(std::ostream& os)const;
105
109 void get_long_help(std::ostream& os)const;
110
112 const std::string get_value_as_string() const;
113
115 bool is_required() const;
116
118 const char *long_help() const;
119
128 std::string get_long_help_xml(CXMLElement& parent, HandlerHelpMap& handler_map) const;
129
133 void post_set();
134
141 void add_option_xml(CXMLElement& parent, HandlerHelpMap& handler_map) const;
142protected:
143
146
151 virtual void do_get_long_help(std::ostream& os) const;
152
153 bool has_flag(CCmdOptionFlags test_flags) const;
154
155 void xmlhelp_set_attribute(CXMLElement& node, const char *name, const std::string& value) const;
156private:
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, CXMLElement& 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
181typedef std::shared_ptr<CCmdOption > PCmdOption;
182
184
185#endif
The base class for all command line options.
Definition: cmdoption.hh:51
void get_long_help(std::ostream &os) const
std::string get_long_help_xml(CXMLElement &parent, HandlerHelpMap &handler_map) const
const std::string get_value_as_string() const
void get_opt_help(std::ostream &os) const
void clear_required()
clear the "required" flag
virtual ~CCmdOption()
ensure virtual destruction
void add_option(CShortoptionMap &sm, CLongoptionMap &lm)
const char * get_long_option() const
void set_value(const char *str_value)
void xmlhelp_set_attribute(CXMLElement &node, const char *name, const std::string &value) const
bool is_required() const
virtual void do_get_long_help(std::ostream &os) const
CCmdOption(char short_opt, const char *long_opt, const char *long_help, const char *short_help, CCmdOptionFlags flags)
void add_option_xml(CXMLElement &parent, HandlerHelpMap &handler_map) const
const char * long_help() const
char get_short_option() const
void write_value(std::ostream &os) const
size_t get_needed_args() const
void print_short_help(std::ostream &os) const
bool has_flag(CCmdOptionFlags test_flags) const
void post_set()
This class implements a facade for the xml Element.
Definition: xmlinterface.hh:50
std::map< char, CCmdOption * > CShortoptionMap
Class to provide a maping from short option names to options.
Definition: cmdoption.hh:36
std::map< std::string, CCmdOption * > CLongoptionMap
Class to provide a maping from long option names to options.
Definition: cmdoption.hh:39
std::shared_ptr< CCmdOption > PCmdOption
a shared pointer definition of the Option
Definition: cmdoption.hh:181
CCmdOptionFlags
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
Definition: defines.hh:101
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36
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:45