1240116Smarcel// Copyright (c) 2007 The NetBSD Foundation, Inc. 2240116Smarcel// All rights reserved. 3240116Smarcel// 4240116Smarcel// Redistribution and use in source and binary forms, with or without 5240116Smarcel// modification, are permitted provided that the following conditions 6240116Smarcel// are met: 7240116Smarcel// 1. Redistributions of source code must retain the above copyright 8240116Smarcel// notice, this list of conditions and the following disclaimer. 9240116Smarcel// 2. Redistributions in binary form must reproduce the above copyright 10240116Smarcel// notice, this list of conditions and the following disclaimer in the 11240116Smarcel// documentation and/or other materials provided with the distribution. 12240116Smarcel// 13240116Smarcel// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 14240116Smarcel// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 15240116Smarcel// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 16240116Smarcel// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17240116Smarcel// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 18240116Smarcel// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19240116Smarcel// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 20240116Smarcel// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21240116Smarcel// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 22240116Smarcel// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23240116Smarcel// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 24240116Smarcel// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25240116Smarcel 26273929Sjmmv#if !defined(ATF_CXX_DETAIL_APPLICATION_HPP) 27273929Sjmmv#define ATF_CXX_DETAIL_APPLICATION_HPP 28240116Smarcel 29240116Smarcel#include <ostream> 30240116Smarcel#include <set> 31240116Smarcel#include <stdexcept> 32240116Smarcel#include <string> 33240116Smarcel 34240116Smarcelnamespace atf { 35240116Smarcelnamespace application { 36240116Smarcel 37240116Smarcel// ------------------------------------------------------------------------ 38240116Smarcel// The "usage_error" class. 39240116Smarcel// ------------------------------------------------------------------------ 40240116Smarcel 41240116Smarcelclass usage_error : public std::runtime_error { 42240116Smarcel char m_text[4096]; 43240116Smarcel 44240116Smarcelpublic: 45240116Smarcel usage_error(const char*, ...) throw(); 46240116Smarcel ~usage_error(void) throw(); 47240116Smarcel 48240116Smarcel const char* what(void) const throw(); 49240116Smarcel}; 50240116Smarcel 51240116Smarcel// ------------------------------------------------------------------------ 52240116Smarcel// The "option" class. 53240116Smarcel// ------------------------------------------------------------------------ 54240116Smarcel 55240116Smarcelclass option { 56240116Smarcel char m_character; 57240116Smarcel std::string m_argument; 58240116Smarcel std::string m_description; 59240116Smarcel 60240116Smarcel friend class app; 61240116Smarcel 62240116Smarcelpublic: 63240116Smarcel option(char, const std::string&, const std::string&); 64240116Smarcel 65240116Smarcel bool operator<(const option&) const; 66240116Smarcel}; 67240116Smarcel 68240116Smarcel// ------------------------------------------------------------------------ 69240116Smarcel// The "app" class. 70240116Smarcel// ------------------------------------------------------------------------ 71240116Smarcel 72240116Smarcelclass app { 73240116Smarcel void process_options(void); 74240116Smarcel void usage(std::ostream&); 75240116Smarcel 76240116Smarcel bool inited(void); 77240116Smarcel 78240116Smarcelprotected: 79240116Smarcel typedef std::set< option > options_set; 80240116Smarcel 81240116Smarcel int m_argc; 82240116Smarcel char* const* m_argv; 83240116Smarcel 84240116Smarcel const char* m_argv0; 85240116Smarcel const char* m_prog_name; 86240116Smarcel std::string m_description; 87261897Sjmmv std::string m_manpage; 88240116Smarcel 89240116Smarcel options_set options(void); 90240116Smarcel 91240116Smarcel // To be redefined. 92240116Smarcel virtual std::string specific_args(void) const; 93240116Smarcel virtual options_set specific_options(void) const; 94240116Smarcel virtual void process_option(int, const char*); 95240116Smarcel virtual int main(void) = 0; 96240116Smarcel 97240116Smarcelpublic: 98261897Sjmmv app(const std::string&, const std::string&); 99240116Smarcel virtual ~app(void); 100240116Smarcel 101240116Smarcel int run(int, char* const*); 102240116Smarcel}; 103240116Smarcel 104240116Smarcel} // namespace application 105240116Smarcel} // namespace atf 106240116Smarcel 107273929Sjmmv#endif // !defined(ATF_CXX_DETAIL_APPLICATION_HPP) 108