Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

test files, no real content.

  • 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  int a = ImplicitConversion<FooBar, const char*>::exists;
85  int val1;
86  long long val2 = conversion_cast<long long>(val1);
87  //val2 = val1;
88  //convertValue(&val2, val1);
89  //explicitConversion(&FooBar(), val1);
90
91  //using namespace1::fooBar1;
92  //fooBar1();
93  //int val1;
94  //char val2;
95  //explicitConversion(&val1, val2);
96
97  std::istringstream asdf;
98  //asdf >> val2;
99
100  int i = 1;
101  while (i < argc)
102  {
103    if (argv[i][0] == '-' && argv[i][1] == '-') // name
104    {
105      if (argv[i][2] == '\0')
106      {
107        failure_ = true;
108        errorString_ += "Expected word after \"--\".\n";
109      }
110      arg.bChecked_ = false;
111      arg.name_ = argv[i] + 2;
112      arg.value_ = "";
113      arguments_.push_back(arg);
114    }
115    else // value
116    {
117      if (arguments_.size() == 0)
118      {
119        failure_ = true;
120        errorString_ += "Expected \"--\" in command line arguments.\n";
121        arg.bChecked_ = false;
122        arg.name_ = "";
123        arg.value_ = "";
124        arguments_.push_back(arg);
125      }
126
127      if (arguments_.back().value_ != "")
128        arguments_.back().value_ += " " + std::string(argv[i]);
129      else
130        arguments_.back().value_ = argv[i];
131    }
132    ++i;
133  }
134}
135
136bool ArgReader::errorHandling()
137{
138  bool argumentsChecked = true;
139  for (unsigned int i = 1; i < arguments_.size(); ++i)
140    argumentsChecked &= arguments_[i].bChecked_;
141
142  if (!argumentsChecked)
143    errorString_ += "Not all arguments could be matched.\n";
144
145  return !argumentsChecked || failure_;
146}
147
148const std::string& ArgReader::getErrorString()
149{
150  return errorString_;
151}
Note: See TracBrowser for help on using the repository browser.