FreeNOS
ArgumentContainer.cpp
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#include "ArgumentContainer.h"
19
23
25{
26 // cleanup flags
28 it.hasCurrent();)
29 {
30 delete it.current();
31 it.remove();
32 }
33
34 // cleanup positionals
35 for (Size i = 0; i < m_positionals.count(); i++)
36 delete m_positionals[i];
37}
38
43
48
49const char * ArgumentContainer::get(const char *name) const
50{
51 // Search flag arguments
52 const Argument * const *arg = m_flags.get(name);
53 if (arg)
54 return *(*arg)->getValue();
55
56 // Search positional arguments
57 for (Size i = 0; i < m_positionals.count(); i++)
58 {
59 const Argument *a = m_positionals[i];
60
61 if (a->getName().equals(name))
62 return *a->getValue();
63 }
64 return ZERO;
65}
66
72
const HashTable< String, Argument * > & getFlags() const
Get flag arguments.
virtual ~ArgumentContainer()
Destructor.
Result addPositional(Argument *arg)
Add positional argument.
HashTable< String, Argument * > m_flags
Contains all flag arguments.
Vector< Argument * > m_positionals
Contains all positional arguments.
const Vector< Argument * > & getPositionals() const
Get positional arguments.
ArgumentContainer()
Constructor.
const char * get(const char *name) const
Get argument by name.
Result addFlag(Argument *arg)
Add flag argument.
Represents program command line argument.
Definition Argument.h:36
const String & getValue() const
Retrieve argument option value (if any)
Definition Argument.cpp:54
const String & getName() const
Retrieve argument name.
Definition Argument.cpp:44
Iterate through a HashTable.
virtual bool hasCurrent() const
Check if there is a current item.
Efficient key -> value lookups.
Definition HashTable.h:45
virtual const V * get(const K &key) const
Returns the first value for the given key.
Definition HashTable.h:287
virtual bool insert(const K &key, const V &value)
Inserts the given item to the HashTable.
Definition HashTable.h:133
virtual bool equals(const String &str) const
Alias for compareTo().
Definition String.cpp:262
Vectors are dynamically resizeable Arrays.
Definition Vector.h:42
virtual int insert(const T &item)
Adds the given item to the Vector, if possible.
Definition Vector.h:93
virtual Size count() const
Returns the number of items inside the Vector.
Definition Vector.h:204
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128
#define ZERO
Zero value.
Definition Macros.h:43