Skip to content

Commit

Permalink
Updated GNEHierarchicalStructure. Refs #16039
Browse files Browse the repository at this point in the history
  • Loading branch information
palvarezlopez committed Jan 22, 2025
1 parent e54cbe3 commit 780badc
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 18 deletions.
18 changes: 16 additions & 2 deletions src/netedit/elements/GNEAttributeCarrier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,9 @@ GNEAttributeCarrier::parse(const std::string& value) {
template<> std::vector<GNEEdge*>
GNEAttributeCarrier::parse(GNENet* net, const std::string& value) {
// Declare string vector
std::vector<std::string> edgeIds = GNEAttributeCarrier::parse<std::vector<std::string> > (value);
const auto edgeIds = GNEAttributeCarrier::parse<std::vector<std::string> > (value);
std::vector<GNEEdge*> parsedEdges;
parsedEdges.reserve(edgeIds.size());
// Iterate over edges IDs, retrieve Edges and add it into parsedEdges
for (const auto& edgeID : edgeIds) {
GNEEdge* retrievedEdge = net->getAttributeCarriers()->retrieveEdge(edgeID, false);
Expand All @@ -401,11 +402,18 @@ GNEAttributeCarrier::parse(GNENet* net, const std::string& value) {
}


template<> GNEHierarchicalContainerChildren<GNEEdge*>
GNEAttributeCarrier::parse(GNENet* net, const std::string& value) {
return GNEHierarchicalContainerChildren<GNEEdge*>(parse<std::vector<GNEEdge*> >(net, value));
}


template<> std::vector<GNELane*>
GNEAttributeCarrier::parse(GNENet* net, const std::string& value) {
// Declare string vector
std::vector<std::string> laneIds = GNEAttributeCarrier::parse<std::vector<std::string> > (value);
const auto laneIds = GNEAttributeCarrier::parse<std::vector<std::string> > (value);
std::vector<GNELane*> parsedLanes;
parsedLanes.reserve(laneIds.size());
// Iterate over lanes IDs, retrieve Lanes and add it into parsedLanes
for (const auto& laneID : laneIds) {
GNELane* retrievedLane = net->getAttributeCarriers()->retrieveLane(laneID, false);
Expand All @@ -420,6 +428,12 @@ GNEAttributeCarrier::parse(GNENet* net, const std::string& value) {
}


template<> GNEHierarchicalContainerChildren<GNELane*>
GNEAttributeCarrier::parse(GNENet* net, const std::string& value) {
return GNEHierarchicalContainerChildren<GNELane*>(parse<std::vector<GNELane*> >(net, value));
}


template<> std::string
GNEAttributeCarrier::parseIDs(const std::vector<GNEEdge*>& ACs) {
// obtain ID's of edges and return their join
Expand Down
8 changes: 4 additions & 4 deletions src/netedit/elements/GNEHierarchicalContainerChildrenHash.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@
#pragma once
#include <config.h>

#include <unordered_set>
#include <set>

// ===========================================================================
// class definitions
// ===========================================================================

template <typename T>
class GNEHierarchicalContainerChildrenHash : public std::unordered_set<T> {
class GNEHierarchicalContainerChildrenHash : public std::set<T> {

public:
/// @brief default constructor
GNEHierarchicalContainerChildrenHash() {
}

/// @brief parameter constructor
GNEHierarchicalContainerChildrenHash(const std::unordered_set<T>& elements) :
std::unordered_set<T>(elements) {
GNEHierarchicalContainerChildrenHash(const std::set<T>& elements) :
std::set<T>(elements) {
}
};
2 changes: 1 addition & 1 deletion src/netedit/elements/GNEHierarchicalElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class GNEHierarchicalElement : public GNEAttributeCarrier {

/// @brief replace children in the given edited element
template<typename T, typename U>
void replaceChildElements(T* editedElement, const std::vector<U>& newChildren) {
void replaceChildElements(T* editedElement, const GNEHierarchicalContainerChildren<U>& newChildren) {
// remove edited elements from children
for (const auto& child : myHierarchicalStructure.getChildren<U>()) {
child->removeChildElement(editedElement);
Expand Down
14 changes: 7 additions & 7 deletions src/netedit/elements/GNEHierarchicalStructure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,43 +437,43 @@ GNEHierarchicalStructure::getChildren() const {


template<> void
GNEHierarchicalStructure::setChildren(const std::vector<GNEJunction*>& newChildren) {
GNEHierarchicalStructure::setChildren(const GNEHierarchicalContainerChildren<GNEJunction*>& newChildren) {
myChildJunctions = newChildren;
}


template<> void
GNEHierarchicalStructure::setChildren(const std::vector<GNEEdge*>& newChildren) {
GNEHierarchicalStructure::setChildren(const GNEHierarchicalContainerChildren<GNEEdge*>& newChildren) {
myChildEdges = newChildren;
}


template<> void
GNEHierarchicalStructure::setChildren(const std::vector<GNELane*>& newChildren) {
GNEHierarchicalStructure::setChildren(const GNEHierarchicalContainerChildren<GNELane*>& newChildren) {
myChildLanes = newChildren;
}


template<> void
GNEHierarchicalStructure::setChildren(const std::vector<GNEAdditional*>& newChildren) {
GNEHierarchicalStructure::setChildren(const GNEHierarchicalContainerChildren<GNEAdditional*>& newChildren) {
myChildAdditionals = newChildren;
}


template<> void
GNEHierarchicalStructure::setChildrenHash(const std::unordered_set<GNETAZSourceSink*>& newChildren) {
GNEHierarchicalStructure::setChildrenHash(const GNEHierarchicalContainerChildrenHash<GNETAZSourceSink*>& newChildren) {
myChildSourceSinks = newChildren;
}


template<> void
GNEHierarchicalStructure::setChildren(const std::vector<GNEDemandElement*>& newChildren) {
GNEHierarchicalStructure::setChildren(const GNEHierarchicalContainerChildren<GNEDemandElement*>& newChildren) {
myChildDemandElements = newChildren;
}


template<> void
GNEHierarchicalStructure::setChildren(const std::vector<GNEGenericData*>& newChildren) {
GNEHierarchicalStructure::setChildren(const GNEHierarchicalContainerChildren<GNEGenericData*>& newChildren) {
myChildGenericDatas = newChildren;
}

Expand Down
4 changes: 2 additions & 2 deletions src/netedit/elements/GNEHierarchicalStructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ class GNEHierarchicalStructure {

/// @brief set children
template<typename T>
void setChildren(const std::vector<T>& newChildren);
void setChildren(const GNEHierarchicalContainerChildren<T>& newChildren);

/// @brief set children hash
template<typename T>
void setChildrenHash(const std::unordered_set<T>& newChildren);
void setChildrenHash(const GNEHierarchicalContainerChildrenHash<T>& newChildren);

private:
/// @brief parents junctions
Expand Down
4 changes: 2 additions & 2 deletions src/netedit/elements/additional/GNEAdditional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,13 +664,13 @@ GNEAdditional::replaceAdditionalParentLanes(const std::string& value) {

void
GNEAdditional::replaceAdditionalChildEdges(const std::string& value) {
replaceChildElements(this, parse<std::vector<GNEEdge*> >(getNet(), value));
replaceChildElements(this, parse<GNEHierarchicalContainerChildren<GNEEdge*> >(getNet(), value));
}


void
GNEAdditional::replaceAdditionalChildLanes(const std::string& value) {
replaceChildElements(this, parse<std::vector<GNELane*> >(getNet(), value));
replaceChildElements(this, parse<GNEHierarchicalContainerChildren<GNELane*> >(getNet(), value));
}


Expand Down

0 comments on commit 780badc

Please sign in to comment.