-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lane.cpp
68 lines (55 loc) · 1.82 KB
/
Lane.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//* Author: Dhiraj Amarnani, Hassan Naveed, Andre Koppert
//* Date: December 18 2017
#include "Lane.h"
#include <iostream>
using namespace std;
//*******************************************************************
//* Lane()
//*
//* The constructor of our Lane class that creates a new
//* instance of our Lane class. It takes a enum direction to, int
//* size, intersections one and two as well as a traffic signal. It
//* does not return anything
//*
//* Pre-conditions: Direction to initializes the lane direction.
//* int size initializes the size of the lane.
//* Intersection* _one _two to add to this lane.
//* TrafficSignal* _myTrafficSignal to add to this
//* lane.
//*
//*******************************************************************
Lane::Lane(Direction to, int size, Intersection* _one, Intersection* _two, TrafficSignal* _myTrafficSignal){
going = to;
sizeOfLane = size;
one = _one;
two = _two;
myTrafficSignal = _myTrafficSignal;
//initialize thisLane array as pointers to sections
thisLane = new Section*[size];
for(int i = 0 ; i < size; i++){
thisLane[i] = new Section;
}
//delete sections to free memory
delete thisLane[size/2];
delete thisLane[size/2 -1];
//reallocate freed memory above to intersection
thisLane[( sizeOfLane/2 )- 1] = one;
thisLane[( sizeOfLane/2 )] = two;
}
//*******************************************************************
//* ~Lane()
//*
//* The destructor of our Lane class. It does not take any parameters
//* or return anything.
//*
//*******************************************************************
Lane::~Lane(){
//delete all sections in thisLane array of pointers
for (int i = 0; i < this-> sizeOfLane; i++){
if (i != this->sizeOfLane/2 && i != this-> sizeOfLane/2-1){
delete thisLane[i];
}
}
//delete the lane itself
delete [] thisLane;
}