GteCommand.cpp
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #include <GTEnginePCH.h>
9 #include <LowLevel/GteLogger.h>
11 using namespace gte;
12 
13 std::string const Command::msOptNotFound("Option not found.");
14 std::string const Command::msArgRequired("Option requires an argument.");
15 std::string const Command::msArgOutOfRange("Argument out of range.");
16 std::string const Command::msFilenameNotFound("Filename not found.");
17 std::string const Command::msDash("-");
18 
19 
21 {
22 }
23 
24 Command::Command (int numArguments, char const* arguments[])
25  :
26  mSmall(0.0),
27  mLarge(0.0),
28  mMinSet(false),
29  mMaxSet(false),
30  mInfSet(false),
31  mSupSet(false),
32  mLastError("")
33 {
34  // The first argument is always the executable name.
35  LogAssert(numArguments > 0, "Invalid number of arguments.");
36 
37  mArguments.resize(numArguments);
38  mProcessed.resize(numArguments);
39  for (int i = 0; i < numArguments; ++i)
40  {
41  mArguments[i] = std::string(arguments[i]);
42  mProcessed[i] = false;
43  }
44 
45  // The executable name, which is considered to have been processed.
46  mProcessed[0] = true;
47 }
48 
50 {
51  // Check to see whether any command line arguments were not processed.
52  int const numArguments = (int)mArguments.size();
53  for (int i = 1; i < numArguments; ++i)
54  {
55  if (!mProcessed[i])
56  {
57  return i;
58  }
59  }
60  return 0;
61 }
62 
64 {
65  mSmall = value;
66  mMinSet = true;
67  return *this;
68 }
69 
71 {
72  mLarge = value;
73  mMaxSet = true;
74  return *this;
75 }
76 
78 {
79  mSmall = value;
80  mInfSet = true;
81  return *this;
82 }
83 
85 {
86  mLarge = value;
87  mSupSet = true;
88  return *this;
89 }
90 
92 {
93  bool value = false;
94  return GetBoolean(name, value);
95 }
96 
98 {
99  int matchFound = 0;
100  value = false;
101 
102  int const numArguments = (int)mArguments.size();
103  for (int i = 1; i < numArguments; ++i)
104  {
105  std::string tmp = mArguments[i];
106  if (!mProcessed[i] && mArguments[i] == (msDash + name))
107  {
108  mProcessed[i] = true;
109  matchFound = i;
110  value = true;
111  break;
112  }
113  }
114 
115  if (matchFound == 0)
116  {
118  }
119 
120  return matchFound;
121 }
122 
124 {
125  int matchFound = 0;
126 
127  int const numArguments = (int)mArguments.size();
128  for (int i = 1; i < numArguments; ++i)
129  {
130  if (!mProcessed[i] && mArguments[i] == (msDash + name))
131  {
132  std::string argument = mArguments[i + 1];
133  if (mProcessed[i + 1]
134  || (argument[0] == '-' && !isdigit((int)argument[1])))
135  {
137  return 0;
138  }
139 
140  value = atoi(argument.c_str());
141  if ((mMinSet && value < mSmall)
142  || (mMaxSet && value > mLarge)
143  || (mInfSet && value <= mSmall)
144  || (mSupSet && value >= mLarge))
145  {
147  return 0;
148  }
149 
150  mProcessed[i] = true;
151  mProcessed[i + 1] = true;
152  matchFound = i;
153  break;
154  }
155  }
156 
157  mMinSet = false;
158  mMaxSet = false;
159  mInfSet = false;
160  mSupSet = false;
161 
162  if (matchFound == 0)
163  {
165  }
166 
167  return matchFound;
168 }
169 
171 {
172  int matchFound = 0;
173 
174  int const numArguments = (int)mArguments.size();
175  for (int i = 1; i <numArguments; ++i)
176  {
177  if (!mProcessed[i] && mArguments[i] == (msDash + name))
178  {
179  std::string argument = mArguments[i + 1];
180  if (mProcessed[i + 1]
181  || (argument[0] == '-' && !isdigit((int)argument[1])))
182  {
184  return 0;
185  }
186 
187  value = (float)atof(argument.c_str());
188  if ((mMinSet && value < mSmall)
189  || (mMaxSet && value > mLarge)
190  || (mInfSet && value <= mSmall)
191  || (mSupSet && value >= mLarge))
192  {
194  return 0;
195  }
196 
197  mProcessed[i] = true;
198  mProcessed[i + 1] = true;
199  matchFound = i;
200  break;
201  }
202  }
203 
204  mMinSet = false;
205  mMaxSet = false;
206  mInfSet = false;
207  mSupSet = false;
208 
209  if (matchFound == 0)
210  {
212  }
213 
214  return matchFound;
215 }
216 
218 {
219  int matchFound = 0;
220 
221  int const numArguments = (int)mArguments.size();
222  for (int i = 1; i < numArguments; ++i)
223  {
224  if (!mProcessed[i] && mArguments[i] == (msDash + name))
225  {
226  std::string argument = mArguments[i + 1];
227  if (mProcessed[i + 1]
228  || (argument[0] == '-' && !isdigit((int)argument[1])))
229  {
231  return 0;
232  }
233 
234  value = atof(argument.c_str());
235  if ((mMinSet && value < mSmall)
236  || (mMaxSet && value > mLarge)
237  || (mInfSet && value <= mSmall)
238  || (mSupSet && value >= mLarge))
239  {
241  return 0;
242  }
243 
244  mProcessed[i] = true;
245  mProcessed[i + 1] = true;
246  matchFound = i;
247  break;
248  }
249  }
250 
251  mMinSet = false;
252  mMaxSet = false;
253  mInfSet = false;
254  mSupSet = false;
255 
256  if (matchFound == 0)
257  {
259  }
260 
261  return matchFound;
262 }
263 
265 {
266  int matchFound = 0;
267 
268  int const numArguments = (int)mArguments.size();
269  for (int i = 1; i < numArguments; ++i)
270  {
271  if (!mProcessed[i] && mArguments[i] == (msDash + name))
272  {
273  std::string argument = mArguments[i + 1];
274  if (mProcessed[i + 1] || argument[0] == '-')
275  {
277  return 0;
278  }
279 
280  value = argument;
281  mProcessed[i] = true;
282  mProcessed[i + 1] = true;
283  matchFound = i;
284  break;
285  }
286  }
287 
288  if (matchFound == 0)
289  {
291  }
292 
293  return matchFound;
294 }
295 
296 int Command::GetFilename (std::string& value, int startArgIndex)
297 {
298  int matchFound = 0;
299 
300  int const numArguments = (int)mArguments.size();
301  for (int i = startArgIndex; i < numArguments; ++i)
302  {
303  std::string argument = mArguments[i];
304  if (!mProcessed[i] && argument[0] != '-')
305  {
306  value = argument;
307  mProcessed[i] = true;
308  matchFound = i;
309  break;
310  }
311  }
312 
313  if (matchFound == 0)
314  {
316  }
317 
318  return matchFound;
319 }
320 
322 {
323  return mLastError;
324 }
325 
Command & Max(double value)
Definition: GteCommand.cpp:70
std::vector< bool > mProcessed
Definition: GteCommand.h:58
Command & Sup(double value)
Definition: GteCommand.cpp:84
double mSmall
Definition: GteCommand.h:61
double mLarge
Definition: GteCommand.h:62
#define LogAssert(condition, message)
Definition: GteLogger.h:86
std::string GetLastError() const
Definition: GteCommand.cpp:321
static std::string const msArgOutOfRange
Definition: GteCommand.h:72
GLsizei const GLfloat * value
Definition: glcorearb.h:819
Command & Inf(double value)
Definition: GteCommand.cpp:77
GLuint const GLchar * name
Definition: glcorearb.h:781
int GetDouble(std::string const &name, double &value)
Definition: GteCommand.cpp:217
std::vector< std::string > mArguments
Definition: GteCommand.h:57
Command & Min(double value)
Definition: GteCommand.cpp:63
int GetString(std::string const &name, std::string &value)
Definition: GteCommand.cpp:264
int GetBoolean(std::string const &name)
Definition: GteCommand.cpp:91
GLsizei const GLchar *const * string
Definition: glcorearb.h:809
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
int GetFilename(std::string &value, int startArgIndex=1)
Definition: GteCommand.cpp:296
bool mInfSet
Definition: GteCommand.h:65
static std::string const msFilenameNotFound
Definition: GteCommand.h:73
int GetFloat(std::string const &name, float &value)
Definition: GteCommand.cpp:170
int ExcessArguments() const
Definition: GteCommand.cpp:49
bool mMaxSet
Definition: GteCommand.h:64
int GetInteger(std::string const &name, int &value)
Definition: GteCommand.cpp:123
static std::string const msDash
Definition: GteCommand.h:74
static std::string const msOptNotFound
Definition: GteCommand.h:70
bool mMinSet
Definition: GteCommand.h:63
bool mSupSet
Definition: GteCommand.h:66
Command(int numArguments, char const *arguments[])
Definition: GteCommand.cpp:24
static std::string const msArgRequired
Definition: GteCommand.h:71
std::string mLastError
Definition: GteCommand.h:69


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:59