-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrack.cpp
More file actions
70 lines (62 loc) · 1.97 KB
/
Track.cpp
File metadata and controls
70 lines (62 loc) · 1.97 KB
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
#include "Track.h"
//Default constructor
Track::Track() {
title = "";
duration = Duration();
}
//Constructor that takes two strings to create a track
Track::Track(std::string title, std::string duration) {
this->title = std::move(title);
this->duration = Duration(std::move(duration));
}
//Constructor that takes a title string and a duration object to create a track.
Track::Track(std::string title, Duration dur) {
this->title = std::move(title);
this->duration = dur;
}
//Getters
const std::string &Track::getTitle() const {
return title;
}
const Duration &Track::getDuration() const {
return duration;
}
std::istream &operator>>(std::istream &is, Track &trackObj) {
char delim;
std::string s1;
std::string restOfLine;
std::string title;
Duration dur;
std::string trackLine;
if (is >> dur >> delim >> s1) {
if (delim == '-') {
//getline is needed in case the track title contains a space character.
std::getline(is, restOfLine);
title = s1 + restOfLine;
trackObj = Track(title, dur);
} else {
is.clear(std::ios_base::failbit);
}
} else {
is.clear(std::ios_base::failbit);
}
return is;
}
std::ostream &operator<<(std::ostream &Str, const Track &trackObj) {
return Str << trackObj.duration << " - " << trackObj.title;
}
void Track::testHarness() {
std::cout << "\n=---Track Test Harness---=" << std::endl;
Track track = Track("Last Train Home", "00:03:22");
Track track2 = Track();
Duration dur = Duration(0, 3, 14);
Track track3 = Track("Alien Boy", dur);
std::cout << track << std::endl;
std::cout << track2 << std::endl;
std::cout << track3 << std::endl;
std::string testString = "00:04:02 - Test Track";
std::stringstream ss(testString);
Track testTrack;
ss >> testTrack;
std::cout << "Title: " << testTrack.getTitle() << "\nDuration: " << testTrack.getDuration() << std::endl;
}