OpenASIP 2.2
Loading...
Searching...
No Matches
CmdLineParser.hh
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file CmdLineParser.hh
26 *
27 * Declaration of class CmdLineParser.
28 *
29 * @author Jussi Nyk�nen 2003 (nykanen-no.spam-cs.tut.fi)
30 * @author Jari M�ntyneva 2006 (jari.mantyneva-no.spam-tut.fi)
31 * @note reviewed 3 December 2003 by jn, kl, ao
32 * @note rating: red
33 */
34
35#ifndef TTA_CMD_LINE_PARSER_HH
36#define TTA_CMD_LINE_PARSER_HH
37
38#include <map>
39#include <vector>
40#include <string>
41
43#include "Exception.hh"
44#include "Application.hh"
45
46class Options;
47
48/**
49 * Abstract base class for command line parsers.
50 *
51 * Is capable of storing and parsing commmand line options.
52 */
54public:
55 CmdLineParser(std::string description);
56 virtual ~CmdLineParser();
57
58 virtual void parse(char* argv[], int argc);
59 virtual void parse(std::vector<std::string> options);
60 virtual void storeOptions(Options& options);
61
62 virtual int numberOfArguments() const;
63 virtual std::string argument(int index) const;
64
65protected:
67 CmdLineOptionParser* findOption(std::string name) const;
68
69 bool parseOption(
70 std::string option, std::string& name, std::string& arguments,
71 std::string& prefix, bool& hasArgument) const;
72 bool readPrefix(
73 std::string& option,
74 std::string& prefix,
75 bool& longOption) const;
76 bool isPrefix(std::string name) const;
77
78 /// Database for holding options with their long names as a key.
79 std::map<std::string, CmdLineOptionParser*> optionLongNames_;
80 /// Database for holding options with their short names as a key.
81 std::map<std::string, CmdLineOptionParser*> optionShortNames_;
82
83 /// Command line is stored here.
84 std::vector<std::string> commandLine_;
85 /// Command line arguments are stored here.
86 std::vector<std::string> arguments_;
87 /// Legal prefixes are stored here.
88 std::vector<std::string> prefixes_;
89
90private:
91 /// For adding new values to maps.
92 typedef std::map<std::string, CmdLineOptionParser*>::value_type valType;
93 /// For traversing non-const maps.
94 typedef std::map<std::string, CmdLineOptionParser*>::iterator mapIter;
95 /// For traversing const maps.
96 typedef
97 std::map<std::string, CmdLineOptionParser*>::const_iterator constMapIter;
98
99 /// Copying not allowed.
101 /// Assignment not allowed.
103
104 void parseAll();
105
106 /// The name of the program.
107 std::string progName_;
108 /// The description of usage of program.
109 std::string description_;
110
111 /// Number of characters reserved for printing short version
112 /// of commandline flag.
113 static const int SHORT_FLAG;
114
115 /// Number of characters reserved for printing long version
116 /// of commandline flag.
117 static const int LONG_FLAG;
118};
119
120#include "CmdLineParser.icc"
121
122#endif
static MachInfoCmdLineOptions options
Definition MachInfo.cc:46
static const int SHORT_FLAG
Number of characters reserved for printing short version of commandline flag.
std::map< std::string, CmdLineOptionParser * >::const_iterator constMapIter
For traversing const maps.
std::map< std::string, CmdLineOptionParser * > optionLongNames_
Database for holding options with their long names as a key.
CmdLineParser & operator=(const CmdLineParser &)
Assignment not allowed.
virtual void storeOptions(Options &options)
std::string progName_
The name of the program.
std::vector< std::string > prefixes_
Legal prefixes are stored here.
std::vector< std::string > commandLine_
Command line is stored here.
CmdLineParser(const CmdLineParser &)
Copying not allowed.
std::map< std::string, CmdLineOptionParser * >::iterator mapIter
For traversing non-const maps.
virtual ~CmdLineParser()
virtual void parse(char *argv[], int argc)
CmdLineOptionParser * findOption(std::string name) const
std::string description_
The description of usage of program.
std::map< std::string, CmdLineOptionParser * >::value_type valType
For adding new values to maps.
virtual std::string argument(int index) const
std::vector< std::string > arguments_
Command line arguments are stored here.
bool parseOption(std::string option, std::string &name, std::string &arguments, std::string &prefix, bool &hasArgument) const
bool readPrefix(std::string &option, std::string &prefix, bool &longOption) const
std::map< std::string, CmdLineOptionParser * > optionShortNames_
Database for holding options with their short names as a key.
virtual int numberOfArguments() const
void addOption(CmdLineOptionParser *opt)
static const int LONG_FLAG
Number of characters reserved for printing long version of commandline flag.
bool isPrefix(std::string name) const