All Classes Files Functions Variables Enumerations Enumerator Macros
show.cpp
Go to the documentation of this file.
1 
17 #include "show.hpp"
18 
21 {
22  // Set the number of episodes for this show to default
23  numEpisodes = 0;
24 };
25 
29 // Constructor
30 Show::Show( int ind, string name )
31 {
32  // Store the index of this show
33  index = ind;
34  // Store the name of this show
35  showname = name;
36 };
37 
40 {};
41 
43 // Gets the show name index
44 int Show::getIndex() const
45 {
46  return index;
47 };
48 
50 // Gets the showname
51 string Show::getShowname() const
52 {
53  return showname;
54 };
55 
59 // Sets the show name index
60 bool Show::setIndex( int ind )
61 {
62  // Store the show name index
63  index = ind;
64 
65  // Return 1 = Success
66  return 1;
67 };
68 
72 // Sets the show name
73 bool Show::setShowname( string name )
74 {
75  // Store the show name index
76  showname = name;
77 
78  // Return 1 = Success
79  return 1;
80 };
81 
86 // Add a season to this show
87 bool Show::addSeason( int seasNum, vector<ErrorHandler> &fail )
88 {
89  // Search through the season vector
90  for( unsigned int i = 0; i < seasons.size(); i++ )
91  {
92  // Check if the season exists
93  if( seasons[i].getNumber() == seasNum )
94  {
95  // Return 0 = Fail
96  return 0;
97  }
98  }
99 
100  // Increase the size of the vector
101  seasons.resize( seasons.size()+1 );
102  // Store data into the last item of the vector
103  seasons[seasons.size()-1].setNumber( seasNum );
104  // Increment the number of seasons for this show
105  numSeasons++;
106 
107  // Sort the seasons in ascending order
108  if( !sortAscending() )
109  {
110  // Output info about files that do not sort
111  string fileError = "Showname : " + getShowname() + " : Season : ";
112  fileError += seasNum;
113  // Save the error to the error handler vector
114  fail.push_back ( ErrorHandler( fileError, ConfigOpts::SortFailureError ) );
115  }
116 
117  // Return 1 = Success
118  return 1;
119 };
120 
123 // Sort seasons in ascending order
125 {
126  // Create a swap flag
127  bool swapped = true;
128  // Create the initial search range
129  int rangeInt = seasons.size();
130 
131  // Check if there are less than 2 seasons
132  if( seasons.size() < 2 )
133  {
134  // Return 1 = Success
135  return 1;
136  }
137 
138  // Bubble sort: stop when no swaps, shorten range each time
139  while( swapped )
140  {
141  // Reset condition
142  swapped = false;
143  // Make the search range smaller
144  rangeInt--;
145  // For each season
146  for( int i = 0; i < rangeInt; i++ )
147  {
148  // Check if previous season number is greater than then next season number
149  if( seasons[i].getNumber() > seasons[i+1].getNumber() )
150  {
151  // Create a temporary season object
152  Season tempSeason;
153 
154  // Store current season info in the temp object
155  tempSeason = seasons[i];
156  // Store the next season as the current season
157  seasons[i] = seasons[i+1];
158  // Store the temp object as the next season
159  seasons[i+1] = tempSeason;
160 
161  // Reset the counter to restart the sort
162  swapped = true;
163  }
164  }
165  }
166 
167  // Return 1 = Success
168  return 1;
169 };
~Show()
Default destructor.
Definition: show.cpp:39
int numSeasons
The number of seasons for *this show.
Definition: show.hpp:55
bool sortAscending()
Sorts the seasons in ascending order.
Definition: show.cpp:124
Show()
Default constructor, set the number of episodes to 0, the default.
Definition: show.cpp:20
int index
The show name's index.
Definition: show.hpp:53
Stores all info required to describe a particular season of a TV show.
Definition: season.hpp:30
The Show class stores all info required to describe an entire TV show.
A sort failure occured.
Definition: options.hpp:126
string getShowname() const
Definition: show.cpp:51
int getIndex() const
Definition: show.cpp:44
vector< Season > seasons
A vector that holds the Season objects.
Definition: show.hpp:48
bool setIndex(int)
Sets the show name index.
Definition: show.cpp:60
string showname
The show's name.
Definition: show.hpp:54
int numEpisodes
The number of episodes for *this show.
Definition: show.hpp:56
The ErrorHandler class stores an error as it occurs.
Definition: handler.hpp:17
bool addSeason(int, vector< ErrorHandler > &)
Adds a season to the current show.
Definition: show.cpp:87
bool setShowname(string)
Sets the show name.
Definition: show.cpp:73