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
OptionsIO.cpp
Go to the documentation of this file.
1
/****************************************************************************/
8
// Helper for parsing command line arguments and reading configuration files
9
/****************************************************************************/
10
// SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
11
// Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
12
/****************************************************************************/
13
//
14
// This file is part of SUMO.
15
// SUMO is free software: you can redistribute it and/or modify
16
// it under the terms of the GNU General Public License as published by
17
// the Free Software Foundation, either version 3 of the License, or
18
// (at your option) any later version.
19
//
20
/****************************************************************************/
21
22
23
// ===========================================================================
24
// included modules
25
// ===========================================================================
26
#ifdef _MSC_VER
27
#include <
windows_config.h
>
28
#else
29
#include <
config.h
>
30
#endif
31
32
#include <string>
33
#include <iostream>
34
#include <xercesc/parsers/SAXParser.hpp>
35
#include <xercesc/sax/HandlerBase.hpp>
36
#include <xercesc/sax/AttributeList.hpp>
37
#include <xercesc/util/PlatformUtils.hpp>
38
#include <xercesc/sax/SAXParseException.hpp>
39
#include <xercesc/sax/SAXException.hpp>
40
#include <cstdlib>
41
#include "
OptionsIO.h
"
42
#include "
OptionsCont.h
"
43
#include "
OptionsLoader.h
"
44
#include "
OptionsParser.h
"
45
#include <
utils/common/FileHelpers.h
>
46
#include <
utils/common/MsgHandler.h
>
47
#include <
utils/common/TplConvert.h
>
48
49
#ifdef CHECK_MEMORY_LEAKS
50
#include <
foreign/nvwa/debug_new.h
>
51
#endif // CHECK_MEMORY_LEAKS
52
53
// ===========================================================================
54
// static member definitions
55
// ===========================================================================
56
int
OptionsIO::myArgC
;
57
char
**
OptionsIO::myArgV
;
58
59
60
// ===========================================================================
61
// method definitions
62
// ===========================================================================
63
void
64
OptionsIO::getOptions
(
bool
loadConfig,
int
argc,
char
** argv) {
65
// preparse the options
66
// (maybe another configuration file was chosen)
67
if
(argc > 0) {
68
myArgC
= argc;
69
myArgV
= argv;
70
}
71
if
(!
OptionsParser::parse
(
myArgC
,
myArgV
)) {
72
throw
ProcessError
(
"Could not parse commandline options."
);
73
}
74
// check whether to use the command line parameters only
75
if
(!loadConfig) {
76
return
;
77
}
78
// read the configuration when everything's ok
79
OptionsCont::getOptions
().resetWritable();
80
loadConfiguration
();
81
// reparse the options
82
// (overwrite the settings from the configuration file)
83
OptionsCont::getOptions
().resetWritable();
84
OptionsParser::parse
(
myArgC
,
myArgV
);
85
}
86
87
88
void
89
OptionsIO::loadConfiguration
() {
90
OptionsCont
& oc =
OptionsCont::getOptions
();
91
if
(!oc.
exists
(
"configuration-file"
) || !oc.
isSet
(
"configuration-file"
)) {
92
return
;
93
}
94
std::string path = oc.
getString
(
"configuration-file"
);
95
if
(!
FileHelpers::exists
(path)) {
96
throw
ProcessError
(
"Could not find configuration '"
+ oc.
getString
(
"configuration-file"
) +
"'."
);
97
}
98
PROGRESS_BEGIN_MESSAGE
(
"Loading configuration"
);
99
// build parser
100
SAXParser parser;
101
parser.setValidationScheme(SAXParser::Val_Auto);
102
parser.setDoNamespaces(
false
);
103
parser.setDoSchema(
false
);
104
// start the parsing
105
OptionsLoader
handler;
106
try
{
107
parser.setDocumentHandler(&handler);
108
parser.setErrorHandler(&handler);
109
parser.parse(path.c_str());
110
if
(handler.
errorOccured
()) {
111
throw
ProcessError
(
"Could not load configuration '"
+ path +
"'."
);
112
}
113
}
catch
(
const
XMLException& e) {
114
throw
ProcessError
(
"Could not load configuration '"
+ path +
"':\n "
+
TplConvert<XMLCh>::_2str
(e.getMessage()));
115
}
116
oc.
relocateFiles
(path);
117
PROGRESS_DONE_MESSAGE
();
118
}
119
120
121
122
/****************************************************************************/
123
build
buildd
sumo-0.15.0~dfsg
src
utils
options
OptionsIO.cpp
Generated on Wed Jul 18 2012 22:58:35 for SUMO - Simulation of Urban MObility by
1.8.1.1