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
SUMOSAXAttributes.h
Go to the documentation of this file.
1
/****************************************************************************/
9
// Encapsulated SAX-Attributes
10
/****************************************************************************/
11
// SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
12
// Copyright (C) 2001-2013 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
#ifndef SUMOSAXAttributes_h
23
#define SUMOSAXAttributes_h
24
25
26
// ===========================================================================
27
// included modules
28
// ===========================================================================
29
#ifdef _MSC_VER
30
#include <
windows_config.h
>
31
#else
32
#include <
config.h
>
33
#endif
34
35
#include <string>
36
#include <vector>
37
38
#include <
utils/common/SUMOTime.h
>
39
#include <
utils/common/ToString.h
>
40
#include <
utils/common/UtilExceptions.h
>
41
#include "
SUMOXMLDefinitions.h
"
42
43
44
// ===========================================================================
45
// class declarations
46
// ===========================================================================
47
class
PositionVector
;
48
class
Boundary
;
49
class
RGBColor
;
50
51
52
// ===========================================================================
53
// class definitions
54
// ===========================================================================
63
class
SUMOSAXAttributes
{
64
public
:
65
/* @brief Constructor
66
* @param[in] tagName The name of the parsed object type; used for error message generation
67
*/
68
SUMOSAXAttributes
(
const
std::string& objectType);
69
70
72
virtual
~SUMOSAXAttributes
() { }
73
74
88
template
<
typename
T>
89
T
get
(
int
attr,
const
char
* objectid,
bool
& ok,
bool
report =
true
)
const
;
90
91
107
template
<
typename
T>
108
T
getOpt
(
int
attr,
const
char
* objectid,
bool
& ok, T defaultValue,
bool
report =
true
)
const
;
109
110
127
SUMOTime
getSUMOTimeReporting
(
int
attr,
const
char
* objectid,
bool
& ok,
128
bool
report =
true
)
const
;
129
130
131
150
SUMOTime
getOptSUMOTimeReporting
(
int
attr,
const
char
* objectid,
bool
& ok,
151
SUMOTime
defaultValue,
bool
report =
true
)
const
;
152
153
154
157
163
virtual
bool
hasAttribute
(
int
id
)
const
= 0;
164
165
171
virtual
bool
hasAttribute
(
const
std::string&
id
)
const
= 0;
172
173
189
virtual
bool
getBool
(
int
id
)
const
= 0;
190
206
virtual
int
getInt
(
int
id
)
const
= 0;
207
208
224
virtual
SUMOLong
getLong
(
int
id
)
const
= 0;
225
226
239
virtual
std::string
getString
(
int
id
)
const
= 0;
240
241
254
virtual
std::string
getStringSecure
(
int
id
,
255
const
std::string& def)
const
= 0;
256
257
273
virtual
SUMOReal
getFloat
(
int
id
)
const
= 0;
274
275
291
virtual
SUMOReal
getFloat
(
const
std::string&
id
)
const
= 0;
292
293
303
virtual
std::string
getStringSecure
(
const
std::string&
id
,
304
const
std::string& def)
const
= 0;
305
306
313
virtual
SumoXMLEdgeFunc
getEdgeFunc
(
bool
& ok)
const
= 0;
314
315
322
virtual
SumoXMLNodeType
getNodeType
(
bool
& ok)
const
= 0;
323
324
331
virtual
RGBColor
getColor
()
const
= 0;
332
333
339
virtual
PositionVector
getShape
(
int
attr)
const
= 0;
340
346
virtual
Boundary
getBoundary
(
int
attr)
const
= 0;
347
353
virtual
std::vector<std::string>
getStringVector
(
int
attr)
const
= 0;
354
360
virtual
std::vector<SUMOReal>
getFloatVector
(
int
attr)
const
= 0;
361
//}
362
363
369
virtual
std::string
getName
(
int
attr)
const
= 0;
370
371
376
virtual
void
serialize
(std::ostream& os)
const
= 0;
377
378
380
const
std::string&
getObjectType
()
const
{
381
return
myObjectType
;
382
}
383
384
385
friend
std::ostream&
operator<<
(std::ostream& os,
const
SUMOSAXAttributes
& src);
386
388
static
const
std::string
ENCODING
;
389
390
399
static
void
parseStringVector
(
const
std::string& def, std::vector<std::string>& into);
400
401
402
protected
:
403
template
<
typename
T> T
getInternal
(
const
int
attr)
const
;
404
void
emitUngivenError
(
const
std::string& attrname,
const
char
* objectid)
const
;
405
void
emitEmptyError
(
const
std::string& attrname,
const
char
* objectid)
const
;
406
void
emitFormatError
(
const
std::string& attrname,
const
std::string& type,
const
char
* objectid)
const
;
407
408
private
:
410
static
bool
myHaveInformedAboutDeprecatedDivider
;
411
412
private
:
414
SUMOSAXAttributes
(
const
SUMOSAXAttributes
& src);
415
417
SUMOSAXAttributes
&
operator=
(
const
SUMOSAXAttributes
& src);
418
420
std::string
myObjectType
;
421
422
};
423
424
425
inline
std::ostream&
operator<<
(std::ostream& os,
const
SUMOSAXAttributes
& src) {
426
src.
serialize
(os);
427
return
os;
428
}
429
430
431
template
<
typename
X>
struct
invalid_return
{
432
static
const
X
value
;
433
static
const
std::string
type
;
434
};
435
436
437
template
<
typename
T>
438
T
SUMOSAXAttributes::get
(
int
attr,
const
char
* objectid,
439
bool
& ok,
bool
report)
const
{
440
if
(!
hasAttribute
(attr)) {
441
if
(report) {
442
emitUngivenError
(
getName
(attr), objectid);
443
}
444
ok =
false
;
445
return
invalid_return<T>::value
;
446
}
447
try
{
448
return
getInternal<T>(attr);
449
}
catch
(
FormatException
&) {
450
if
(report) {
451
emitFormatError
(
getName
(attr),
"of type "
+
invalid_return<T>::type
, objectid);
452
}
453
}
catch
(
EmptyData
&) {
454
if
(report) {
455
emitEmptyError
(
getName
(attr), objectid);
456
}
457
}
458
ok =
false
;
459
return
invalid_return<T>::value
;
460
}
461
462
463
template
<
typename
T>
464
T
SUMOSAXAttributes::getOpt
(
int
attr,
const
char
* objectid,
465
bool
& ok, T defaultValue,
bool
report)
const
{
466
if
(!
hasAttribute
(attr)) {
467
return
defaultValue;
468
}
469
try
{
470
return
getInternal<T>(attr);
471
}
catch
(
FormatException
&) {
472
if
(report) {
473
emitFormatError
(
getName
(attr),
"of type "
+
invalid_return<T>::type
, objectid);
474
}
475
}
catch
(
EmptyData
&) {
476
if
(report) {
477
emitEmptyError
(
getName
(attr), objectid);
478
}
479
}
480
ok =
false
;
481
return
invalid_return<T>::value
;
482
}
483
484
485
#endif
486
487
/****************************************************************************/
488
home
gladk
tmp
05
sumo-0.17.1~dfsg
src
utils
xml
SUMOSAXAttributes.h
Generated on Sun Jun 16 2013 07:08:32 for SUMO - Simulation of Urban MObility by
1.8.1.2