Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/gui/src/util/ArgReader.cc @ 1997

Last change on this file since 1997 was 1652, checked in by rgrieder, 16 years ago
  • clean up in OrxonoxPlatform.h
  • that's it
  • Property svn:eol-style set to native
File size: 2.7 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Reto Grieder
24 *      Benjamin Knecht <beni_at_orxonox.net>
25 *   Co-authors:
26 *      ...
27 *
28 */
29
30/**
31 @file  ArgReader.cc
32 @brief Argument Reader
33 */
34
35#include "ArgReader.h"
36#include "SubString.h"
37
38
39std::string ArgReader::parse(int argc, char **argv)
40{
41    std::string errorString;
42    CmdLineArg arg;
43    int i = 1;
44    while (i < argc)
45    {
46        if (argv[i][0] == '-' && argv[i][1] == '-') // name
47        {
48            if (argv[i][2] == '\0')
49            {
50                errorString += "Expected word after \"--\".\n";
51            }
52            arg.bChecked_ = false;
53            arg.name_ = argv[i] + 2;
54            arg.value_ = " ";
55            arguments_.push_back(arg);
56        }
57        else // value
58        {
59            if (arguments_.size() == 0)
60            {
61                errorString += "Expected \"--\" in command line arguments.\n";
62                arg.bChecked_ = false;
63                arg.name_ = "";
64                arg.value_ = " ";
65                arguments_.push_back(arg);
66            }
67
68            if (arguments_.back().value_ != " ")
69                arguments_.back().value_ += " " + std::string(argv[i]);
70            else
71                arguments_.back().value_ = argv[i];
72        }
73        ++i;
74    }
75    return errorString;
76}
77
78const std::string& ArgReader::getArgument(const std::string& option)
79{
80    unsigned int iArg = 0;
81    while (iArg < arguments_.size())
82    {
83        if (arguments_[iArg].name_ == option)
84        {
85            arguments_[iArg].bChecked_ = true;
86            return arguments_[iArg].value_;
87        }
88        ++iArg;
89    }
90    return blankString;
91}
92
93bool ArgReader::allChecked()
94{
95    bool argumentsChecked = true;
96    for (unsigned int i = 1; i < arguments_.size(); ++i)
97        argumentsChecked &= arguments_[i].bChecked_;
98
99    return argumentsChecked;
100}
Note: See TracBrowser for help on using the repository browser.