Path: blob/main/contrib/atf/atf-c++/detail/application.hpp
39562 views
// Copyright (c) 2007 The NetBSD Foundation, Inc.1// All rights reserved.2//3// Redistribution and use in source and binary forms, with or without4// modification, are permitted provided that the following conditions5// are met:6// 1. Redistributions of source code must retain the above copyright7// notice, this list of conditions and the following disclaimer.8// 2. Redistributions in binary form must reproduce the above copyright9// notice, this list of conditions and the following disclaimer in the10// documentation and/or other materials provided with the distribution.11//12// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND13// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,14// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF15// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.16// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY17// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE19// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS20// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER21// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR22// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN23// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.2425#if !defined(ATF_CXX_DETAIL_APPLICATION_HPP)26#define ATF_CXX_DETAIL_APPLICATION_HPP2728#include <ostream>29#include <set>30#include <stdexcept>31#include <string>3233namespace atf {34namespace application {3536// ------------------------------------------------------------------------37// The "usage_error" class.38// ------------------------------------------------------------------------3940class usage_error : public std::runtime_error {41char m_text[4096];4243public:44usage_error(const char*, ...) throw();45~usage_error(void) throw();4647const char* what(void) const throw();48};4950// ------------------------------------------------------------------------51// The "option" class.52// ------------------------------------------------------------------------5354class option {55char m_character;56std::string m_argument;57std::string m_description;5859friend class app;6061public:62option(char, const std::string&, const std::string&);6364bool operator<(const option&) const;65};6667// ------------------------------------------------------------------------68// The "app" class.69// ------------------------------------------------------------------------7071class app {72void process_options(void);73void usage(std::ostream&);7475bool inited(void);7677protected:78typedef std::set< option > options_set;7980int m_argc;81char* const* m_argv;8283const char* m_argv0;84const char* m_prog_name;85std::string m_description;86std::string m_manpage;8788options_set options(void);8990// To be redefined.91virtual std::string specific_args(void) const;92virtual options_set specific_options(void) const;93virtual void process_option(int, const char*);94virtual int main(void) = 0;9596public:97app(const std::string&, const std::string&);98virtual ~app(void);99100int run(int, char* const*);101};102103} // namespace application104} // namespace atf105106#endif // !defined(ATF_CXX_DETAIL_APPLICATION_HPP)107108109