All Classes Files Functions Variables Enumerations Enumerator Macros
season.cpp
Go to the documentation of this file.
1 
15 #include "season.hpp"
16 
19 {
20  // Set the number of episodes for this season to default
21  numEpisodes = 0;
22 };
23 
26 Season::Season( int seasNum )
27 {
28  // Set the number of episodes for this season to default
29  numEpisodes = 0;
30  // Store the number of this season
31  number = seasNum;
32 };
33 
36 {};
37 
48 // Add an episode to the season
49 bool Season::addEpisode( int num, int xep, string pep, string title, string newfile,
50  string newdir, string oldfile, string olddir )
51 {
52  // Increase the vector size by 1
53  episodes.resize( episodes.size() + 1 );
54 
55  // Store data into the last item of the vector
56  episodes[episodes.size()-1].reset( num, xep, pep, title, newfile,
57  newdir, oldfile, olddir );
58 
59  // Increment the number of episodes for this season
60  numEpisodes++;
61 
62  // Return 1 = Success
63  return 1;
64 };
65 
69 // Set the number of the current season
70 bool Season::setNumber( int num )
71 {
72  // Store the number of this season
73  number = num;
74 
75  // Return 1 = Success
76  return 1;
77 };
78 
80 // Get the number of the current season
81 int Season::getNumber() const
82 {
83  return number;
84 };
85 
87 // Get the number of episodes within the current season
88 int Season::getNumEps() const
89 {
90  // Return the number of episodes
91  return episodes.size();
92 };
93 
96 // Sort episodes by number in ascending order
98 {
99  // Create a swap flag
100  bool swapped = true;
101  // Create the initial search range
102  int rangeInt = episodes.size();
103 
104  // Check if there are less than 2 episodes
105  if( episodes.size() < 2 )
106  {
107  // Return 1 = Success
108  return 1;
109  }
110 
111  // Bubble sort: stop when no swaps, shorten range each time
112  while( swapped )
113  {
114  // Reset condition
115  swapped = false;
116  // Make the search range smaller
117  rangeInt--;
118  // For each episode
119  for( int i = 0; i < rangeInt; i++ )
120  {
121  // Check if previous ep number is greater than then next ep number
122  if( episodes[i].getNumber() > episodes[i+1].getNumber() )
123  {
124  // Create a temporary episode object
125  Episode tempEp;
126 
127  // Store current episode info in the temp object
128  tempEp.reset( episodes[i].getNumber(),
129  episodes[i].getExtra(),
130  episodes[i].getPart(),
131  episodes[i].getTitle(),
132  episodes[i].getFilename(),
133  episodes[i].getDirectory(),
134  episodes[i].getOldFile(),
135  episodes[i].getOldDir() );
136  // Store the next episode as the current episode
137  episodes[i].reset( episodes[i+1].getNumber(),
138  episodes[i+1].getExtra(),
139  episodes[i+1].getPart(),
140  episodes[i+1].getTitle(),
141  episodes[i+1].getFilename(),
142  episodes[i+1].getDirectory(),
143  episodes[i+1].getOldFile(),
144  episodes[i+1].getOldDir() );
145  // Store the temp object as the next episode
146  episodes[i+1].reset( tempEp.getNumber(),
147  tempEp.getExtra(),
148  tempEp.getPart(),
149  tempEp.getTitle(),
150  tempEp.getFilename(),
151  tempEp.getDirectory(),
152  tempEp.getOldFile(),
153  tempEp.getOldDir() );
154 
155  // Reset the counter to restart the sort
156  swapped = true;
157  }
158  }
159  }
160 
161  // Return 1 = Success
162  return 1;
163 };
int getNumber() const
Definition: season.cpp:81
int numEpisodes
The number of episodes in the season.
Definition: season.hpp:51
int number
The season's number.
Definition: season.hpp:50
vector< Episode > episodes
A vector that holds each Episode.
Definition: season.hpp:47
string getFilename() const
Definition: episode.cpp:131
int getExtra() const
Definition: episode.cpp:101
string getTitle() const
Definition: episode.cpp:113
int getNumEps() const
Definition: season.cpp:88
The Season class stores all info required to describe a particular season of a TV show...
int getNumber() const
Definition: episode.cpp:95
string getPart() const
Definition: episode.cpp:107
Stores parsed file information regarding a single episode; to be used as a vector.
Definition: episode.hpp:25
string getOldDir() const
Definition: episode.cpp:125
string getOldFile() const
Definition: episode.cpp:119
~Season()
Default destructor.
Definition: season.cpp:35
bool setNumber(int)
Set the season number.
Definition: season.cpp:70
Season()
Default constructor, sets the number of episodes to 0 by default.
Definition: season.cpp:18
bool addEpisode(int, int, string, string, string, string, string, string)
Saves the info required to describe a particular episode.
Definition: season.cpp:49
bool reset(int, int, string, string, string, string, string, string)
Resets the info required to describe a particular episode.
Definition: episode.cpp:70
string getDirectory() const
Definition: episode.cpp:137
bool sortAscending()
Sorts the episodes by number in ascending order.
Definition: season.cpp:97