Timetabler
segment.cpp
1 #include "fields/segment.h"
2 
3 #include <cassert>
4 #include <iostream>
5 #include <string>
6 #include "global.h"
7 
14 Segment::Segment(int startSegment, int endSegment) {
15  assert((startSegment <= endSegment) && "Start Segment after End Segment!");
16  this->startSegment = startSegment;
17  this->endSegment = endSegment;
18 }
19 
28 bool Segment::operator==(const Segment &other) {
29  return ((this->startSegment == other.startSegment) &&
30  (this->endSegment == other.endSegment));
31 }
32 
40 int Segment::length() { return (endSegment - startSegment + 1); }
41 
52 bool Segment::isIntersecting(const Segment &other) {
53  if (this->startSegment < other.startSegment) {
54  return !(this->endSegment < other.startSegment);
55  } else if (this->startSegment > other.startSegment) {
56  return !(this->startSegment > other.endSegment);
57  }
58  return true;
59 }
60 
66 FieldType Segment::getType() { return FieldType::segment; }
67 
75 std::string Segment::getName() {
76  return std::to_string(startSegment) + std::to_string(endSegment);
77 }
78 
84 std::string Segment::getTypeName() { return "Segment"; }
FieldType getType()
Gets the type under the FieldType enum.
Definition: segment.cpp:66
bool isIntersecting(const Segment &other)
Determines if two Segments are intersecting. Two segments are said to be intersecting if they contain...
Definition: segment.cpp:52
bool operator==(const Segment &other)
Checks if two segment objects are identical, which is if their start and end segments are identical...
Definition: segment.cpp:28
int length()
Gets the length of the Segment, which is the number of segment units it represents. For example, the length of the Segment 16 is 6.
Definition: segment.cpp:40
Segment(int, int)
Constructs the Segment object.
Definition: segment.cpp:14
std::string getTypeName()
Gets the type name, which is "Segment".
Definition: segment.cpp:84
FieldType
Enum that represents all the field types.
Definition: global.h:9
std::string getName()
Gets the name of the Segment. The name is a string that concatenates the start and end segment values...
Definition: segment.cpp:75
Class for segment.
Definition: segment.h:13