Eclipse SUMO - Simulation of Urban MObility
Node.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
19 // Representation of electric circuit nodes, i.e. wire junctions and connection points.
21 /****************************************************************************/
22 #include <string>
23 #include <algorithm>
24 #include "Node.h"
25 #include "Element.h"
26 
27 using namespace std;
28 
29 // A constructor, same functionality as "init" functions
30 Node::Node(string name, int id) {
31  isground = false;
32  this->name = name; // unique property, each object has distinctive and unique name
33  this->id = id; // a sequential ID number, might be useful when making the equation
34  this->num_matrixRow = -1;
35  this->num_matrixCol = -1;
36  this->voltage = 0;
37  this->elements = new vector<Element*>(0);
38  isremovable = false;
39 }
40 
41 // connects an element to the node
42 void Node::addElement(Element* element) {
43  elements->push_back(element);
44 }
45 
46 void Node::eraseElement(Element* element) {
47  elements->erase(std::remove(elements->begin(), elements->end(), element), elements->end());
48 }
49 
50 // getters and setters
51 double Node::getVoltage() {
52  return this->voltage;
53 }
54 
55 void Node::setVoltage(double voltage) {
56  this->voltage = voltage;
57 }
58 
60  return (int) elements->size();
61 }
62 
63 string& Node::getName() {
64  return this->name;
65 }
66 
68  return this->isground;
69 }
70 
71 void Node::setGround(bool newIsGround) {
72  this->isground = newIsGround;
73 }
74 
75 int Node::getId() {
76  return this->id;
77 }
78 
79 void Node::setId(int newId) {
80  this->id = newId;
81 }
82 
83 void Node::setNumMatrixRow(int num) {
84  this->num_matrixRow = num;
85 }
86 
88  return this->num_matrixRow;
89 }
90 
91 void Node::setNumMatrixCol(int num) {
92  this->num_matrixCol = num;
93 }
94 
96  return this->num_matrixCol;
97 }
98 
99 vector<Element*>* Node::getElements() {
100  return elements;
101 }
102 
103 void Node::setRemovability(bool newIsRemovable) {
104  this->isremovable = newIsRemovable;
105 }
106 
108  // for (vector<Element*>::iterator it = this->getElements()->begin(); it != this->getElements()->end(); it++) {
109  for (Element* it : *this->getElements()) {
110  if (it != element) {
111  return it;
112  }
113  }
114  return nullptr;
115 }
vector< Element * > * getElements()
Definition: Node.cpp:99
void setVoltage(double voltage)
Definition: Node.cpp:55
void setGround(bool isground)
Definition: Node.cpp:71
void setNumMatrixCol(int num)
Definition: Node.cpp:91
int getId()
Definition: Node.cpp:75
string & getName()
Definition: Node.cpp:63
int getNumMatrixCol()
Definition: Node.cpp:95
Element * getAnOtherElement(Element *element)
Definition: Node.cpp:107
bool isGround()
Definition: Node.cpp:67
void addElement(Element *element)
Definition: Node.cpp:42
void eraseElement(Element *element)
Definition: Node.cpp:46
int getNumOfElements()
Definition: Node.cpp:59
double getVoltage()
Definition: Node.cpp:51
void setNumMatrixRow(int num)
Definition: Node.cpp:83
Node(string name, int id)
Definition: Node.cpp:30
void setId(int id)
Definition: Node.cpp:79
void setRemovability(bool isremovable)
Definition: Node.cpp:103
int getNumMatrixRow()
Definition: Node.cpp:87