generate-shapes/src/pfaedle/trgraph/NodePL.cpp

164 lines
4.5 KiB
C++
Raw Normal View History

2018-06-09 17:14:08 +02:00
// Copyright 2018, University of Freiburg,
// Chair of Algorithms and Data Structures.
// Authors: Patrick Brosi <brosi@informatik.uni-freiburg.de>
#include <string>
#include <unordered_map>
#include "pfaedle/trgraph/NodePL.h"
#include "pfaedle/trgraph/StatGroup.h"
#include "pfaedle/trgraph/StatInfo.h"
#include "util/String.h"
using pfaedle::trgraph::StatInfo;
using pfaedle::trgraph::NodePL;
using pfaedle::trgraph::Component;
// we use the adress of this dummy station info as a special value
// of this node, meaning "is a station block". Re-using the _si field here
// saves some memory
StatInfo NodePL::_blockerSI = StatInfo();
std::unordered_map<const Component*, size_t> NodePL::_comps;
// _____________________________________________________________________________
2018-07-24 19:33:18 +02:00
NodePL::NodePL()
: _geom(0, 0),
_si(0),
_component(0)
#ifdef PFAEDLE_DBG
,
_vis(0)
#endif
{
}
2018-06-09 17:14:08 +02:00
// _____________________________________________________________________________
NodePL::NodePL(const NodePL& pl)
2018-07-24 19:33:18 +02:00
: _geom(pl._geom),
_si(0),
_component(pl._component)
#ifdef PFAEDLE_DBG
,
_vis(pl._vis)
#endif
{
2018-06-09 17:14:08 +02:00
if (pl._si) setSI(*(pl._si));
}
// _____________________________________________________________________________
NodePL::NodePL(const util::geo::FPoint& geom)
2018-07-24 19:33:18 +02:00
: _geom(geom),
_si(0),
_component(0)
#ifdef PFAEDLE_DBG
,
_vis(0)
#endif
{
}
2018-06-09 17:14:08 +02:00
// _____________________________________________________________________________
NodePL::NodePL(const util::geo::FPoint& geom, const StatInfo& si)
2018-07-24 19:33:18 +02:00
: _geom(geom),
_si(0),
_component(0)
#ifdef PFAEDLE_DBG
,
_vis(0)
#endif
{
2018-06-09 17:14:08 +02:00
setSI(si);
}
// _____________________________________________________________________________
NodePL::~NodePL() {
if (getSI()) delete _si;
if (_component) {
_comps[_component]--;
if (_comps[_component] == 0) {
delete _component;
_comps.erase(_comps.find(_component));
}
}
}
// _____________________________________________________________________________
2018-07-24 19:33:18 +02:00
void NodePL::setVisited() const {
#ifdef PFAEDLE_DBG
_vis = true;
#endif
}
2018-06-09 17:14:08 +02:00
// _____________________________________________________________________________
void NodePL::setNoStat() { _si = 0; }
// _____________________________________________________________________________
const Component* NodePL::getComp() const { return _component; }
// _____________________________________________________________________________
void NodePL::setComp(const Component* c) {
if (_component == c) return;
_component = c;
// NOT thread safe!
if (!_comps.count(c))
_comps[c] = 1;
else
_comps[c]++;
}
// _____________________________________________________________________________
const util::geo::FPoint* NodePL::getGeom() const { return &_geom; }
// _____________________________________________________________________________
void NodePL::setGeom(const util::geo::FPoint& geom) { _geom = geom; }
// _____________________________________________________________________________
2018-08-01 14:25:54 +02:00
util::json::Dict NodePL::getAttrs() const {
util::json::Dict obj;
obj["component"] = std::to_string(reinterpret_cast<size_t>(_component));
2018-07-24 19:33:18 +02:00
#ifdef PFAEDLE_DBG
2018-08-01 14:25:54 +02:00
obj["dijkstra_vis"] = _vis ? "yes" : "no";
2018-07-24 19:33:18 +02:00
#endif
2018-06-09 17:14:08 +02:00
if (getSI()) {
2018-08-01 14:25:54 +02:00
obj["station_info_ptr"] = util::toString(_si);
obj["station_name"] = _si->getName();
obj["station_alt_names"] = util::implode(_si->getAltNames(), ",");
obj["from_osm"] = _si->isFromOsm() ? "yes" : "no";
obj["station_platform"] = _si->getTrack();
obj["station_group"] =
2018-06-09 17:14:08 +02:00
std::to_string(reinterpret_cast<size_t>(_si->getGroup()));
std::stringstream gtfsIds;
if (_si->getGroup()) {
for (auto* s : _si->getGroup()->getStops()) {
gtfsIds << s->getId() << " (" << s->getName() << "),";
}
}
2018-08-01 14:25:54 +02:00
obj["station_group_stops"] = gtfsIds.str();
2018-06-09 17:14:08 +02:00
}
2018-08-01 14:25:54 +02:00
return obj;
2018-06-09 17:14:08 +02:00
}
// _____________________________________________________________________________
void NodePL::setSI(const StatInfo& si) { _si = new StatInfo(si); }
// _____________________________________________________________________________
const StatInfo* NodePL::getSI() const {
if (isBlocker()) return 0;
return _si;
}
// _____________________________________________________________________________
StatInfo* NodePL::getSI() {
if (isBlocker()) return 0;
return _si;
}
// _____________________________________________________________________________
void NodePL::setBlocker() { _si = &_blockerSI; }
// _____________________________________________________________________________
bool NodePL::isBlocker() const { return _si == &_blockerSI; }