MovieList Class Reference

This class is used read movies into memory. More...

#include <MovieList.hpp>

List of all members.


Public Member Functions

 MovieList (Profile *profile=NULL)
 default constructor
 ~MovieList ()
 default destructor
void addMovie (Movie *m)
 Add a movie to the list.
string getDescription ()
 Get the description of the movie-list.
string getHTMLRepresentation (char *imgPath, CGIParser *cgiparser=NULL, bool fakeRtspServer=false)
 Get an HTML-representation of the movie-list.
void readMoviesFromFile (const char *filename)
 Read movies from specified xml-file.

Static Public Member Functions

MoviegetMovieById (string movieId)

Detailed Description

This class is used read movies into memory.

Author:
Klaus Schoeffmann

Definition at line 71 of file MovieList.hpp.


Member Function Documentation

string MovieList::getHTMLRepresentation char *  imgPath,
CGIParser cgiparser = NULL,
bool  fakeRtspServer = false
 

Get an HTML-representation of the movie-list.

Parameters:
imgPath specifies the path where referenced images are stored
Definition at line 97 of file MovieList.cpp.

References CGIParser::getFieldValue(), Profile::getHeight(), Movie::getHTMLRepresentation(), Profile::getProfileId(), Profile::getWidth(), and semifunc::newStrCpy().

00098 { 00099 string data; 00100 uint userId = 0; 00101 uint linktype = 0; 00102 char *sphost = NULL; 00103 char *spport = NULL; 00104 if (cgiparser != NULL) 00105 { 00106 userId = atoi(cgiparser->getFieldValue("userid").c_str()); 00107 linktype = atoi(cgiparser->getFieldValue("linktype").c_str()); 00108 sphost = semifunc::newStrCpy((char*)cgiparser->getFieldValue("sphost").c_str()); 00109 spport = semifunc::newStrCpy((char*)cgiparser->getFieldValue("spport").c_str()); 00110 } 00111 00112 //create html file of all movies 00113 vector<Movie*>::const_iterator iter = list.begin(); 00114 for (;iter != list.end(); iter++) 00115 { 00116 Movie *movie = *iter; 00117 if (cgiparser != NULL) 00118 { 00119 data += movie->getHTMLRepresentation(imgPath, 00120 userId, profile->getProfileId(), 00121 linktype, profile->getWidth(), profile->getHeight(), 00122 fakeRtspServer, sphost, spport); 00123 } 00124 else 00125 { 00126 data += movie->getHTMLRepresentation(imgPath, 0, 0, 1, 0, 0, fakeRtspServer); 00127 } 00128 } 00129 00130 return data; 00131 }

Movie * MovieList::getMovieById string  movieId  )  [static]
 

Returns:
reference to the movie in the list, which has the specified id
Definition at line 77 of file MovieList.cpp.

References Movie::getId().

Referenced by SessionList::writeHTMLRepresentation().

00078 { 00079 vector<Movie*>::const_iterator iter = list.begin(); 00080 for (;iter != list.end(); iter++) 00081 { 00082 Movie *movie = *iter; 00083 if (movieId == movie->getId()) return movie; 00084 } 00085 //not found 00086 return NULL; 00087 }

void MovieList::readMoviesFromFile const char *  filename  ) 
 

Read movies from specified xml-file.

This function is a very small implementation of a MPEG21-DigitalItem-Parser. The read movies will be stored in the vector 'list'. Definition at line 134 of file MovieList.cpp.

References Movie::getId(), and Movie::setUrl().

00135 { 00136 ifstream fp (filename, ios::in); 00137 if (! fp.is_open()) 00138 { 00139 cerr << "Error opening file '" << filename << "'"; 00140 exit (1); 00141 } 00142 00143 //read file into vector, tag by tag 00144 vector<string> vec; 00145 char buffer[4095]; 00146 00147 uint pos = 0; 00148 char c; 00149 while(true) 00150 { 00151 if (fp.get(c)) 00152 { 00153 //look if a tag starts 00154 if (c == '<' && pos != 0) 00155 { 00156 //push back old buffer 00157 buffer[pos] = '\0'; 00158 pos = 0; 00159 vec.push_back(string(buffer)); 00160 buffer[pos++] = c; 00161 } 00162 else if (c == '>') 00163 { 00164 buffer[pos++] = c; 00165 buffer[pos] = '\0'; 00166 pos = 0; 00167 vec.push_back(string(buffer)); 00168 } 00169 else 00170 { 00171 buffer[pos++] = c; 00172 } 00173 } 00174 else 00175 { 00176 break; 00177 } 00178 } 00179 fp.close(); 00180 00181 00182 //parse vector 00183 string name, description, img, url; 00184 string lastId, lastCondId; 00185 Movie *movie; 00186 uint i, statement=0; 00187 for (i=0; i<vec.size(); i++) 00188 { 00189 00190 //on selection-tags, store ID 00191 if (vec[i].find("<Selection") != string::npos) 00192 { 00193 unsigned int loc1 = vec[i].find("select_id=\"") + 11; 00194 unsigned int loc2 = vec[i].find("\"", loc1); 00195 lastId = vec[i].substr(loc1, loc2-loc1); 00196 } 00197 else if (vec[i].find("<Statement") != string::npos) 00198 { 00199 //read whole content until end of statement-tag 00200 string stmt = readStatement(i, vec); 00201 //cout << "\nread statement: " << stmt; 00202 00203 //assumption: 1st statement = name of movie, 2nd = desc, and so on... 00204 if (statement++ == 0) 00205 { 00206 //cout << "\nassigning to desc = " << stmt; 00207 this->desc.assign(stmt); 00208 } 00209 else if ((statement-1) % 2 == 1) 00210 { 00211 //cout << "\nassigning to name = " << stmt; 00212 //name of movie 00213 name.assign(stmt); 00214 } 00215 else if ((statement-1) % 2 == 0) 00216 { 00217 //cout << "\nassigning to description = " << stmt; 00218 //description of movie 00219 description.assign(stmt); 00220 } 00221 } 00222 else if (vec[i].find("<Resource mimeType=\"image/jpeg\"") != string::npos) 00223 { 00224 //image of movie 00225 unsigned int loc1 = vec[i].find("ref=\"") + 5; 00226 unsigned int loc2 = vec[i].find("\"", loc1); 00227 img = vec[i].substr(loc1, loc2-loc1); 00228 00229 //create movie and store in list 00230 movie = new Movie(name, lastId, description, img, "url"); 00231 list.push_back(movie); 00232 } 00233 //on conditions: store id for later use on resource-tag 00234 else if (vec[i].find("<Condition") != string::npos) 00235 { 00236 unsigned int loc1 = vec[i].find("require=\"") + 9; 00237 unsigned int loc2 = vec[i].find("\"", loc1); 00238 lastCondId = vec[i].substr(loc1, loc2-loc1); 00239 } 00240 //on resource: add this url to corresponding movie 00241 else if (vec[i].find("<Resource") != string::npos) 00242 { 00243 if (vec[i].find("mimeType=\"video/mpeg\"") != string::npos) 00244 { 00245 unsigned int loc1 = vec[i].find("ref=\"") + 5; 00246 unsigned int loc2 = vec[i].find("\"", loc1); 00247 url = vec[i].substr(loc1, loc2-loc1); 00248 uint j; 00249 for (j=0; j<list.size(); j++) 00250 { 00251 Movie *m = list[j]; 00252 if (m->getId().compare(lastCondId) == 0) 00253 { 00254 m->setUrl(url); 00255 } 00256 } 00257 } 00258 } 00259 } 00260 }


The documentation for this class was generated from the following files: