Skip to content

Commit

Permalink
Spitted GNEHierarchicalContainer in GNEHierarchicalContainerParents a…
Browse files Browse the repository at this point in the history
…nd GNEHierarchicalContainerChildren. Refs #16039
  • Loading branch information
palvarezlopez committed Jan 21, 2025
1 parent 6f4c907 commit d580862
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 80 deletions.
3 changes: 2 additions & 1 deletion src/netedit/elements/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ set(netedit_elements_SRCS
GNEContour.h
GNEGeneralHandler.cpp
GNEGeneralHandler.h
GNEHierarchicalContainer.h
GNEHierarchicalContainerParents.h
GNEHierarchicalContainerChildren.h
GNEHierarchicalElement.cpp
GNEHierarchicalElement.h
GNEHierarchicalStructure.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
/****************************************************************************/
/// @file GNEHierarchicalContainer.h
/// @file GNEHierarchicalContainerChildren.h
/// @author Pablo Alvarez Lopez
/// @date Jan 2025
///
Expand Down Expand Up @@ -42,24 +42,16 @@ class GNEHierarchicalElement;
// class definitions
// ===========================================================================

/// @brief container type
enum class HierarchicalContainerType {
BASIC
};

template <typename T>
class GNEHierarchicalContainer : public std::vector<T> {
class GNEHierarchicalContainerChildren : public std::vector<T> {

public:
/// @brief default constructor
GNEHierarchicalContainer() {}
GNEHierarchicalContainerChildren() {}

/// @brief parameter constructor
GNEHierarchicalContainer(const std::vector<T>& elements, HierarchicalContainerType type):
myType(type) {
if (myType == HierarchicalContainerType::BASIC) {
myVectorElements.reserve(MAX_HIERARCHICAL_PARENTS);
}
GNEHierarchicalContainerChildren(const std::vector<T>& elements) {
myVectorElements = elements;
}

/// @brief get container size
Expand Down Expand Up @@ -93,9 +85,6 @@ class GNEHierarchicalContainer : public std::vector<T> {
}

private:
/// @brief container type
HierarchicalContainerType myType;

/// @brief elements vector
std::vector<T> myVectorElements;
};
93 changes: 93 additions & 0 deletions src/netedit/elements/GNEHierarchicalContainerParents.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/****************************************************************************/
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0/
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License 2.0 are satisfied: GNU General Public License, version 2
// or later which is available at
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
/****************************************************************************/
/// @file GNEHierarchicalContainerParents.h
/// @author Pablo Alvarez Lopez
/// @date Jan 2025
///
// Template container for GNEHierarchical elements
/****************************************************************************/
#pragma once
#include <config.h>

#include <vector>


#define MAX_HIERARCHICAL_PARENTS 10

// ===========================================================================
// class declarations
// ===========================================================================

class GNENetworkElement;
class GNEJunction;
class GNEEdge;
class GNELane;
class GNEAdditional;
class GNEDemandElement;
class GNEGenericData;
class GNEHierarchicalElement;

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

template <typename T>
class GNEHierarchicalContainerParents : public std::vector<T> {

public:
/// @brief default constructor
GNEHierarchicalContainerParents() {
myVectorElements.reserve(10);
}

/// @brief parameter constructor
GNEHierarchicalContainerParents(const std::vector<T>& elements) {
myVectorElements.reserve(10);
myVectorElements = elements;
}

/// @brief get container size
size_t size() const {
return myVectorElements.size();
}

/// @brief add parent element
void insert(T element) {
myVectorElements.push_back(element);
}

/// @brief remove parent element
bool erase(T element) {
auto it = std::find(myVectorElements.begin(), myVectorElements.end(), element);
if (it != myVectorElements.end()) {
myVectorElements.erase(it);
return true;
} else {
return false;
}
}

/// @brief update all elements
void set(const std::vector<T>& elements) {
myVectorElements.clear();
myVectorElements.reserve(elements.size());
for (const auto &element : elements) {
myVectorElements.push_back(element);
}
}

private:
/// @brief elements vector
std::vector<T> myVectorElements;
};
32 changes: 16 additions & 16 deletions src/netedit/elements/GNEHierarchicalElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,33 +107,33 @@ GNEHierarchicalElement::getAllHierarchicalElements() const {
}


const GNEHierarchicalContainer<GNEJunction*>&
const GNEHierarchicalContainerParents<GNEJunction*>&
GNEHierarchicalElement::getParentJunctions() const {
return myHierarchicalStructure.getParents<GNEJunction*>();
}


const GNEHierarchicalContainer<GNEEdge*>&
const GNEHierarchicalContainerParents<GNEEdge*>&
GNEHierarchicalElement::getParentEdges() const {
return myHierarchicalStructure.getParents<GNEEdge*>();
}


const GNEHierarchicalContainer<GNELane*>&
const GNEHierarchicalContainerParents<GNELane*>&
GNEHierarchicalElement::getParentLanes() const {
return myHierarchicalStructure.getParents<GNELane*>();
}


const GNEHierarchicalContainer<GNEAdditional*>&
const GNEHierarchicalContainerParents<GNEAdditional*>&
GNEHierarchicalElement::getParentAdditionals() const {
return myHierarchicalStructure.getParents<GNEAdditional*>();
}


const GNEHierarchicalContainer<GNEAdditional*>
const GNEHierarchicalContainerParents<GNEAdditional*>
GNEHierarchicalElement::getParentStoppingPlaces() const {
GNEHierarchicalContainer<GNEAdditional*> stoppingPlaces;
GNEHierarchicalContainerParents<GNEAdditional*> stoppingPlaces;
for (const auto& additional : getParentAdditionals()) {
if (additional->getTagProperty().isStoppingPlace()) {
stoppingPlaces.push_back(additional);
Expand All @@ -143,9 +143,9 @@ GNEHierarchicalElement::getParentStoppingPlaces() const {
}


const GNEHierarchicalContainer<GNEAdditional*>
const GNEHierarchicalContainerParents<GNEAdditional*>
GNEHierarchicalElement::getParentTAZs() const {
GNEHierarchicalContainer<GNEAdditional*> TAZs;
GNEHierarchicalContainerParents<GNEAdditional*> TAZs;
for (const auto& additional : getParentAdditionals()) {
if (additional->getTagProperty().isTAZElement()) {
TAZs.push_back(additional);
Expand All @@ -155,49 +155,49 @@ GNEHierarchicalElement::getParentTAZs() const {
}


const GNEHierarchicalContainer<GNEDemandElement*>&
const GNEHierarchicalContainerParents<GNEDemandElement*>&
GNEHierarchicalElement::getParentDemandElements() const {
return myHierarchicalStructure.getParents<GNEDemandElement*>();
}


const GNEHierarchicalContainer<GNEGenericData*>&
const GNEHierarchicalContainerParents<GNEGenericData*>&
GNEHierarchicalElement::getParentGenericDatas() const {
return myHierarchicalStructure.getParents<GNEGenericData*>();
}


const GNEHierarchicalContainer<GNEJunction*>&
const GNEHierarchicalContainerChildren<GNEJunction*>&
GNEHierarchicalElement::getChildJunctions() const {
return myHierarchicalStructure.getChildren<GNEJunction*>();
}


const GNEHierarchicalContainer<GNEEdge*>&
const GNEHierarchicalContainerChildren<GNEEdge*>&
GNEHierarchicalElement::getChildEdges() const {
return myHierarchicalStructure.getChildren<GNEEdge*>();
}


const GNEHierarchicalContainer<GNELane*>&
const GNEHierarchicalContainerChildren<GNELane*>&
GNEHierarchicalElement::getChildLanes() const {
return myHierarchicalStructure.getChildren<GNELane*>();
}


const GNEHierarchicalContainer<GNEAdditional*>&
const GNEHierarchicalContainerChildren<GNEAdditional*>&
GNEHierarchicalElement::getChildAdditionals() const {
return myHierarchicalStructure.getChildren<GNEAdditional*>();
}


const GNEHierarchicalContainer<GNEDemandElement*>&
const GNEHierarchicalContainerChildren<GNEDemandElement*>&
GNEHierarchicalElement::getChildDemandElements() const {
return myHierarchicalStructure.getChildren<GNEDemandElement*>();
}


const GNEHierarchicalContainer<GNEGenericData*>&
const GNEHierarchicalContainerChildren<GNEGenericData*>&
GNEHierarchicalElement::getChildGenericDatas() const {
return myHierarchicalStructure.getChildren<GNEGenericData*>();
}
Expand Down
28 changes: 14 additions & 14 deletions src/netedit/elements/GNEHierarchicalElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,46 +89,46 @@ class GNEHierarchicalElement : public GNEAttributeCarrier {
std::vector<GNEHierarchicalElement*> getAllHierarchicalElements() const;

/// @brief get parent junctions
const GNEHierarchicalContainer<GNEJunction*>& getParentJunctions() const;
const GNEHierarchicalContainerParents<GNEJunction*>& getParentJunctions() const;

/// @brief get parent edges
const GNEHierarchicalContainer<GNEEdge*>& getParentEdges() const;
const GNEHierarchicalContainerParents<GNEEdge*>& getParentEdges() const;

/// @brief get parent lanes
const GNEHierarchicalContainer<GNELane*>& getParentLanes() const;
const GNEHierarchicalContainerParents<GNELane*>& getParentLanes() const;

/// @brief get parent additionals
const GNEHierarchicalContainer<GNEAdditional*>& getParentAdditionals() const;
const GNEHierarchicalContainerParents<GNEAdditional*>& getParentAdditionals() const;

/// @brief get parent stoppingPlaces (used by plans)
const GNEHierarchicalContainer<GNEAdditional*> getParentStoppingPlaces() const;
const GNEHierarchicalContainerParents<GNEAdditional*> getParentStoppingPlaces() const;

/// @brief get parent TAZs (used by plans)
const GNEHierarchicalContainer<GNEAdditional*> getParentTAZs() const;
const GNEHierarchicalContainerParents<GNEAdditional*> getParentTAZs() const;

/// @brief get parent demand elements
const GNEHierarchicalContainer<GNEDemandElement*>& getParentDemandElements() const;
const GNEHierarchicalContainerParents<GNEDemandElement*>& getParentDemandElements() const;

/// @brief get parent demand elements
const GNEHierarchicalContainer<GNEGenericData*>& getParentGenericDatas() const;
const GNEHierarchicalContainerParents<GNEGenericData*>& getParentGenericDatas() const;

/// @brief get child junctions
const GNEHierarchicalContainer<GNEJunction*>& getChildJunctions() const;
const GNEHierarchicalContainerChildren<GNEJunction*>& getChildJunctions() const;

/// @brief get child edges
const GNEHierarchicalContainer<GNEEdge*>& getChildEdges() const;
const GNEHierarchicalContainerChildren<GNEEdge*>& getChildEdges() const;

/// @brief get child lanes
const GNEHierarchicalContainer<GNELane*>& getChildLanes() const;
const GNEHierarchicalContainerChildren<GNELane*>& getChildLanes() const;

/// @brief return child additionals
const GNEHierarchicalContainer<GNEAdditional*>& getChildAdditionals() const;
const GNEHierarchicalContainerChildren<GNEAdditional*>& getChildAdditionals() const;

/// @brief return child demand elements
const GNEHierarchicalContainer<GNEDemandElement*>& getChildDemandElements() const;
const GNEHierarchicalContainerChildren<GNEDemandElement*>& getChildDemandElements() const;

/// @brief return child generic data elements
const GNEHierarchicalContainer<GNEGenericData*>& getChildGenericDatas() const;
const GNEHierarchicalContainerChildren<GNEGenericData*>& getChildGenericDatas() const;

/// @}

Expand Down
Loading

0 comments on commit d580862

Please sign in to comment.