Eclipse SUMO - Simulation of Urban MObility
SUMOSAXAttributesImpl_Cached.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2007-2022 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/****************************************************************************/
18// Encapsulated xml-attributes that use a map from string-attr-names to string-attr-values as backend
19/****************************************************************************/
20#pragma once
21#include <config.h>
22
23#include <string>
24#include <map>
25#include <iostream>
26#include <xercesc/sax2/Attributes.hpp>
30#include "SUMOSAXAttributes.h"
31
32
33// ===========================================================================
34// class definitions
35// ===========================================================================
43public:
50 SUMOSAXAttributesImpl_Cached(const std::map<std::string, std::string>& attrs,
51 const std::vector<std::string>& predefinedTagsMML,
52 const std::string& objectType);
53
56
59
65 bool hasAttribute(int id) const;
66
79 std::string getString(int id, bool* isPresent = nullptr) const;
80
93 std::string getStringSecure(int id, const std::string& def) const;
94
96 bool hasAttribute(const std::string& id) const;
97
113 double getFloat(const std::string& id) const;
114
124 std::string getStringSecure(const std::string& id,
125 const std::string& def) const;
127
135 std::string getName(int attr) const;
136
141 void serialize(std::ostream& os) const;
142
145 std::vector<std::string> getAttributeNames() const;
146
148 SUMOSAXAttributes* clone() const;
149
150private:
157 const std::string& getAttributeValueSecure(int id) const;
158
159private:
161 std::map<std::string, std::string> myAttrs;
162
164 const std::vector<std::string>& myPredefinedTagsMML;
165
166private:
169
172};
Encapsulated SAX-Attributes.
Encapsulated Xerces-SAX-attributes.
std::string getName(int attr) const
Converts the given attribute id into a man readable string.
SUMOSAXAttributesImpl_Cached & operator=(const SUMOSAXAttributesImpl_Cached &src)=delete
Invalidated assignment operator.
std::string getStringSecure(int id, const std::string &def) const
Returns the string-value of the named (by its enum-value) attribute.
std::map< std::string, std::string > myAttrs
The encapsulated attributes.
double getFloat(const std::string &id) const
Returns the double-value of the named attribute.
SUMOSAXAttributesImpl_Cached(const std::map< std::string, std::string > &attrs, const std::vector< std::string > &predefinedTagsMML, const std::string &objectType)
Constructor.
SUMOSAXAttributesImpl_Cached(const SUMOSAXAttributesImpl_Cached &src)=delete
Invalidated copy constructor.
const std::string & getAttributeValueSecure(int id) const
Returns Xerces-value of the named attribute.
void serialize(std::ostream &os) const
Prints all attribute names and values into the given stream.
std::vector< std::string > getAttributeNames() const
Retrieves all attribute names.
std::string getString(int id, bool *isPresent=nullptr) const
Returns the string-value of the named (by its enum-value) attribute.
SUMOSAXAttributes * clone() const
return a new deep-copy attributes object
const std::vector< std::string > & myPredefinedTagsMML
Map of attribute ids to their (readable) string-representation.
bool hasAttribute(int id) const
Returns the information whether the named (by its enum-value) attribute is within the current list.