SUMO - Simulation of Urban MObility
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
Option.cpp
Go to the documentation of this file.
1
/****************************************************************************/
9
// A class representing a single program option
10
/****************************************************************************/
11
// SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
12
// Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
13
/****************************************************************************/
14
//
15
// This file is part of SUMO.
16
// SUMO is free software: you can redistribute it and/or modify
17
// it under the terms of the GNU General Public License as published by
18
// the Free Software Foundation, either version 3 of the License, or
19
// (at your option) any later version.
20
//
21
/****************************************************************************/
22
23
24
// ===========================================================================
25
// included modules
26
// ===========================================================================
27
#ifdef _MSC_VER
28
#include <
windows_config.h
>
29
#else
30
#include <
config.h
>
31
#endif
32
33
#include <string>
34
#include <exception>
35
#include <sstream>
36
#include "
Option.h
"
37
#include <
utils/common/TplConvert.h
>
38
#include <
utils/common/UtilExceptions.h
>
39
#include <
utils/common/StringTokenizer.h
>
40
#include <
utils/common/MsgHandler.h
>
41
#include <
utils/common/ToString.h
>
42
43
#ifdef CHECK_MEMORY_LEAKS
44
#include <
foreign/nvwa/debug_new.h
>
45
#endif // CHECK_MEMORY_LEAKS
46
47
48
// ===========================================================================
49
// method definitions
50
// ===========================================================================
51
/* -------------------------------------------------------------------------
52
* Option - methods
53
* ----------------------------------------------------------------------- */
54
Option::Option
(
bool
set
)
55
: myAmSet(set), myHaveTheDefaultValue(true), myAmWritable(true) {}
56
57
58
Option::Option
(
const
Option
& s)
59
: myAmSet(s.myAmSet), myHaveTheDefaultValue(s.myHaveTheDefaultValue),
60
myAmWritable(s.myAmWritable) {}
61
62
63
Option::~Option
() {}
64
65
66
Option
&
67
Option::operator=
(
const
Option
& s) {
68
if
(
this
== &s) {
69
return
*
this
;
70
}
71
myAmSet
= s.
myAmSet
;
72
myHaveTheDefaultValue
= s.
myHaveTheDefaultValue
;
73
myAmWritable
= s.
myAmWritable
;
74
return
*
this
;
75
}
76
77
78
bool
79
Option::isSet
()
const
{
80
return
myAmSet
;
81
}
82
83
84
SUMOReal
85
Option::getFloat
()
const
{
86
throw
InvalidArgument
(
"This is not a SUMOReal-option"
);
87
}
88
89
90
int
91
Option::getInt
()
const
{
92
throw
InvalidArgument
(
"This is not an int-option"
);
93
}
94
95
96
std::string
97
Option::getString
()
const
{
98
throw
InvalidArgument
(
"This is not a string-option"
);
99
}
100
101
102
bool
103
Option::getBool
()
const
{
104
throw
InvalidArgument
(
"This is not a bool-option"
);
105
}
106
107
108
const
IntVector
&
109
Option::getIntVector
()
const
{
110
throw
InvalidArgument
(
"This is not an int vector-option"
);
111
}
112
113
114
bool
115
Option::markSet
() {
116
bool
ret =
myAmWritable
;
117
myHaveTheDefaultValue
=
false
;
118
myAmSet
=
true
;
119
myAmWritable
=
false
;
120
return
ret;
121
}
122
123
124
void
125
Option::unSet
() {
126
myAmSet
=
false
;
127
myAmWritable
=
true
;
128
}
129
130
131
bool
132
Option::isBool
()
const
{
133
return
false
;
134
}
135
136
137
bool
138
Option::isDefault
()
const
{
139
return
myHaveTheDefaultValue
;
140
}
141
142
143
bool
144
Option::isFileName
()
const
{
145
return
false
;
146
}
147
148
149
bool
150
Option::isWriteable
()
const
{
151
return
myAmWritable
;
152
}
153
154
155
void
156
Option::resetWritable
() {
157
myAmWritable
=
true
;
158
}
159
160
161
const
std::string&
162
Option::getDescription
()
const
{
163
return
myDescription
;
164
}
165
166
167
void
168
Option::setDescription
(
const
std::string& desc) {
169
myDescription
= desc;
170
}
171
172
173
const
std::string&
174
Option::getTypeName
()
const
{
175
return
myTypeName
;
176
}
177
178
179
180
181
/* -------------------------------------------------------------------------
182
* Option_Integer - methods
183
* ----------------------------------------------------------------------- */
184
Option_Integer::Option_Integer
()
185
:
Option
() {
186
myTypeName
=
"INT"
;
187
}
188
189
190
Option_Integer::Option_Integer
(
int
value)
191
:
Option
(true), myValue(value) {
192
myTypeName
=
"INT"
;
193
}
194
195
196
Option_Integer::~Option_Integer
() {}
197
198
199
Option_Integer::Option_Integer
(
const
Option_Integer
& s)
200
:
Option
(s) {
201
myValue
= s.
myValue
;
202
}
203
204
205
Option_Integer
&
206
Option_Integer::operator=
(
const
Option_Integer
& s) {
207
if
(
this
== &s) {
208
return
*
this
;
209
}
210
Option::operator=
(s);
211
myValue
= s.
myValue
;
212
return
*
this
;
213
}
214
215
216
int
217
Option_Integer::getInt
()
const
{
218
return
myValue
;
219
}
220
221
222
bool
223
Option_Integer::set
(
const
std::string& v) {
224
try
{
225
myValue
=
TplConvert::_2int
(v.c_str());
226
return
markSet
();
227
}
catch
(...) {
228
std::string s =
"'"
+ v +
"' is not a valid integer."
;
229
throw
ProcessError
(s);
230
}
231
}
232
233
234
std::string
235
Option_Integer::getValueString
()
const
{
236
std::ostringstream s;
237
s <<
myValue
;
238
return
s.str();
239
}
240
241
242
243
/* -------------------------------------------------------------------------
244
* Option_String - methods
245
* ----------------------------------------------------------------------- */
246
Option_String::Option_String
()
247
:
Option
() {
248
myTypeName
=
"STR"
;
249
}
250
251
252
Option_String::Option_String
(
const
std::string& value, std::string typeName)
253
:
Option
(true), myValue(value) {
254
myTypeName
= typeName;
255
}
256
257
258
Option_String::~Option_String
() {}
259
260
261
Option_String::Option_String
(
const
Option_String
& s)
262
:
Option
(s) {
263
myValue
= s.
myValue
;
264
}
265
266
267
Option_String
&
268
Option_String::operator=
(
const
Option_String
& s) {
269
if
(
this
== &s) {
270
return
*
this
;
271
}
272
Option::operator=
(s);
273
myValue
= s.
myValue
;
274
return
*
this
;
275
}
276
277
278
std::string
279
Option_String::getString
()
const
{
280
return
myValue
;
281
}
282
283
284
bool
285
Option_String::set
(
const
std::string& v) {
286
myValue
= v;
287
return
markSet
();
288
}
289
290
291
std::string
292
Option_String::getValueString
()
const
{
293
return
myValue
;
294
}
295
296
297
298
/* -------------------------------------------------------------------------
299
* Option_Float - methods
300
* ----------------------------------------------------------------------- */
301
Option_Float::Option_Float
()
302
:
Option
() {
303
myTypeName
=
"FLOAT"
;
304
}
305
306
307
Option_Float::Option_Float
(
SUMOReal
value)
308
:
Option
(true), myValue(value) {
309
myTypeName
=
"FLOAT"
;
310
}
311
312
313
Option_Float::~Option_Float
() {}
314
315
316
Option_Float::Option_Float
(
const
Option_Float
& s)
317
:
Option
(s) {
318
myValue
= s.
myValue
;
319
}
320
321
322
Option_Float
&
323
Option_Float::operator=
(
const
Option_Float
& s) {
324
if
(
this
== &s) {
325
return
*
this
;
326
}
327
Option::operator=
(s);
328
myValue
= s.
myValue
;
329
return
*
this
;
330
}
331
332
333
SUMOReal
334
Option_Float::getFloat
()
const
{
335
return
myValue
;
336
}
337
338
339
bool
340
Option_Float::set
(
const
std::string& v) {
341
try
{
342
myValue
=
TplConvert::_2SUMOReal
(v.c_str());
343
return
markSet
();
344
}
catch
(...) {
345
throw
ProcessError
(
"'"
+ v +
"' is not a valid float."
);
346
}
347
}
348
349
350
std::string
351
Option_Float::getValueString
()
const
{
352
std::ostringstream s;
353
s <<
myValue
;
354
return
s.str();
355
}
356
357
358
359
/* -------------------------------------------------------------------------
360
* Option_Bool - methods
361
* ----------------------------------------------------------------------- */
362
Option_Bool::Option_Bool
()
363
:
Option
() {
364
myTypeName
=
"BOOL"
;
365
}
366
367
368
Option_Bool::Option_Bool
(
bool
value)
369
:
Option
(true), myValue(value) {
370
myTypeName
=
"BOOL"
;
371
}
372
373
374
Option_Bool::~Option_Bool
() {}
375
376
377
Option_Bool::Option_Bool
(
const
Option_Bool
& s)
378
:
Option
(s) {
379
myValue
= s.
myValue
;
380
}
381
382
383
Option_Bool
&
384
Option_Bool::operator=
(
const
Option_Bool
& s) {
385
if
(
this
== &s) {
386
return
*
this
;
387
}
388
Option::operator=
(s);
389
myValue
= s.
myValue
;
390
return
*
this
;
391
}
392
393
394
bool
395
Option_Bool::getBool
()
const
{
396
return
myValue
;
397
}
398
399
400
bool
401
Option_Bool::set
(
const
std::string& v) {
402
try
{
403
myValue
=
TplConvert::_2bool
(v.c_str());
404
return
markSet
();
405
}
catch
(...) {
406
throw
ProcessError
(
"'"
+ v +
"' is not a valid bool."
);
407
}
408
}
409
410
411
std::string
412
Option_Bool::getValueString
()
const
{
413
if
(
myValue
) {
414
return
"true"
;
415
}
416
return
"false"
;
417
}
418
419
420
bool
421
Option_Bool::isBool
()
const
{
422
return
true
;
423
}
424
425
426
427
/* -------------------------------------------------------------------------
428
* Option_FileName - methods
429
* ----------------------------------------------------------------------- */
430
Option_FileName::Option_FileName
()
431
:
Option_String
() {
432
myTypeName
=
"FILE"
;
433
}
434
435
436
Option_FileName::Option_FileName
(
const
std::string& value)
437
:
Option_String
(value) {
438
myTypeName
=
"FILE"
;
439
}
440
441
442
Option_FileName::Option_FileName
(
const
Option_String
& s)
443
:
Option_String
(s) {}
444
445
446
Option_FileName::~Option_FileName
() {}
447
448
449
Option_FileName
&
450
Option_FileName::operator=
(
const
Option_FileName
& s) {
451
Option_String::operator=
(s);
452
return
(*
this
);
453
}
454
455
456
bool
457
Option_FileName::isFileName
()
const
{
458
return
true
;
459
}
460
461
462
463
/* -------------------------------------------------------------------------
464
* Option_UIntVector - methods
465
* ----------------------------------------------------------------------- */
466
Option_IntVector::Option_IntVector
()
467
:
Option
() {
468
myTypeName
=
"INT[]"
;
469
}
470
471
472
Option_IntVector::Option_IntVector
(
const
IntVector
& value)
473
:
Option
(true), myValue(value) {
474
myTypeName
=
"INT[]"
;
475
}
476
477
478
Option_IntVector::Option_IntVector
(
const
Option_IntVector
& s)
479
:
Option
(s), myValue(s.myValue) {}
480
481
482
Option_IntVector::~Option_IntVector
() {}
483
484
485
Option_IntVector
&
486
Option_IntVector::operator=
(
const
Option_IntVector
& s) {
487
Option::operator=
(s);
488
myValue
= s.
myValue
;
489
return
(*
this
);
490
}
491
492
493
const
IntVector
&
494
Option_IntVector::getIntVector
()
const
{
495
return
myValue
;
496
}
497
498
499
bool
500
Option_IntVector::set
(
const
std::string& v) {
501
myValue
.clear();
502
try
{
503
if
(v.find(
';'
) != std::string::npos) {
504
WRITE_WARNING
(
"Please note that using ';' as list separator is deprecated.\n From 1.0 onwards, only ',' will be accepted."
);
505
}
506
StringTokenizer
st(v,
";,"
,
true
);
507
while
(st.
hasNext
()) {
508
myValue
.push_back(
TplConvert::_2int
(st.
next
().c_str()));
509
}
510
return
markSet
();
511
}
catch
(
EmptyData
&) {
512
throw
ProcessError
(
"Empty element occured in "
+ v);
513
}
catch
(...) {
514
throw
ProcessError
(
"'"
+ v +
"' is not a valid integer vector."
);
515
}
516
}
517
518
519
std::string
520
Option_IntVector::getValueString
()
const
{
521
return
joinToString
(
myValue
,
','
);
522
}
523
524
525
526
/****************************************************************************/
527
build
buildd
sumo-0.16.0~dfsg
src
utils
options
Option.cpp
Generated on Tue Apr 16 2013 01:32:19 for SUMO - Simulation of Urban MObility by
1.8.3.1