LCOV - code coverage report
Current view: top level - src/utils/iodevices - PlainXMLFormatter.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 42 42
Test Date: 2024-11-22 15:46:21 Functions: 100.0 % 8 8

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2012-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    PlainXMLFormatter.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Michael Behrisch
      17              : /// @date    2012
      18              : ///
      19              : // Static storage of an output device and its base (abstract) implementation
      20              : /****************************************************************************/
      21              : #include <config.h>
      22              : 
      23              : #include <utils/common/ToString.h>
      24              : #include <utils/options/OptionsCont.h>
      25              : #include "PlainXMLFormatter.h"
      26              : 
      27              : 
      28              : // ===========================================================================
      29              : // member method definitions
      30              : // ===========================================================================
      31      1488202 : PlainXMLFormatter::PlainXMLFormatter(const int defaultIndentation)
      32      1488202 :     : myDefaultIndentation(defaultIndentation), myHavePendingOpener(false) {
      33      1488202 : }
      34              : 
      35              : 
      36              : bool
      37        12466 : PlainXMLFormatter::writeHeader(std::ostream& into, const SumoXMLTag& rootElement) {
      38        12466 :     if (myXMLStack.empty()) {
      39        12466 :         OptionsCont::getOptions().writeXMLHeader(into);
      40        12466 :         openTag(into, rootElement);
      41        12466 :         return true;
      42              :     }
      43              :     return false;
      44              : }
      45              : 
      46              : 
      47              : bool
      48        61536 : PlainXMLFormatter::writeXMLHeader(std::ostream& into, const std::string& rootElement,
      49              :                                   const std::map<SumoXMLAttr, std::string>& attrs, bool includeConfig) {
      50        61536 :     if (myXMLStack.empty()) {
      51        53147 :         OptionsCont::getOptions().writeXMLHeader(into, includeConfig);
      52        53147 :         openTag(into, rootElement);
      53       157795 :         for (std::map<SumoXMLAttr, std::string>::const_iterator it = attrs.begin(); it != attrs.end(); ++it) {
      54       104648 :             writeAttr(into, it->first, it->second);
      55              :         }
      56        53147 :         into << ">\n";
      57        53147 :         myHavePendingOpener = false;
      58        53147 :         return true;
      59              :     }
      60              :     return false;
      61              : }
      62              : 
      63              : 
      64              : void
      65     13388322 : PlainXMLFormatter::openTag(std::ostream& into, const std::string& xmlElement) {
      66     13388322 :     if (myHavePendingOpener) {
      67      2887938 :         into << ">\n";
      68              :     }
      69     13388322 :     myHavePendingOpener = true;
      70     13388322 :     into << std::string(4 * (myXMLStack.size() + myDefaultIndentation), ' ') << "<" << xmlElement;
      71     13388322 :     myXMLStack.push_back(xmlElement);
      72     13388322 : }
      73              : 
      74              : 
      75              : void
      76      5741509 : PlainXMLFormatter::openTag(std::ostream& into, const SumoXMLTag& xmlElement) {
      77      5741509 :     openTag(into, toString(xmlElement));
      78      5741509 : }
      79              : 
      80              : 
      81              : bool
      82     13665671 : PlainXMLFormatter::closeTag(std::ostream& into, const std::string& comment) {
      83     13665671 :     if (!myXMLStack.empty()) {
      84     13388301 :         if (myHavePendingOpener) {
      85     10447149 :             into << "/>" << comment << "\n";
      86     10447149 :             myHavePendingOpener = false;
      87              :         } else {
      88      2941152 :             const std::string indent(4 * (myXMLStack.size() + myDefaultIndentation - 1), ' ');
      89      2941152 :             into << indent << "</" << myXMLStack.back() << ">" << comment << "\n";
      90              :         }
      91              :         myXMLStack.pop_back();
      92     13388301 :         return true;
      93              :     }
      94              :     return false;
      95              : }
      96              : 
      97              : 
      98              : void
      99         1106 : PlainXMLFormatter::writePreformattedTag(std::ostream& into, const std::string& val) {
     100         1106 :     if (myHavePendingOpener) {
     101           80 :         into << ">\n";
     102           80 :         myHavePendingOpener = false;
     103              :     }
     104              :     into << val;
     105         1106 : }
     106              : 
     107              : void
     108        53719 : PlainXMLFormatter::writePadding(std::ostream& into, const std::string& val) {
     109              :     into << val;
     110        53719 : }
     111              : 
     112              : 
     113              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1