-
Notifications
You must be signed in to change notification settings - Fork 0
/
lines.h
177 lines (124 loc) · 3.73 KB
/
lines.h
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#ifndef LINES_H_INCLUDED
#define LINES_H_INCLUDED
// PROJECT DEPENDENCIES
#include "serializable.h"
#include "stations.h"
#include "timestamp.h"
#include "timetable.h"
// STL INCLUDES
#include <list>
#include <string>
#include <stdexcept>
//CONSTANTS DEFS
#define IID_NO_ICON -1
#define IID_BUS 0
#define IID_TROLLEY 1
#define IID_TRAM 2
#define IID_METRO 3
#define IID_BOAT 4
#define IID_MONORAIL 5
// class Line
class Line : public Serializable
{
friend class Lines;
public:
typedef unsigned int ID;
typedef unsigned int LineNumber;
typedef int IconID;
struct Stop : public Serializable
{
// typedefs
typedef TimeOffset TimeStampType;
// constructors
Stop();
Stop(Station::ID s, const TimeStampType& t);
Stop(const PropertyTree& pt);
// operators
const bool operator>(const Stop& x)const;
const bool operator<(const Stop& x)const;
const bool operator==(const Stop& x)const;
const bool operator!=(const Stop& x)const;
// serialization
virtual PropertyTree serialize() const;
virtual void deserialize(const PropertyTree& pt);
Station::ID station;
TimeStampType time;
}; // struct Stop
typedef std::list<Stop> StopList;
// constructors
explicit Line(const char* name, const LineNumber& number = 0, const IconID& icon = IID_NO_ICON);
explicit Line(const std::string& name, const LineNumber& number = 0, const IconID& icon = IID_NO_ICON);
explicit Line(const PropertyTree& pt);
// destructor
~Line();
// public members
const ID& getID() const;
IconID& getIcon();
const IconID& getIcon() const;
void SetIcon(IconID icon);
LineNumber& getNumber();
const LineNumber& getNumber() const;
void SetNumber(LineNumber number);
void setName(const std::string& n);
void setName(char const * const n);
std::string& getName();
const std::string& getName() const;
Stop* addStop(const Station::ID& station, const Stop::TimeStampType& time);
Stop* addStop(const Stop& stop);
void deleteStops(const Station::ID& station); // deletes all stops at given station
const StopList& getStopsList() const;
void clearStops();
Timetable& getTimetable();
const Timetable& getTimetable()const;
void setTimetable(const Timetable& tt);
// serializing
virtual PropertyTree serialize() const;
virtual void deserialize(const PropertyTree& pt);
private:
std::string _name;
ID _id;
LineNumber _number;
StopList _list;
Timetable _timetable;
IconID _icon;
}; // class Line
/** \brief Manager class for Lines
*
*
*/
class Lines : public Serializable
{
friend class Line;
public:
// public typedefs
typedef std::list<Line> LineList;
// static members
static Lines* instance();
static void destroy();
// public members
Line::ID peekNextFreeID() const;
Line& addLine(const Line& newLine);
Line& getLine(Line::ID id);
const Line& getLine(Line::ID id)const;
bool deleteLine(const Line::ID& id);
const LineList& getLinesList() const;
LineList& getLinesList();
void deleteStops(Station::ID station); // deletes all stops at given station in all lines
// serialization
Serializable::PropertyTree serialize() const;
void deserialize(const Serializable::PropertyTree& pt);
private:
typedef std::stack<Line::ID> IDStack;
// constructors
Lines();
// destructor
virtual ~Lines();
//private members
Line::ID getNextFreeID();
void freeID(Line::ID id);
static Lines* _instance;
LineList _list;
Line::ID _idCounter;
IDStack _idStack;
}; // class Lines
#endif // LINES_H_INCLUDED