FreeNOS
ArgumentParser.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Niek Linnenbank
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef __LIBAPP_ARGUMENTPARSER_H
19 #define __LIBAPP_ARGUMENTPARSER_H
20 
21 #include <Types.h>
22 #include <Macros.h>
23 #include <String.h>
24 #include <HashTable.h>
25 #include <Vector.h>
26 #include "Argument.h"
27 #include "ArgumentContainer.h"
28 
41 {
42  public:
43 
47  enum Result
48  {
53  };
54 
55  public:
56 
61 
65  virtual ~ArgumentParser();
66 
72  String getUsage() const;
73 
79  const String & name() const;
80 
86  void setName(const char *name);
87 
93  void setDescription(const String & desc);
94 
104  Result registerFlag(char arg,
105  const char *name,
106  const char *description);
107 
117  Result registerPositional(const char *name,
118  const char *description,
119  Size count = 1);
120 
133  Result parse(int argc,
134  char **argv,
135  ArgumentContainer & output);
136 
137  private:
138 
141 
144 
147 
150 
153 };
154 
160 #endif /* __LIBAPP_ARGUMENTPARSER_H */
HashTable< String, Argument * >
ArgumentParser::Result
Result
Result codes.
Definition: ArgumentParser.h:47
Macros.h
Vector.h
Types.h
ArgumentParser::m_name
String m_name
Program name.
Definition: ArgumentParser.h:149
String
Abstraction of strings.
Definition: String.h:41
HashTable.h
ArgumentParser
Generic command-line argument parser.
Definition: ArgumentParser.h:40
ArgumentParser::m_description
String m_description
Program description.
Definition: ArgumentParser.h:152
ArgumentParser::NotFound
@ NotFound
Definition: ArgumentParser.h:51
ArgumentParser::setDescription
void setDescription(const String &desc)
Set program description.
Definition: ArgumentParser.cpp:95
ArgumentParser::m_flags
HashTable< String, Argument * > m_flags
Contains all registered flag arguments by name.
Definition: ArgumentParser.h:140
ArgumentParser::ArgumentParser
ArgumentParser()
Constructor.
Definition: ArgumentParser.cpp:21
ArgumentContainer.h
ArgumentContainer
Generic command-line argument parser.
Definition: ArgumentContainer.h:40
ArgumentParser::InvalidArgument
@ InvalidArgument
Definition: ArgumentParser.h:50
ArgumentParser::~ArgumentParser
virtual ~ArgumentParser()
Destructor.
Definition: ArgumentParser.cpp:27
ArgumentParser::m_positionals
Vector< Argument * > m_positionals
Contains all registered positional arguments.
Definition: ArgumentParser.h:146
ArgumentParser::AlreadyExists
@ AlreadyExists
Definition: ArgumentParser.h:52
ArgumentParser::Success
@ Success
Definition: ArgumentParser.h:49
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
ArgumentParser::registerFlag
Result registerFlag(char arg, const char *name, const char *description)
Register a flag Argument.
Definition: ArgumentParser.cpp:100
ArgumentParser::name
const String & name() const
Retrieve program name.
Definition: ArgumentParser.cpp:85
ArgumentParser::m_flagsId
HashTable< String, Argument * > m_flagsId
Contains all registered flag arguments by single character identifier.
Definition: ArgumentParser.h:143
ArgumentParser::registerPositional
Result registerPositional(const char *name, const char *description, Size count=1)
Register a positional argument.
Definition: ArgumentParser.cpp:119
Argument.h
String.h
Vector< Argument * >
ArgumentParser::getUsage
String getUsage() const
Get program usage.
Definition: ArgumentParser.cpp:42
ArgumentParser::setName
void setName(const char *name)
Set program name.
Definition: ArgumentParser.cpp:90
ArgumentParser::parse
Result parse(int argc, char **argv, ArgumentContainer &output)
Parse input arguments.
Definition: ArgumentParser.cpp:136