1c243e490SMarcel Moolenaar // Copyright (c) 2007 The NetBSD Foundation, Inc. 2c243e490SMarcel Moolenaar // All rights reserved. 3c243e490SMarcel Moolenaar // 4c243e490SMarcel Moolenaar // Redistribution and use in source and binary forms, with or without 5c243e490SMarcel Moolenaar // modification, are permitted provided that the following conditions 6c243e490SMarcel Moolenaar // are met: 7c243e490SMarcel Moolenaar // 1. Redistributions of source code must retain the above copyright 8c243e490SMarcel Moolenaar // notice, this list of conditions and the following disclaimer. 9c243e490SMarcel Moolenaar // 2. Redistributions in binary form must reproduce the above copyright 10c243e490SMarcel Moolenaar // notice, this list of conditions and the following disclaimer in the 11c243e490SMarcel Moolenaar // documentation and/or other materials provided with the distribution. 12c243e490SMarcel Moolenaar // 13c243e490SMarcel Moolenaar // THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 14c243e490SMarcel Moolenaar // CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 15c243e490SMarcel Moolenaar // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 16c243e490SMarcel Moolenaar // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17c243e490SMarcel Moolenaar // IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 18c243e490SMarcel Moolenaar // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19c243e490SMarcel Moolenaar // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 20c243e490SMarcel Moolenaar // GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21c243e490SMarcel Moolenaar // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 22c243e490SMarcel Moolenaar // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23c243e490SMarcel Moolenaar // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 24c243e490SMarcel Moolenaar // IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25c243e490SMarcel Moolenaar 26*0677dfd1SJulio Merino #if !defined(ATF_CXX_DETAIL_APPLICATION_HPP) 27*0677dfd1SJulio Merino #define ATF_CXX_DETAIL_APPLICATION_HPP 28c243e490SMarcel Moolenaar 29c243e490SMarcel Moolenaar #include <ostream> 30c243e490SMarcel Moolenaar #include <set> 31c243e490SMarcel Moolenaar #include <stdexcept> 32c243e490SMarcel Moolenaar #include <string> 33c243e490SMarcel Moolenaar 34c243e490SMarcel Moolenaar namespace atf { 35c243e490SMarcel Moolenaar namespace application { 36c243e490SMarcel Moolenaar 37c243e490SMarcel Moolenaar // ------------------------------------------------------------------------ 38c243e490SMarcel Moolenaar // The "usage_error" class. 39c243e490SMarcel Moolenaar // ------------------------------------------------------------------------ 40c243e490SMarcel Moolenaar 41c243e490SMarcel Moolenaar class usage_error : public std::runtime_error { 42c243e490SMarcel Moolenaar char m_text[4096]; 43c243e490SMarcel Moolenaar 44c243e490SMarcel Moolenaar public: 45c243e490SMarcel Moolenaar usage_error(const char*, ...) throw(); 46c243e490SMarcel Moolenaar ~usage_error(void) throw(); 47c243e490SMarcel Moolenaar 48c243e490SMarcel Moolenaar const char* what(void) const throw(); 49c243e490SMarcel Moolenaar }; 50c243e490SMarcel Moolenaar 51c243e490SMarcel Moolenaar // ------------------------------------------------------------------------ 52c243e490SMarcel Moolenaar // The "option" class. 53c243e490SMarcel Moolenaar // ------------------------------------------------------------------------ 54c243e490SMarcel Moolenaar 55c243e490SMarcel Moolenaar class option { 56c243e490SMarcel Moolenaar char m_character; 57c243e490SMarcel Moolenaar std::string m_argument; 58c243e490SMarcel Moolenaar std::string m_description; 59c243e490SMarcel Moolenaar 60c243e490SMarcel Moolenaar friend class app; 61c243e490SMarcel Moolenaar 62c243e490SMarcel Moolenaar public: 63c243e490SMarcel Moolenaar option(char, const std::string&, const std::string&); 64c243e490SMarcel Moolenaar 65c243e490SMarcel Moolenaar bool operator<(const option&) const; 66c243e490SMarcel Moolenaar }; 67c243e490SMarcel Moolenaar 68c243e490SMarcel Moolenaar // ------------------------------------------------------------------------ 69c243e490SMarcel Moolenaar // The "app" class. 70c243e490SMarcel Moolenaar // ------------------------------------------------------------------------ 71c243e490SMarcel Moolenaar 72c243e490SMarcel Moolenaar class app { 73c243e490SMarcel Moolenaar void process_options(void); 74c243e490SMarcel Moolenaar void usage(std::ostream&); 75c243e490SMarcel Moolenaar 76c243e490SMarcel Moolenaar bool inited(void); 77c243e490SMarcel Moolenaar 78c243e490SMarcel Moolenaar protected: 79c243e490SMarcel Moolenaar typedef std::set< option > options_set; 80c243e490SMarcel Moolenaar 81c243e490SMarcel Moolenaar int m_argc; 82c243e490SMarcel Moolenaar char* const* m_argv; 83c243e490SMarcel Moolenaar 84c243e490SMarcel Moolenaar const char* m_argv0; 85c243e490SMarcel Moolenaar const char* m_prog_name; 86c243e490SMarcel Moolenaar std::string m_description; 871a61beb0SJulio Merino std::string m_manpage; 88c243e490SMarcel Moolenaar 89c243e490SMarcel Moolenaar options_set options(void); 90c243e490SMarcel Moolenaar 91c243e490SMarcel Moolenaar // To be redefined. 92c243e490SMarcel Moolenaar virtual std::string specific_args(void) const; 93c243e490SMarcel Moolenaar virtual options_set specific_options(void) const; 94c243e490SMarcel Moolenaar virtual void process_option(int, const char*); 95c243e490SMarcel Moolenaar virtual int main(void) = 0; 96c243e490SMarcel Moolenaar 97c243e490SMarcel Moolenaar public: 981a61beb0SJulio Merino app(const std::string&, const std::string&); 99c243e490SMarcel Moolenaar virtual ~app(void); 100c243e490SMarcel Moolenaar 101c243e490SMarcel Moolenaar int run(int, char* const*); 102c243e490SMarcel Moolenaar }; 103c243e490SMarcel Moolenaar 104c243e490SMarcel Moolenaar } // namespace application 105c243e490SMarcel Moolenaar } // namespace atf 106c243e490SMarcel Moolenaar 107*0677dfd1SJulio Merino #endif // !defined(ATF_CXX_DETAIL_APPLICATION_HPP) 108