LCOV - code coverage report
Current view: top level - src/utils/common - IDSupplier.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 90.0 % 20 18
Test Date: 2024-11-22 15:46:21 Functions: 80.0 % 5 4

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-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    IDSupplier.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Jakob Erdmann
      17              : /// @author  Michael Behrisch
      18              : /// @date    Sept 2002
      19              : ///
      20              : // A class that generates enumerated and prefixed string-ids
      21              : /****************************************************************************/
      22              : #include <config.h>
      23              : 
      24              : #include <string>
      25              : #include <sstream>
      26              : #include <iostream>
      27              : #include "StdDefs.h"
      28              : #include "IDSupplier.h"
      29              : 
      30              : 
      31              : // ===========================================================================
      32              : // method definitions
      33              : // ===========================================================================
      34            0 : IDSupplier::IDSupplier(const std::string& prefix, long long int begin)
      35            0 :     : myCurrent(begin), myPrefix(prefix) {}
      36              : 
      37              : 
      38              : 
      39           84 : IDSupplier::IDSupplier(const std::string& prefix, const std::vector<std::string>& knownIDs)
      40           84 :     : myCurrent(0), myPrefix(prefix) {
      41        26048 :     for (std::vector<std::string>::const_iterator id_it = knownIDs.begin(); id_it != knownIDs.end(); ++id_it) {
      42        25964 :         avoid(*id_it);
      43              :     }
      44           84 : }
      45              : 
      46              : 
      47           84 : IDSupplier::~IDSupplier() {}
      48              : 
      49              : 
      50              : std::string
      51         6280 : IDSupplier::getNext() {
      52         6280 :     std::ostringstream strm;
      53         6280 :     strm << myPrefix << myCurrent++;
      54         6280 :     return strm.str();
      55         6280 : }
      56              : 
      57              : 
      58              : void
      59        25964 : IDSupplier::avoid(const std::string& id) {
      60              :     // does it start with prefix?
      61        25964 :     if (id.find(myPrefix) == 0) {
      62              :         long long int number;
      63        51928 :         std::istringstream buf(id.substr(myPrefix.size()));
      64              :         buf >> number;
      65              :         // does it continue with a number?
      66        25964 :         if (!buf.fail()) {
      67        25480 :             myCurrent = MAX2(myCurrent, number + 1);
      68              :         }
      69        25964 :     }
      70        25964 : }
      71              : 
      72              : 
      73              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1