LCOV - code coverage report
Current view: top level - src/utils/xml - SUMOSAXAttributesImpl_Cached.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 25.7 % 35 9
Test Date: 2024-11-20 15:55:46 Functions: 35.7 % 14 5

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2002-2024 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    SUMOSAXAttributesImpl_Cached.cpp
      15              : /// @author  Jakob Erdmann
      16              : /// @date    Dec 2016
      17              : ///
      18              : // Encapsulated xml-attributes that use a map from string-attr-names to string-attr-values as backend
      19              : /****************************************************************************/
      20              : #include <config.h>
      21              : 
      22              : #include <cassert>
      23              : #include <xercesc/sax2/Attributes.hpp>
      24              : #include <xercesc/sax2/DefaultHandler.hpp>
      25              : #include <xercesc/util/XercesVersion.hpp>
      26              : #include <xercesc/util/TransService.hpp>
      27              : #include <xercesc/util/TranscodingException.hpp>
      28              : #include <utils/common/RGBColor.h>
      29              : #include <utils/common/StringTokenizer.h>
      30              : #include <utils/common/StringUtils.h>
      31              : #include <utils/common/StringBijection.h>
      32              : #include <utils/geom/Boundary.h>
      33              : #include <utils/geom/PositionVector.h>
      34              : #include "SUMOSAXAttributesImpl_Cached.h"
      35              : #include "SUMOSAXAttributesImpl_Cached.h"
      36              : 
      37              : 
      38              : // ===========================================================================
      39              : // class definitions
      40              : // ===========================================================================
      41        10228 : SUMOSAXAttributesImpl_Cached::SUMOSAXAttributesImpl_Cached(
      42              :     const std::map<std::string, std::string>& attrs,
      43              :     const std::vector<std::string>& predefinedTagsMML,
      44        10228 :     const std::string& objectType) :
      45              :     SUMOSAXAttributes(objectType),
      46              :     myAttrs(attrs),
      47        10228 :     myPredefinedTagsMML(predefinedTagsMML) { }
      48              : 
      49              : 
      50        20456 : SUMOSAXAttributesImpl_Cached::~SUMOSAXAttributesImpl_Cached() { }
      51              : 
      52              : 
      53              : bool
      54         8321 : SUMOSAXAttributesImpl_Cached::hasAttribute(int id) const {
      55              :     assert(id >= 0);
      56              :     assert(id < (int)myPredefinedTagsMML.size());
      57         8321 :     return myAttrs.find(myPredefinedTagsMML[id]) != myAttrs.end();
      58              : }
      59              : 
      60              : 
      61              : std::string
      62        45041 : SUMOSAXAttributesImpl_Cached::getString(int id, bool* isPresent) const {
      63        45041 :     const auto it = myAttrs.find(myPredefinedTagsMML[id]);
      64        45041 :     if (it != myAttrs.end()) {
      65              :         return it->second;
      66              :     }
      67            0 :     *isPresent = false;
      68            0 :     return "";
      69              : }
      70              : 
      71              : 
      72              : std::string
      73            0 : SUMOSAXAttributesImpl_Cached::getStringSecure(int id, const std::string& str) const {
      74            0 :     const std::string& result = getAttributeValueSecure(id);
      75            0 :     return result.size() == 0 ? str : result;
      76              : }
      77              : 
      78              : 
      79              : const std::string&
      80            0 : SUMOSAXAttributesImpl_Cached::getAttributeValueSecure(int id) const {
      81              :     assert(id >= 0);
      82              :     assert(id < (int)myPredefinedTagsMML.size());
      83            0 :     return myAttrs.find(myPredefinedTagsMML[id])->second;
      84              : }
      85              : 
      86              : 
      87              : double
      88            0 : SUMOSAXAttributesImpl_Cached::getFloat(const std::string& id) const {
      89            0 :     return StringUtils::toDouble(myAttrs.find(id)->second);
      90              : }
      91              : 
      92              : 
      93              : bool
      94            0 : SUMOSAXAttributesImpl_Cached::hasAttribute(const std::string& id) const {
      95            0 :     return myAttrs.find(id) != myAttrs.end();
      96              : }
      97              : 
      98              : 
      99              : std::string
     100            0 : SUMOSAXAttributesImpl_Cached::getStringSecure(const std::string& id,
     101              :         const std::string& str) const {
     102              :     std::map<std::string, std::string>::const_iterator it = myAttrs.find(id);
     103            0 :     if (it != myAttrs.end() && it->second != "") {
     104              :         return it->second;
     105              :     } else {
     106              :         return str;
     107              :     }
     108              : }
     109              : 
     110              : 
     111              : std::string
     112            0 : SUMOSAXAttributesImpl_Cached::getName(int attr) const {
     113              :     assert(attr >= 0);
     114              :     assert(attr < (int)myPredefinedTagsMML.size());
     115            0 :     return myPredefinedTagsMML[attr];
     116              : }
     117              : 
     118              : 
     119              : void
     120            0 : SUMOSAXAttributesImpl_Cached::serialize(std::ostream& os) const {
     121            0 :     for (std::map<std::string, std::string>::const_iterator it = myAttrs.begin(); it != myAttrs.end(); ++it) {
     122              :         os << " " << it->first;
     123            0 :         os << "=\"" << it->second << "\"";
     124              :     }
     125            0 : }
     126              : 
     127              : std::vector<std::string>
     128            0 : SUMOSAXAttributesImpl_Cached::getAttributeNames() const {
     129              :     std::vector<std::string> result;
     130            0 :     for (std::map<std::string, std::string>::const_iterator it = myAttrs.begin(); it != myAttrs.end(); ++it) {
     131            0 :         result.push_back(it->first);
     132              :     }
     133            0 :     return result;
     134            0 : }
     135              : 
     136              : SUMOSAXAttributes*
     137            0 : SUMOSAXAttributesImpl_Cached::clone() const {
     138            0 :     return new SUMOSAXAttributesImpl_Cached(myAttrs, myPredefinedTagsMML, getObjectType());
     139              : }
     140              : 
     141              : 
     142              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1