cmdoption.hh
Go to the documentation of this file.
/* -*- mia-c++ -*-
*
* This file is part of MIA - a toolbox for medical image analysis
* Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
*
* MIA is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MIA; if not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef mia_core_cmdoption_hh
#define mia_core_cmdoption_hh
#include <string>
#include <memory>
#include <iostream>
#include <mia/core/cmdoptionflags.hh>
#include <mia/core/handlerbase.hh>
NS_MIA_BEGIN
class CCmdOption;
class CXMLElement;
typedef std::map<char, CCmdOption *> CShortoptionMap;
typedef std::map<std::string, CCmdOption *> CLongoptionMap;
class EXPORT_CORE CCmdOption
{
public:
CCmdOption(char short_opt, const char *long_opt, const char *long_help,
const char *short_help, CCmdOptionFlags flags);
virtual ~CCmdOption();
void add_option(CShortoptionMap& sm, CLongoptionMap& lm);
size_t get_needed_args() const;
void write_value(std::ostream& os) const;
void set_value(const char *str_value);
const char *get_long_option() const;
char get_short_option() const;
void print_short_help(std::ostream& os) const;
void get_opt_help(std::ostream& os)const;
void get_long_help(std::ostream& os)const;
const std::string get_value_as_string() const;
bool is_required() const;
const char *long_help() const;
std::string get_long_help_xml(CXMLElement& parent, HandlerHelpMap& handler_map) const;
void post_set();
void add_option_xml(CXMLElement& parent, HandlerHelpMap& handler_map) const;
protected:
void clear_required();
virtual void do_get_long_help(std::ostream& os) const;
bool has_flag(CCmdOptionFlags test_flags) const;
void xmlhelp_set_attribute(CXMLElement& node, const char *name, const std::string& value) const;
private:
std::string get_flag_string() const;
const char *get_short_help() const;
virtual void do_add_option(CShortoptionMap& sm, CLongoptionMap& lm);
virtual void do_print_short_help(std::ostream& os) const;
virtual void do_get_opt_help(std::ostream& os) const;
virtual bool do_set_value(const char *str_value) = 0;
virtual size_t do_get_needed_args() const;
virtual void do_write_value(std::ostream& os) const = 0;
virtual const std::string do_get_value_as_string() const;
virtual void do_post_set();
virtual void do_get_long_help_xml(std::ostream& os, CXMLElement& parent, HandlerHelpMap& handler_map) const;
char m_short_opt;
const char *m_long_opt;
const char *m_long_help;
const char *m_short_help;
CCmdOptionFlags m_flags;
};
typedef std::shared_ptr<CCmdOption > PCmdOption;
NS_MIA_END
#endif
CCmdOption
The base class for all command line options.
Definition cmdoption.hh:51
CCmdOption::get_long_help
void get_long_help(std::ostream &os) const
CCmdOption::get_long_help_xml
std::string get_long_help_xml(CXMLElement &parent, HandlerHelpMap &handler_map) const
CCmdOption::get_value_as_string
const std::string get_value_as_string() const
CCmdOption::get_opt_help
void get_opt_help(std::ostream &os) const
CCmdOption::clear_required
void clear_required()
clear the "required" flag
CCmdOption::~CCmdOption
virtual ~CCmdOption()
ensure virtual destruction
CCmdOption::add_option
void add_option(CShortoptionMap &sm, CLongoptionMap &lm)
CCmdOption::get_long_option
const char * get_long_option() const
CCmdOption::set_value
void set_value(const char *str_value)
CCmdOption::xmlhelp_set_attribute
void xmlhelp_set_attribute(CXMLElement &node, const char *name, const std::string &value) const
CCmdOption::is_required
bool is_required() const
CCmdOption::do_get_long_help
virtual void do_get_long_help(std::ostream &os) const
CCmdOption::CCmdOption
CCmdOption(char short_opt, const char *long_opt, const char *long_help, const char *short_help, CCmdOptionFlags flags)
CCmdOption::add_option_xml
void add_option_xml(CXMLElement &parent, HandlerHelpMap &handler_map) const
CCmdOption::long_help
const char * long_help() const
CCmdOption::get_short_option
char get_short_option() const
CCmdOption::write_value
void write_value(std::ostream &os) const
CCmdOption::get_needed_args
size_t get_needed_args() const
CCmdOption::print_short_help
void print_short_help(std::ostream &os) const
CCmdOption::has_flag
bool has_flag(CCmdOptionFlags test_flags) const
CCmdOption::post_set
void post_set()
CXMLElement
This class implements a facade for the xml Element.
Definition xmlinterface.hh:50
CShortoptionMap
std::map< char, CCmdOption * > CShortoptionMap
Class to provide a maping from short option names to options.
Definition cmdoption.hh:36
CLongoptionMap
std::map< std::string, CCmdOption * > CLongoptionMap
Class to provide a maping from long option names to options.
Definition cmdoption.hh:39
PCmdOption
std::shared_ptr< CCmdOption > PCmdOption
a shared pointer definition of the Option
Definition cmdoption.hh:181
cmdoptionflags.hh
CCmdOptionFlags
CCmdOptionFlags
Definition cmdoptionflags.hh:28
NS_MIA_BEGIN
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition defines.hh:33
EXPORT_CORE
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
Definition defines.hh:101
NS_MIA_END
#define NS_MIA_END
conveniance define to end the mia namespace
Definition defines.hh:36
HandlerHelpMap
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
handlerbase.hh