| 1 | // ArgumentParser.hxx -- flightgear viewer argument parser |
| 2 | // |
| 3 | // Copyright (C) 2021 by Erik Hofman |
| 4 | // |
| 5 | // This program is free software; you can redistribute it and/or |
| 6 | // modify it under the terms of the GNU General Public License as |
| 7 | // published by the Free Software Foundation; either version 2 of the |
| 8 | // License, or (at your option) any later version. |
| 9 | // |
| 10 | // This program is distributed in the hope that it will be useful, but |
| 11 | // WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | // General Public License for more details. |
| 14 | // |
| 15 | // You should have received a copy of the GNU General Public License |
| 16 | // along with this program; if not, write to the Free Software |
| 17 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 | |
| 19 | #pragma once |
| 20 | |
| 21 | #include <vector> |
| 22 | #include <map> |
| 23 | |
| 24 | #include <osg/ArgumentParser> |
| 25 | |
| 26 | class ArgumentParser |
| 27 | { |
| 28 | public: |
| 29 | ArgumentParser(int argc, char **argv); |
| 30 | ~ArgumentParser() = default; |
| 31 | |
| 32 | bool read(const char *arg); |
| 33 | bool read(const char *arg, std::string& value); |
| 34 | bool read(const char *arg, std::string& name, std::string& value); |
| 35 | |
| 36 | int argc() { return files.size(); } |
| 37 | std::string& getApplicationName() { return appName; } |
| 38 | |
| 39 | void reportRemainingOptionsAsUnrecognized(); |
| 40 | void writeErrorMessages(std::ostream& output); |
| 41 | |
| 42 | osg::ArgumentParser& osg() { return arguments; } |
| 43 | |
| 44 | operator std::vector<std::string>&() { return files; } |
| 45 | |
| 46 | private: |
| 47 | int arg_num; |
| 48 | char **arg_values; |
| 49 | std::string appName; |
| 50 | |
| 51 | std::vector<std::string> errors; |
| 52 | std::map<std::string, std::string> args; |
| 53 | std::vector<std::string> files; |
| 54 | |
| 55 | osg::ArgumentParser arguments; |
| 56 | }; |
| 57 |