// Copyright 2018, University of Freiburg, // Chair of Algorithms and Data Structures. // Authors: Patrick Brosi #include #include #include #include "pfaedle/trgraph/EdgePL.h" #include "util/geo/Geo.h" using pfaedle::trgraph::EdgePL; using pfaedle::trgraph::TransitEdgeLine; std::map EdgePL::_flines; std::map EdgePL::_tlines; // _____________________________________________________________________________ EdgePL::EdgePL() : _length(0), _oneWay(0), _hasRestr(false), _rev(false), _lvl(0) { _l = new LINE(); _flines[_l] = 1; } // _____________________________________________________________________________ EdgePL::EdgePL(const EdgePL& pl) : EdgePL(pl, false) {} // _____________________________________________________________________________ EdgePL::EdgePL(const EdgePL& pl, bool geoflat) : _length(pl._length), _oneWay(pl._oneWay), _hasRestr(pl._hasRestr), _rev(pl._rev), _lvl(pl._lvl) { if (geoflat) { _l = pl._l; } else { _l = new LINE(*pl._l); } _flines[_l]++; for (auto l : pl._lines) addLine(l); } // _____________________________________________________________________________ EdgePL::~EdgePL() { if (_l) { _flines[_l]--; if (_flines[_l] == 0) delete _l; } for (auto l : _lines) unRefTLine(l); } // _____________________________________________________________________________ void EdgePL::unRefTLine(const TransitEdgeLine* l) { if (l) { _tlines[l]--; if (_tlines[l] == 0) { delete l; _tlines.erase(_tlines.find(l)); } } } // _____________________________________________________________________________ EdgePL EdgePL::revCopy() const { EdgePL ret(*this); ret.setRev(); if (ret.oneWay() == 1) ret.setOneWay(2); else if (ret.oneWay() == 2) ret.setOneWay(1); return ret; } // _____________________________________________________________________________ void EdgePL::setLength(double d) { _length = d; } // _____________________________________________________________________________ double EdgePL::getLength() const { return _length; } // _____________________________________________________________________________ void EdgePL::addLine(const TransitEdgeLine* l) { if (std::find(_lines.begin(), _lines.end(), l) == _lines.end()) { _lines.reserve(_lines.size() + 1); _lines.push_back(l); if (_tlines.count(l)) _tlines[l]++; else _tlines[l] = 1; } } // _____________________________________________________________________________ void EdgePL::addLines(const std::vector& l) { for (auto line : l) addLine(line); } // _____________________________________________________________________________ const std::vector& EdgePL::getLines() const { return _lines; } // _____________________________________________________________________________ void EdgePL::addPoint(const POINT& p) { _l->push_back(p); } // _____________________________________________________________________________ const LINE* EdgePL::getGeom() const { return _l; } // _____________________________________________________________________________ LINE* EdgePL::getGeom() { return _l; } // _____________________________________________________________________________ util::json::Dict EdgePL::getAttrs() const { util::json::Dict obj; obj["m_length"] = std::to_string(_length); obj["oneway"] = std::to_string(static_cast(_oneWay)); obj["level"] = std::to_string(_lvl); obj["restriction"] = isRestricted() ? "yes" : "no"; std::stringstream ss; bool first = false; for (auto* l : _lines) { if (first) ss << ","; ss << l->shortName; if (l->fromStr.size() || l->toStr.size()) { ss << "(" << l->fromStr; ss << "->" << l->toStr << ")"; } first = true; } obj["lines"] = ss.str(); return obj; } // _____________________________________________________________________________ void EdgePL::setRestricted() { _hasRestr = true; } // _____________________________________________________________________________ bool EdgePL::isRestricted() const { return _hasRestr; } // _____________________________________________________________________________ uint8_t EdgePL::oneWay() const { return _oneWay; } // _____________________________________________________________________________ void EdgePL::setOneWay(uint8_t dir) { _oneWay = dir; } // _____________________________________________________________________________ void EdgePL::setOneWay() { _oneWay = 1; } // _____________________________________________________________________________ void EdgePL::setLvl(uint8_t lvl) { _lvl = lvl; } // _____________________________________________________________________________ uint8_t EdgePL::lvl() const { return _lvl; } // _____________________________________________________________________________ void EdgePL::setRev() { _rev = true; } // _____________________________________________________________________________ bool EdgePL::isRev() const { return _rev; } // _____________________________________________________________________________ const POINT& EdgePL::backHop() const { if (isRev()) { return *(++(getGeom()->cbegin())); } return *(++(getGeom()->crbegin())); } // _____________________________________________________________________________ const POINT& EdgePL::frontHop() const { if (isRev()) { return *(++(getGeom()->crbegin())); } return *(++(getGeom()->cbegin())); }