All Classes Files Functions Variables Enumerations Enumerator Macros
mainOutput.cpp
Go to the documentation of this file.
1 #include "output.hpp"
13 
15 // Default constructor
17 {};
18 
24 // Constructor: set options to determine output requirements
25 OutPut::OutPut( Library *libObj, vector<ErrorHandler> &fail, ConfigOpts *confObj )
26 {
27  // Check if the log flag is set
28  if( confObj->getFlags( confObj->WriteToLogFile_flag ) )
29  {
30  // Set the output stream to an output file stream of a log file
31  tout = &lout;
32  // Open the log file at the given location
33  lout.open( confObj->getOptions( confObj->LogFileLocation_opt ).c_str() );
34  // Check if the summary flag is set
35  if( confObj->getFlags( confObj->VerbosityLevelSummary_flag ) )
36  {
37  // Write to the standard console output
38  cout << "Writing to log: " << confObj->getOptions( confObj->LogFileLocation_opt ) << endl;
39  }
40  }
41  // Check if log flag is not set
42  else
43  {
44  // Set the output stream to the standard console output
45  tout = &cout;
46  }
47 
48  // Check if the summary flag is set
49  if( confObj->getFlags( confObj->VerbosityLevelSummary_flag ) )
50  {
51  // Output summary of a FindShows object
52  outputSummary( libObj, confObj, *tout, fail.size() );
53  }
54 
55  // Check if the verbose flag is set
56  if( confObj->getFlags( confObj->VerbosityLevelVerbose_flag ) )
57  {
58  // Output all errors contained in error handler vector
59  outputError( fail, *tout );
60  // Append a blank line at the end of the output
61  *tout << endl;
62  }
63 
64  // Check if output argument is not empty
65  if( confObj->getOptions( confObj->OutputSourceArgument_opt ) != "" )
66  {
67  // Check if the script flag is set
68  if( confObj->getFlags( confObj->WriteToScriptFile_flag ) )
69  {
70  // Open the script file at the given location
71  sout.open( confObj->getOptions( confObj->ScriptFileLocation_opt ).c_str() );
72  // Check if the summary flag is set
73  if( confObj->getFlags( confObj->VerbosityLevelSummary_flag ) )
74  {
75  // Write to the standard console output
76  cout << "Writing to batch: " << confObj->getOptions( confObj->ScriptFileLocation_opt ) << endl;
77  }
78  // Output the script header
79  sout << SCRIPT1 << endl;
80  // Set the output stream to an output file stream of a script file
81  tout = &sout;
82  }
83 
84  // For each show found
85  for( unsigned int i = 0; i < libObj->shows.size(); i++ )
86  {
87  // For each season found
88  for( unsigned int j = 0; j < libObj->shows[i].seasons.size(); j++ )
89  {
90  // For each episode found
91  for( unsigned int k = 0; k < libObj->shows[i].seasons[j].episodes.size(); k++ )
92  {
93  // Output show, season, and episode info
94  outputTasks( &libObj->shows[i].seasons[j].episodes[k], confObj, *tout );
95  }
96  }
97  }
98 
99  // Check if the script flag is set
100  if( confObj->getFlags( confObj->WriteToScriptFile_flag ) )
101  {
102  // Close the script file
103  sout.close();
104  }
105  }
106 
107  // Check if the log flag is set
108  if( confObj->getFlags( confObj->WriteToLogFile_flag ) )
109  {
110  // Close the log file
111  lout.close();
112  }
113 
114  // Check if the xml flag is set
115  if( confObj->getFlags( confObj->WriteToXmlFile_flag ) )
116  {
117  // Set the output stream to an output file stream of an XML file
118  tout = &fout;
119  // Open the XML file at the given location
120  fout.open( confObj->getOptions( confObj->XmlFileLocation_opt ).c_str() );
121 
122  // Write to the standard console output
123  cout << "Writing to xml: " << confObj->getOptions( confObj->XmlFileLocation_opt ) << endl;
124 
125  // Output an XML of the Library object
126  outputXML( libObj, *tout );
127  // Close the XML file
128  fout.close();
129  }
130 
131  // Check if the gap flag is set
132  if( confObj->getFlags( confObj->WriteToGapFile_flag ) )
133  {
134  // Set the output stream to an output file stream of a gap file
135  tout = &fout;
136  // Open the gap file at the given location
137  fout.open( confObj->getOptions( confObj->GapFileLocation_opt ).c_str() );
138 
139  // Write to the standard console output
140  cout << "Writing to gap: " << confObj->getOptions( confObj->GapFileLocation_opt ) << endl;
141 
142  // Output an gap of the Library object
143  outputMissing( libObj, *tout );
144  // Close the gap file
145  fout.close();
146  }
147 };
148 
150 // Default destructor
152 {};
153 
160 // Outputs summary information from objects
161 void OutPut::outputSummary( Library *libObj, ConfigOpts *confObj, ostream &tout, int errInt )
162 {
163  // Check if Parser objects exist
164  if( libObj == NULL )
165  {
166  // Write to the standard console output
167  cout << "Error: no data found in Parser object" << endl;
168  }
169  // If Parser objects don't exist
170  else
171  {
172  // Output the total number of shows parsed
173  tout << "Total files parsed: " << confObj->v_fileList.size() << endl;
174  tout << "Parser errors: " << errInt << endl << endl;
175 
176  // For each show
177  for( unsigned int i = 0; i < libObj->shows.size(); i++ )
178  {
179  // Create a episode counter
180  int countEpisode = 0;
181  // Check if the verbose flag is set
182  if( confObj->getFlags( confObj->VerbosityLevelVerbose_flag ) )
183  {
184  // Output Show names
185  tout << confObj->v_showList[libObj->shows[i].getIndex()][0] << endl;
186  }
187 
188  // For each season
189  for( unsigned int j = 0; j < libObj->shows[i].seasons.size(); j++ )
190  {
191  // For each episode
192  for( unsigned int k = 0; k < libObj->shows[i].seasons[j].episodes.size(); k++ )
193  {
194  // Increment the episode counter
195  countEpisode++;
196  }
197  // Check if the verbose flag is set
198  if( confObj->getFlags( confObj->VerbosityLevelVerbose_flag ) )
199  {
200  // Output episodes per show per season
201  tout << " [Season " << libObj->shows[i].seasons[j].getNumber() << "] - "
202  << libObj->shows[i].seasons[j].episodes.size() << " episodes" << endl;
203  }
204  }
205  // Check if the verbose flag is not set
206  if( !confObj->getFlags( confObj->VerbosityLevelVerbose_flag ) )
207  {
208  // Output Show names
209  tout << confObj->v_showList[libObj->shows[i].getIndex()][0] << " - " << countEpisode << " episodes" << endl;
210  }
211  }
212  }
213  // Append a blank line at the end of the output
214  tout << endl;
215 };
216 
221 // Outputs the error information from an object
222 void OutPut::outputError( vector<ErrorHandler> &fail, ostream &tout )
223 {
224  // Check if the Parser object has an error
225  for(unsigned int i = 0; i < fail.size(); i++ )
226  {
227  // Output directory, file, and error information
228  tout << "Error found: \"" << fail[i].errorFile << "\"" << endl;
229  switch( fail[i].errorData )
230  {
232  tout << "Season/Episode pattern match failed : skipped file" << endl;
233  break;
235  tout << "Show name match failed : skipped file" << endl;
236  break;
238  tout << "An episode already exists : skipped file" << endl;
239  break;
241  tout << "Sort failed" << endl;
242  break;
243  default:
244  tout << "Undefined error" << endl;
245  }
246  }
247 };
The OutPut class prints summary and error information from objects.
A Show name match failure occured.
Definition: options.hpp:124
OutPut()
The default constructor.
Definition: mainOutput.cpp:16
static bool getFlags(flagValue)
Retrieves the user configuration flags from an array.
Definition: mainPublic.cpp:280
output summary and error information
Definition: options.hpp:109
ofstream lout
Output file stream object for a log file.
Definition: output.hpp:51
#define SCRIPT1
Definition: options.hpp:30
vector< Show > shows
A vector that holds each Show.
Definition: library.hpp:41
~OutPut()
The default destructor.
Definition: mainOutput.cpp:151
static vector< vector< string > > v_showList
A vector of vectors the will store a list of shows and a list of their episodes.
Definition: options.hpp:140
ofstream fout
Output file stream object for a file (WTF?)
Definition: output.hpp:53
A sort failure occured.
Definition: options.hpp:126
holds xml file name and location
Definition: options.hpp:89
static string getOptions(optionValue)
Retrieves the user configuration options from an array.
Definition: mainPublic.cpp:129
output directory from args
Definition: options.hpp:80
static void outputMissing(Library *, ostream &)
Outputs gaps in a given Library object's contents.
Definition: gap.cpp:17
holds gap file name and location
Definition: options.hpp:90
static vector< string > v_fileList
A vector that contains the list of input files to be parsed.
Definition: options.hpp:142
holds script file name and location
Definition: options.hpp:82
ofstream sout
Output file stream object for a script file.
Definition: output.hpp:52
write a script instead of internal action
Definition: options.hpp:103
output to log instead of stdout
Definition: options.hpp:110
static void outputXML(Library *, ostream &)
Outputs summary information from objects in XML format.
Definition: xml.cpp:18
static void outputError(vector< ErrorHandler > &, ostream &)
Outputs the given error information to the given stream.
Definition: mainOutput.cpp:222
A duplicate Episode failure occured.
Definition: options.hpp:125
A Season or Episode pattern match failure occured.
Definition: options.hpp:123
ostream * tout
Temporary output stream pointer, to store output file stream object address.
Definition: output.hpp:50
Stores all config options, settings, and flags for clerk.
Definition: options.hpp:60
static void outputSummary(Library *, ConfigOpts *, ostream &, int)
Outputs a summary of an input Library object.
Definition: mainOutput.cpp:161
holds log file name and location
Definition: options.hpp:81
static void outputTasks(Episode *, ConfigOpts *, ostream &)
Outputs to the given stream the commands needed to perform the requested tasks.
Definition: tasks.cpp:20
Stores all info required to describe all shows.
Definition: library.hpp:30