Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/handlers/TemplateHandler.h
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4
// This program and the accompanying materials are made available under the
5
// terms of the Eclipse Public License 2.0 which is available at
6
// https://www.eclipse.org/legal/epl-2.0/
7
// This Source Code may also be made available under the following Secondary
8
// Licenses when the conditions for such availability set forth in the Eclipse
9
// Public License 2.0 are satisfied: GNU General Public License, version 2
10
// or later which is available at
11
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
/****************************************************************************/
14
/// @file TemplateHandler.h
15
/// @author Pablo Alvarez Lopez
16
/// @date Dec 2022
17
///
18
// A SAX-Handler for loading templates
19
/****************************************************************************/
20
#pragma once
21
#include <config.h>
22
23
#include <xercesc/sax/HandlerBase.hpp>
24
#include <xercesc/sax/AttributeList.hpp>
25
#include <xercesc/sax/SAXParseException.hpp>
26
#include <xercesc/sax/SAXException.hpp>
27
#include <string>
28
29
30
// ===========================================================================
31
// class declarations
32
// ===========================================================================
33
34
class OptionsCont;
35
36
// ===========================================================================
37
// class definitions
38
// ===========================================================================
39
/**
40
* @class TemplateHandler
41
* @brief A SAX-Handler for loading options
42
*/
43
class TemplateHandler : public XERCES_CPP_NAMESPACE::HandlerBase {
44
45
public:
46
/// @brief run parser
47
static void parseTemplate(OptionsCont& options, const std::string& templateString);
48
49
private:
50
/// @brief Constructor
51
TemplateHandler(OptionsCont& options);
52
53
/// @brief destructor
54
~TemplateHandler();
55
56
/// @name Handlers for the SAX DocumentHandler interface
57
/// @{
58
59
/** @brief Called on the occurrence of the beginning of a tag
60
*
61
* Sets the name of the last item
62
*/
63
void startElement(const XMLCh* const name, XERCES_CPP_NAMESPACE::AttributeList& attributes);
64
65
/// @brief add option
66
bool addOption(std::string value, const std::string& synonymes, const std::string& type,
67
const std::string& help, bool required, bool positional, const std::string& listSep) const;
68
69
/** @brief Called on the end of an element
70
*
71
* Resets the element name
72
*/
73
void endElement(const XMLCh* const name);
74
75
/// @}
76
77
/// @name Handlers for the SAX ErrorHandler interface
78
/// @{
79
80
/** @brief Called on an XML-warning
81
*
82
* The warning is reported to the warning-instance of MsgHandler
83
*/
84
void warning(const XERCES_CPP_NAMESPACE::SAXParseException& exception);
85
86
/** @brief Called on an XML-error
87
*
88
* The warning is reported to the error-instance of MsgHandler
89
*/
90
void error(const XERCES_CPP_NAMESPACE::SAXParseException& exception);
91
92
/** @brief Called on an XML-fatal error
93
*
94
* The warning is reported to the error-instance of MsgHandler
95
*/
96
void fatalError(const XERCES_CPP_NAMESPACE::SAXParseException& exception);
97
98
/// @}
99
100
/// @brief The information whether an error occurred
101
bool myError;
102
103
/// @brief The nesting level of parsed elements
104
int myLevel;
105
106
/// @brief The options to fill
107
OptionsCont& myOptions;
108
109
/// @brief The name of the current option
110
std::string myOptionName;
111
112
/// @brief current subtopic
113
std::string mySubTopic;
114
115
/// @brief invalid int in string format
116
static const std::string INVALID_INT_STR;
117
118
/// @brief invalid double in string format
119
static const std::string INVALID_DOUBLE_STR;
120
121
/// @brief invalidate default onstructor
122
TemplateHandler() = delete;
123
124
/// @brief invalid copy constructor
125
TemplateHandler(const TemplateHandler& s) = delete;
126
127
/// @brief invalid assignment operator
128
TemplateHandler& operator=(const TemplateHandler& s) = delete;
129
};
130
131