Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core3/src/util/ArgReader.cc @ 1710

Last change on this file since 1710 was 1535, checked in by rgrieder, 16 years ago

merged input branch back to trunk

  • Property svn:eol-style set to native
File size: 2.3 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 *   Co-authors:
25 *      Benjamin Knecht <beni_at_orxonox.net>
26 *
27 */
28
29/**
30 @file  ArgReader.cc
31 @brief Argument Reader
32 */
33
34#include "ArgReader.h"
35#include "SubString.h"
36
37ArgReader::ArgReader(int argc, char **argv)
38{
39  failure_ = false;
40  errorString_ = "";
41  CmdLineArg arg;
42
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        failure_ = true;
51        errorString_ += "Expected word after \"--\".\n";
52      }
53      arg.bChecked_ = false;
54      arg.name_ = argv[i] + 2;
55      arg.value_ = "";
56      arguments_.push_back(arg);
57    }
58    else // value
59    {
60      if (arguments_.size() == 0)
61      {
62        failure_ = true;
63        errorString_ += "Expected \"--\" in command line arguments.\n";
64        arg.bChecked_ = false;
65        arg.name_ = "";
66        arg.value_ = "";
67        arguments_.push_back(arg);
68      }
69
70      if (arguments_.back().value_ != "")
71        arguments_.back().value_ += " " + std::string(argv[i]);
72      else
73        arguments_.back().value_ = argv[i];
74    }
75    ++i;
76  }
77}
78
79bool ArgReader::errorHandling()
80{
81  bool argumentsChecked = true;
82  for (unsigned int i = 1; i < arguments_.size(); ++i)
83    argumentsChecked &= arguments_[i].bChecked_;
84
85  if (!argumentsChecked)
86    errorString_ += "Not all arguments could be matched.\n";
87
88  return !argumentsChecked || failure_;
89}
90
91const std::string& ArgReader::getErrorString()
92{
93  return errorString_;
94}
Note: See TracBrowser for help on using the repository browser.