/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file IDSupplier.cpp14/// @author Daniel Krajzewicz15/// @author Jakob Erdmann16/// @author Michael Behrisch17/// @date Sept 200218///19// A class that generates enumerated and prefixed string-ids20/****************************************************************************/21#include <config.h>2223#include <string>24#include <sstream>25#include <iostream>26#include "StdDefs.h"27#include "IDSupplier.h"282930// ===========================================================================31// method definitions32// ===========================================================================33IDSupplier::IDSupplier(const std::string& prefix, long long int begin)34: myCurrent(begin), myPrefix(prefix) {}35363738IDSupplier::IDSupplier(const std::string& prefix, const std::vector<std::string>& knownIDs)39: myCurrent(0), myPrefix(prefix) {40for (std::vector<std::string>::const_iterator id_it = knownIDs.begin(); id_it != knownIDs.end(); ++id_it) {41avoid(*id_it);42}43}444546IDSupplier::~IDSupplier() {}474849std::string50IDSupplier::getNext() {51std::ostringstream strm;52strm << myPrefix << myCurrent++;53return strm.str();54}555657void58IDSupplier::avoid(const std::string& id) {59// does it start with prefix?60if (id.find(myPrefix) == 0) {61long long int number;62std::istringstream buf(id.substr(myPrefix.size()));63buf >> number;64// does it continue with a number?65if (!buf.fail()) {66myCurrent = MAX2(myCurrent, number + 1);67}68}69}707172/****************************************************************************/737475