Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

gcc test commit again

  • Property svn:eol-style set to native
File size: 3.5 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#include <ostream>
37#include <iostream>
38
39class FooBar
40{
41    //friend class ArgReader;
42public:
43    operator long long() const
44    {
45        return 0;
46    }
47    float float_;
48    static FooBar& createFooBar();
49private:
50    //FooBar();
51    //FooBar(const FooBar& instance);
52    //~FooBar();
53};
54
55inline std::ostream& operator<<(std::ostream& outstream, const FooBar& fb)
56{
57    return outstream << fb.float_;
58}
59inline std::istream& operator>>(std::istream& instream,  const FooBar& fb);
60//inline bool explicitConversion(const char** output, const FooBar input)
61//{
62//    return true;
63//}
64
65#include "Convert.h"
66
67template<>
68struct ConverterExplicit<const char*, FooBar>
69{
70    static bool convert(const char** output, const FooBar input)
71    {
72        return true;
73    }
74};
75
76#include "MultiType.h"
77
78ArgReader::ArgReader(int argc, char **argv)
79{
80  failure_ = false;
81  errorString_ = "";
82  CmdLineArg arg;
83
84  //std::cout << errorString_;
85
86  int a = conversionTests::ImplicitConversion<FooBar, const char*>::exists;
87  int val1;
88  long long val2 = conversion_cast<long long>(val1);
89  //val2 = val1;
90  //convertValue(&val2, val1);
91  //explicitConversion(&FooBar(), val1);
92
93  //using namespace1::fooBar1;
94  //fooBar1();
95  //int val1;
96  //char val2;
97  //explicitConversion(&val1, val2);
98
99  std::istringstream asdf;
100  //asdf >> val2;
101
102  int i = 1;
103  while (i < argc)
104  {
105    if (argv[i][0] == '-' && argv[i][1] == '-') // name
106    {
107      if (argv[i][2] == '\0')
108      {
109        failure_ = true;
110        errorString_ += "Expected word after \"--\".\n";
111      }
112      arg.bChecked_ = false;
113      arg.name_ = argv[i] + 2;
114      arg.value_ = "";
115      arguments_.push_back(arg);
116    }
117    else // value
118    {
119      if (arguments_.size() == 0)
120      {
121        failure_ = true;
122        errorString_ += "Expected \"--\" in command line arguments.\n";
123        arg.bChecked_ = false;
124        arg.name_ = "";
125        arg.value_ = "";
126        arguments_.push_back(arg);
127      }
128
129      if (arguments_.back().value_ != "")
130        arguments_.back().value_ += " " + std::string(argv[i]);
131      else
132        arguments_.back().value_ = argv[i];
133    }
134    ++i;
135  }
136}
137
138bool ArgReader::errorHandling()
139{
140  bool argumentsChecked = true;
141  for (unsigned int i = 1; i < arguments_.size(); ++i)
142    argumentsChecked &= arguments_[i].bChecked_;
143
144  if (!argumentsChecked)
145    errorString_ += "Not all arguments could be matched.\n";
146
147  return !argumentsChecked || failure_;
148}
149
150const std::string& ArgReader::getErrorString()
151{
152  return errorString_;
153}
Note: See TracBrowser for help on using the repository browser.