• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /***************************************************************************
2  *
3  * Copyright 2010,2011 BMW Car IT GmbH
4  *
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  ****************************************************************************/
19 #include "Argument.h"
20 #include <iostream>
21 #include <stdlib.h>
22 
BoolArgument(string name,bool default_value,int argc,const char * const argv[])23 BoolArgument::BoolArgument(string name, bool default_value, int argc, const char * const argv[])
24 : value(default_value)
25 {
26     for (int arg = 1; arg < argc; ++arg) {
27         const char* lpArgNow = argv[arg];
28 
29         if ((lpArgNow[0] == '-') && (name == &lpArgNow[1])) {
30             value = !value;
31         }
32     }
33 }
34 
get()35 bool BoolArgument::get()
36 {
37     return value;
38 }
39 
FloatArgument(string name,float default_value,int argc,const char * const argv[])40 FloatArgument::FloatArgument(string name, float default_value, int argc, const char * const argv[])
41 : value(default_value)
42 {
43     for (int arg = 1; arg < argc; ++arg)
44     {
45         char dummy[] = "";
46         const char* lpArgNow = argv[arg];
47         const char* lpArgNext = dummy;
48 
49         if (arg != argc - 1)
50         {
51             lpArgNext = argv[arg + 1];
52         }
53 
54         if ((lpArgNow[0] == '-') && (name == &lpArgNow[1]))
55         {
56             value = atof(lpArgNext);
57         }
58     }
59 }
60 
get()61 float FloatArgument::get()
62 {
63     return value;
64 }
65 
66 
IntArgument(string name,int default_value,int argc,const char * const argv[])67 IntArgument::IntArgument(string name, int default_value, int argc, const char * const argv[])
68 : value(default_value)
69 {
70     for (int arg = 1; arg < argc; ++arg)
71     {
72         char dummy[] = "";
73         const char* lpArgNow = argv[arg];
74         const char* lpArgNext = dummy;
75 
76         if (arg != argc - 1)
77         {
78             lpArgNext = argv[arg + 1];
79         }
80 
81         if ((lpArgNow[0] == '-') && (name == &lpArgNow[1]))
82         {
83             value = atoi(lpArgNext);
84         }
85     }
86 }
87 
get()88 int IntArgument::get()
89 {
90     return value;
91 }
92 
93 
UnsignedIntArgument(string name,unsigned int default_value,int argc,const char * const argv[])94 UnsignedIntArgument::UnsignedIntArgument(string name, unsigned int default_value, int argc, const char * const argv[])
95 : value(default_value)
96 {
97     for (int arg = 1; arg < argc; ++arg)
98     {
99         char dummy[] = "";
100         const char* lpArgNow = argv[arg];
101         const char* lpArgNext = dummy;
102 
103         if (arg != argc - 1)
104         {
105             lpArgNext = argv[arg + 1];
106         }
107 
108         if ((lpArgNow[0] == '-') && (name == &lpArgNow[1]))
109         {
110             value = atoll(lpArgNext);
111         }
112     }
113 }
114 
get()115 unsigned int UnsignedIntArgument::get()
116 {
117     return value;
118 }
119