#include <CAcURL2FTS.h>

Public Member Functions | |
| const string & | getURLToFeatureFileName () const |
| CAcURL2FTS (const CXMLElement &inContentElement) | |
| virtual | operator bool () const |
| virtual int | size () const |
| pair< bool, string > | URLToFFN (const string &inURL) const |
| void | addImage (string inURL, string inThumbnailURL, string inFeatureFileName) |
| pair< bool, string > | IDToFFN (TID inID) const |
Protected Attributes | |
| TID | mID |
| string | mURLPrefix |
| string | mThumbnailURLPrefix |
| CMutex | mMutexURL2FTS |
| string_string_map | mURLToFFN |
| TID_string_map | mIDToFFN |
| ifstream | mURLToFeatureFile |
| string | mURLToFeatureFileName |
Private Attributes | |
| bool | mWellConstructed |
Friends | |
| class | CAcIFFileSystem |
| void | newStartURL2FTSElement (void *inUserData, const char *inElementName, const char **inAttributes) |
| void | newEndURL2FTSElement (void *inUserData, const char *inElementName) |
Definition at line 66 of file CAcURL2FTS.h.
| CAcURL2FTS::CAcURL2FTS | ( | const CXMLElement & | inContentElement | ) |
Constructor: slurp in an url2fts file and fill the maps.
Like every accessor, this accessor takes a <collection> MRML element as input (
Definition at line 106 of file CAcURL2FTS.cc.
References CMutex::lock(), CAccessorImplementation::mIDToAccessorElement, mIDToFFN, mURLToFeatureFile, mURLToFeatureFileName, mURLToFFN, CAccessorImplementation::mURLToID, mWellConstructed, my_throw, newEndURL2FTSElement, newStartURL2FTSElement, CMutex::unlock(), and USE_FLATFILE.
00106 : 00107 mURLToFeatureFileName(inCollectionElement.stringReadAttribute(mrml_const::cui_base_dir).second 00108 +inCollectionElement.stringReadAttribute(mrml_const::cui_feature_file_location).second), 00109 mURLToFeatureFile((inCollectionElement.stringReadAttribute(mrml_const::cui_base_dir).second 00110 +inCollectionElement.stringReadAttribute(mrml_const::cui_feature_file_location).second).c_str()) 00111 { 00112 gMutex->lock(); 00113 00114 cout << endl 00115 << "Opening " 00116 << mURLToFeatureFileName; 00117 if(!mURLToFeatureFile) 00118 cout <<" ...FAILED!"; 00119 else 00120 cout << " ...success." 00121 << endl; 00122 00123 mWellConstructed=mURLToFeatureFile; 00124 00125 mURLToFFN.clear(); 00126 mURLToID.clear(); 00127 mIDToFFN.clear(); 00128 mIDToAccessorElement.clear(); 00129 00130 00131 int lID=0; 00132 if(USE_FLATFILE){ 00133 00134 /* as long as there is no end of file */ 00135 while(mURLToFeatureFile){ 00136 string lURL; 00137 string lThumbnailURL; 00138 string lFeatureFileName; 00139 00140 /* read in the URLs of all the images with the corresponding feature file */ 00141 00142 00143 00144 mURLToFeatureFile >> lURL 00145 >> lThumbnailURL 00146 >> lFeatureFileName; 00147 00148 00149 if(lURL.size()>4){ 00150 #ifndef _NO_PRINT_INIT 00151 cout << lID 00152 << ": URL " << lURL << flush << endl 00153 << " Thumbnail " << lThumbnailURL << flush << endl 00154 << " FeatureFileName " << lThumbnailURL << flush << endl; 00155 #endif 00156 00157 mURLToFFN.insert(make_pair(lURL,lFeatureFileName)); 00158 mIDToFFN.insert(make_pair(lID,lFeatureFileName)); 00159 mURLToID.insert(make_pair(lURL,lID)); 00160 mIDToAccessorElement.insert(make_pair(lID,CAccessorElement(lID, 00161 lURL, 00162 lThumbnailURL, 00163 lFeatureFileName))); 00164 lID++; 00165 } 00166 } 00167 }else{// use an XML parser 00168 cout << "constructing parser" << endl; 00169 XML_Parser lParser = XML_ParserCreate(NULL);//default encoding 00170 XML_SetUserData(lParser, 00171 this); 00172 XML_SetElementHandler(lParser, 00173 newStartURL2FTSElement, 00174 newEndURL2FTSElement); 00175 00176 bool lParseError=false; 00177 string lURL2FTS; 00178 00179 cout << "Reading " << endl; 00180 00181 mURLToFeatureFile.seekg(0,ios::end); 00182 int lFileSize(mURLToFeatureFile.tellg()); 00183 mURLToFeatureFile.seekg(0,ios::beg); 00184 00185 cout << lFileSize 00186 << " characters" 00187 << endl; 00188 00189 char* lBuffer=new char[lFileSize+1]; 00190 mURLToFeatureFile.read(lBuffer,lFileSize); 00191 lBuffer[lFileSize]=char(0); 00192 00193 cout << "Read url2fts.xml" << endl; 00194 00195 bool lDone=false; 00196 for(int i=0; 00197 i<=lFileSize/10000; 00198 i++){ 00199 if (!XML_Parse(lParser, 00200 lBuffer+i*10000, 00201 (lFileSize-i*10000<10000) 00202 ?lFileSize-i*10000:10000, 00203 lDone) 00204 ) { 00205 cerr << "libGIFTAcURL2FTS/cc/CAcURL2FTS.cc:" << __LINE__ << ": XML ERROR: " 00206 << XML_ErrorString(XML_GetErrorCode(lParser)) 00207 << " at line " 00208 << XML_GetCurrentLineNumber(lParser) 00209 << endl; 00210 char lLine[10]; 00211 sprintf(lLine,"%d",__LINE__); 00212 00213 my_throw(new VEConfigurationError(string(string("libGIFTAcURL2FTS/cc/CAcURL2FTS.cc:") 00214 + string(lLine) 00215 + string("Could not read file ") 00216 + string(mURLToFeatureFileName)) 00217 .c_str())); 00218 } 00219 } 00220 cout << "Successfully processed" << endl; 00221 delete lBuffer; 00222 XML_ParserFree(lParser); 00223 } 00224 00225 00226 00227 cout << "URLFile " 00228 << mURLToFeatureFileName 00229 << " processed." 00230 << endl; 00231 mURLToFeatureFile.close(); 00232 gMutex->unlock(); 00233 }; CAcURL2FTS::operator bool()const{
| const string & CAcURL2FTS::getURLToFeatureFileName | ( | ) | const |
gives back the content of mURLToFeatureFileName
Definition at line 238 of file CAcURL2FTS.cc.
References mURLToFeatureFileName.
00238 { 00239 return mURLToFeatureFileName; 00240 };
| CAcURL2FTS::operator bool | ( | ) | const [virtual] |
Is this accessor up and working?
Implements CAccessorImplementation.
Reimplemented in CAcIFFileSystem, and CAcIFMeta.
Definition at line 234 of file CAcURL2FTS.cc.
References mWellConstructed.
00234 { 00235 return mWellConstructed; 00236 }
| int CAcURL2FTS::size | ( | ) | const [virtual] |
Give the number of elements stored in this accessor
Reimplemented from CAccessorImplementation.
Reimplemented in CAcIFFileSystem, and CAcIFMeta.
Definition at line 243 of file CAcURL2FTS.cc.
References CMutex::lock(), mIDToFFN, mMutexURL2FTS, and CMutex::unlock().
00243 { 00244 mMutexURL2FTS.lock(); 00245 int lReturnValue(mIDToFFN.size()); 00246 mMutexURL2FTS.unlock(); 00247 return lReturnValue; 00248 };
| pair< bool, string > CAcURL2FTS::URLToFFN | ( | const string & | inURL | ) | const |
gives the feature file name which corresponds to a given URL return value: pair of bool (does the feature file exsist) string (the feature file name)
Definition at line 251 of file CAcURL2FTS.cc.
References CMutex::lock(), mMutexURL2FTS, mURLToFFN, and CMutex::unlock().
00251 { 00252 mMutexURL2FTS.lock(); 00253 string_string_map::const_iterator lFound=mURLToFFN.find(inURL); 00254 00255 if(lFound != mURLToFFN.end()){ 00256 pair<bool,string> lReturnValue(make_pair(true,lFound->second)); 00257 mMutexURL2FTS.unlock(); 00258 return lReturnValue; 00259 }else{ 00260 // should be false here?? 00261 pair<bool,string> lReturnValue(make_pair(true,string(inURL+"does not exsist"))); 00262 mMutexURL2FTS.unlock(); 00263 return lReturnValue; 00264 } 00265 };
| void CAcURL2FTS::addImage | ( | string | inURL, | |
| string | inThumbnailURL, | |||
| string | inFeatureFileName | |||
| ) |
Add a new element to the file
Definition at line 91 of file CAcURL2FTS.cc.
References mID, CAccessorImplementation::mIDToAccessorElement, mIDToFFN, mURLToFFN, and CAccessorImplementation::mURLToID.
Referenced by newStartURL2FTSElement().
00091 { 00092 mURLToFFN.insert(make_pair(inURL,inFeatureFileName)); 00093 mIDToFFN.insert(make_pair(mID,inFeatureFileName)); 00094 mURLToID.insert(make_pair(inURL,mID)); 00095 mIDToAccessorElement.insert(make_pair(mID,CAccessorElement(mID, 00096 inURL, 00097 inThumbnailURL, 00098 inFeatureFileName))); 00099 mID++; 00100 }
gives the feature file name which corresponds to a given URL return value: pair of bool (does the feature file exsist) string (the feature file name)
Definition at line 267 of file CAcURL2FTS.cc.
References CMutex::lock(), mIDToFFN, mMutexURL2FTS, and CMutex::unlock().
00267 { 00268 mMutexURL2FTS.lock(); 00269 TID_string_map::const_iterator lFound=mIDToFFN.find(inID); 00270 00271 00272 if(lFound != mIDToFFN.end()){ 00273 pair<bool,string> lReturnValue(make_pair(true,lFound->second)); 00274 mMutexURL2FTS.unlock(); 00275 return lReturnValue; 00276 }else{ 00277 pair<bool,string> lReturnValue(make_pair(true,string("the requested id does not exsist"))); 00278 mMutexURL2FTS.unlock(); 00279 return lReturnValue; 00280 } 00281 };
friend class CAcIFFileSystem [friend] |
Definition at line 100 of file CAcURL2FTS.h.
| void newStartURL2FTSElement | ( | void * | inUserData, | |
| const char * | inElementName, | |||
| const char ** | inAttributes | |||
| ) | [friend] |
we construct this with a little help from this friend
Definition at line 46 of file CAcURL2FTS.cc.
Referenced by CAcURL2FTS().
00048 { 00049 00050 CAcURL2FTS* lAccessor=(CAcURL2FTS*)inUserData; 00051 00052 //cout << inElementName << endl; 00053 00054 string lElementName(inElementName); 00055 CAttributeList lAttributes(inAttributes); 00056 00057 if(lElementName=="image-list"){ 00058 lAccessor->mID=0; 00059 lAccessor->mURLPrefix=string(""); 00060 lAccessor->mThumbnailURLPrefix=string(""); 00061 if(lAttributes.stringReadAttribute("url-prefix").first){ 00062 lAccessor->mURLPrefix=lAttributes.stringReadAttribute("url-prefix").second; 00063 } 00064 if(lAttributes.stringReadAttribute("thumbnail-url-prefix").first){ 00065 lAccessor->mThumbnailURLPrefix=lAttributes.stringReadAttribute("thumbnail-url-prefix").second; 00066 } 00067 } 00068 if(lElementName=="image"){ 00069 string lURL=lAccessor->mURLPrefix+lAttributes.stringReadAttribute("url-postfix").second; 00070 string lThumbnailURL=lAccessor->mThumbnailURLPrefix+lAttributes.stringReadAttribute("thumbnail-url-postfix").second; 00071 string lFeatureFileName=lAttributes.stringReadAttribute("feature-file-name").second; 00072 00073 lAccessor->addImage(lURL,lThumbnailURL,lFeatureFileName); 00074 00075 // lAccessor->mURLToFFN.insert(make_pair(lURL,lFeatureFileName)); 00076 // lAccessor->mIDToFFN.insert(make_pair(lAccessor->mID,lFeatureFileName)); 00077 // lAccessor->mURLToID.insert(make_pair(lURL,lAccessor->mID)); 00078 // lAccessor->mIDToAccessorElement.insert(make_pair(lAccessor->mID,CAccessorElement(lAccessor->mID, 00079 // lURL, 00080 // lThumbnailURL, 00081 // lFeatureFileName))); 00082 // lAccessor->mID++; 00083 00084 //cout << lURL << endl; 00085 //cout << lThumbnailURL << endl; 00086 //cout << lFeatureFileName << endl; 00087 } 00088 }
| void newEndURL2FTSElement | ( | void * | inUserData, | |
| const char * | inElementName | |||
| ) | [friend] |
we construct this with a little help from this friend
Definition at line 102 of file CAcURL2FTS.cc.
Referenced by CAcURL2FTS().
bool CAcURL2FTS::mWellConstructed [private] |
is this well constructed
Definition at line 69 of file CAcURL2FTS.h.
Referenced by CAcURL2FTS(), and operator bool().
TID CAcURL2FTS::mID [protected] |
the ID of the next element
Definition at line 74 of file CAcURL2FTS.h.
Referenced by addImage(), and newStartURL2FTSElement().
string CAcURL2FTS::mURLPrefix [protected] |
the url-prefix for the image list
Definition at line 78 of file CAcURL2FTS.h.
Referenced by newStartURL2FTSElement().
string CAcURL2FTS::mThumbnailURLPrefix [protected] |
the thumbnail-url-prefix for the image list
Definition at line 82 of file CAcURL2FTS.h.
Referenced by newStartURL2FTSElement().
CMutex CAcURL2FTS::mMutexURL2FTS [protected] |
the mutex for multithreading the name is intended to be unique and immune against inheritance...
Definition at line 88 of file CAcURL2FTS.h.
Referenced by IDToFFN(), size(), and URLToFFN().
string_string_map CAcURL2FTS::mURLToFFN [protected] |
map from the url of an image to the name of the feature file for this image
Definition at line 90 of file CAcURL2FTS.h.
Referenced by addImage(), CAcURL2FTS(), and URLToFFN().
TID_string_map CAcURL2FTS::mIDToFFN [protected] |
map from the id of an image to the name of the feature file for this image
Definition at line 92 of file CAcURL2FTS.h.
Referenced by addImage(), CAcURL2FTS(), IDToFFN(), and size().
ifstream CAcURL2FTS::mURLToFeatureFile [mutable, protected] |
string CAcURL2FTS::mURLToFeatureFileName [protected] |
Name of the file that contains pairs of URL and the Feature file that belongs to the URL
Definition at line 98 of file CAcURL2FTS.h.
Referenced by CAcURL2FTS(), and getURLToFeatureFileName().
1.5.6