#include <CAlgorithmCollection.h>

Public Member Functions | |
| CAlgorithm * | getAlgorithmInConstruction () |
| void | startAlgorithmConstruction (CAlgorithm *inAlgorithm) |
| CAlgorithmCollection (string inConfigFileName) | |
| ~CAlgorithmCollection () | |
| void | addAlgorithm (CAlgorithm *inAlgorithm) |
| adding an algorithm with a given ID/name and a given base | |
| CAlgorithm & | getAlgorithmByType (const string &inType) const |
| bool | containsAlgorithmByType (const string &inType) const |
| CAlgorithm * | makeAlgorithmByType (const string &inType) const |
| CAlgorithm * | getDefaultAlgorithm () const |
| CAlgorithm * | makeDefaultAlgorithm () const |
| CXMLElement * | getAlgorithmList (const CXMLElement &inGetAlgorithms) const |
| string | toXML (bool inIsPrivate=false) const |
| CXMLElement * | toXMLElement () const |
| CQuery * | makeQuery (const string &inBaseType, CAccessorAdminCollection &inAccessorAdminCollection, CAlgorithm &inAlgorithm, CStaticQueryFactory &inFactory) |
Protected Types | |
| typedef map< string, CAlgorithm * > | CContent |
Protected Member Functions | |
| CContent::const_iterator | begin () const |
| CContent::const_iterator | end () const |
Protected Attributes | |
| CAlgorithm * | mAlgorithmInConstruction |
| CContent | mContent |
We provide a list of algorithms which correspond to so-called "basetypes". At present there are only two: bayesian and inverted_file.
Each algorithm which will be configured in the configuration file will have a basetype. Corresponding to this there is generated a CQuery structure for each algorithm out of the configuration.
Wolfgang Mueller
Definition at line 58 of file CAlgorithmCollection.h.
typedef map<string,CAlgorithm*> CAlgorithmCollection::CContent [protected] |
The content of an algorithm collection is a map between algorihm type and a pointer to the corresponding CAlgorithm
Definition at line 66 of file CAlgorithmCollection.h.
| CAlgorithmCollection::CAlgorithmCollection | ( | string | inConfigFileName | ) |
Constructor
Definition at line 139 of file CAlgorithmCollection.cc.
References endAlgorithmCollectionElement(), my_throw, and startAlgorithmCollectionElement().
00139 : 00140 mAlgorithmInConstruction(0) 00141 { 00142 00143 ifstream lConfigFile(inConfigFileName.c_str()); 00144 00145 if(lConfigFile){ 00146 00147 00148 lConfigFile.seekg(0,ios::end); 00149 int lSize=lConfigFile.tellg(); 00150 char lConfigFileContent[lSize+1]; 00151 00152 lConfigFile.seekg(0,ios::beg); 00153 lConfigFile.read(lConfigFileContent, 00154 lSize); 00155 00156 00157 lConfigFileContent[lSize]=0; 00158 00159 cout << "gift: CAlgorithmCollection: The following is the config file " << endl 00160 << "located at \"" << inConfigFileName << "\" as read by this program: " 00161 << endl; 00162 cout << lConfigFileContent 00163 << endl 00164 << "This config file content will now be parsed by an XML parser " << endl 00165 << "If error messages occur, these are related to the content shown above." << endl; 00166 00167 XML_Parser lParser = XML_ParserCreate(NULL);//default encoding 00168 XML_SetUserData(lParser, 00169 this); 00170 XML_SetElementHandler(lParser, 00171 startAlgorithmCollectionElement, 00172 endAlgorithmCollectionElement); 00173 int lDone=true; 00174 do { 00175 if (!XML_Parse(lParser, 00176 lConfigFileContent, 00177 lSize, 00178 lDone)) { 00179 cerr << "CAlgorithmCollection.cc: XML ERROR: " 00180 << XML_ErrorString(XML_GetErrorCode(lParser)) 00181 << " at line " 00182 << XML_GetCurrentLineNumber(lParser) 00183 << endl 00184 << "file was:[" 00185 << endl 00186 << lConfigFileContent 00187 << "]" 00188 << endl; 00189 00190 my_throw(GIFTException("XML Error")); 00191 } 00192 } while (!lDone); 00193 00194 00195 XML_ParserFree(lParser); 00196 cout << "gift: CAlgorithmCollection: The config file has " << endl 00197 << "been parsed successfully by CAlgorithmCollection" << endl 00198 << "maybe other parts of the program will also parse" << endl 00199 << "the same config file. " << endl; 00200 00201 }else{ 00202 //here I get an internal compiler error with egcs 00203 00204 my_throw(VENotFound(inConfigFileName.c_str())); 00205 cerr << "gift: this line should not be reached" 00206 << endl; 00207 cerr << "gift: I could not find config file: " 00208 << inConfigFileName 00209 << endl; 00210 exit(1); 00211 } 00212 00213 }
| CAlgorithmCollection::~CAlgorithmCollection | ( | ) |
Destructor destroys all members of CContent
Definition at line 215 of file CAlgorithmCollection.cc.
References mContent.
00215 { 00216 for(CContent::iterator i=mContent.begin(); 00217 i!=mContent.end(); 00218 i++){ 00219 delete i->second; 00220 } 00221 };
| CAlgorithmCollection::CContent::const_iterator CAlgorithmCollection::begin | ( | ) | const [protected] |
for being able to read all the content
Definition at line 224 of file CAlgorithmCollection.cc.
References mContent.
00224 { 00225 return mContent.begin(); 00226 }
| CAlgorithmCollection::CContent::const_iterator CAlgorithmCollection::end | ( | ) | const [protected] |
for being able to read all the content
Definition at line 229 of file CAlgorithmCollection.cc.
References mContent.
Referenced by toXMLElement().
00229 { 00230 return mContent.end(); 00231 }
| CAlgorithm * CAlgorithmCollection::getAlgorithmInConstruction | ( | ) |
returns a pointer to the algorithm in construction
Definition at line 346 of file CAlgorithmCollection.cc.
References mAlgorithmInConstruction.
Referenced by endAlgorithmCollectionElement(), and startAlgorithmCollectionElement().
00346 { 00347 return mAlgorithmInConstruction; 00348 }
| void CAlgorithmCollection::startAlgorithmConstruction | ( | CAlgorithm * | inAlgorithm | ) |
Definition at line 350 of file CAlgorithmCollection.cc.
References mAlgorithmInConstruction.
Referenced by endAlgorithmCollectionElement(), and startAlgorithmCollectionElement().
00351 { 00352 mAlgorithmInConstruction=inAlgorithm; 00353 }
| void CAlgorithmCollection::addAlgorithm | ( | CAlgorithm * | inAlgorithm | ) |
adding an algorithm with a given ID/name and a given base
adding a completely built algorithm XML document tree
Definition at line 234 of file CAlgorithmCollection.cc.
References CXMLElement::check(), CAlgorithm::getType(), and mContent.
Referenced by endAlgorithmCollectionElement().
00234 { 00235 inAlgorithm->check(); 00236 mContent.insert(make_pair(inAlgorithm->getType().second, 00237 inAlgorithm)); 00238 };
| CAlgorithm & CAlgorithmCollection::getAlgorithmByType | ( | const string & | inType | ) | const |
Algorithm for TYPE => permits configuring probably only the pointered version is interesting
Definition at line 244 of file CAlgorithmCollection.cc.
References mContent.
Referenced by CAlgorithm::configure(), and CSessionManager::getPropertySheet().
00244 { 00245 CContent::const_iterator lFound(mContent.find(inType)); 00246 if(lFound!=mContent.end()){ 00247 return *lFound->second; 00248 }else{ 00249 // return a default algorithm, if none was found. 00250 00251 cout << "returning a default algorithm:" 00252 << mContent.begin()->first 00253 << ": " 00254 << mContent.begin()->second 00255 << endl; 00256 00257 if(mContent.find("adefault")!=mContent.end()){ 00258 return *mContent.find("adefault")->second; 00259 } 00260 assert(mContent.size()); 00261 return *mContent.begin()->second; 00262 } 00263 }
| bool CAlgorithmCollection::containsAlgorithmByType | ( | const string & | inType | ) | const |
Algorithm for TYPE => permits configuring probably only the pointered version is interesting
Definition at line 240 of file CAlgorithmCollection.cc.
References mContent.
Referenced by CAlgorithm::configure().
00240 { 00241 CContent::const_iterator lFound(mContent.find(inType)); 00242 return(lFound!=mContent.end()); 00243 };
| CAlgorithm * CAlgorithmCollection::makeAlgorithmByType | ( | const string & | inType | ) | const |
Creates a new algorithm for agiven type by cloning what you would get with getAlgorithm. The values made here will be used as default in the subsequent CQuery building process.
Definition at line 264 of file CAlgorithmCollection.cc.
References CAlgorithm::clone(), and mContent.
00264 { 00265 CContent::const_iterator lFound(mContent.find(inType)); 00266 if(lFound!=mContent.end()){ 00267 return lFound->second->clone(); 00268 }else{ 00269 return 0; 00270 } 00271 };
| CAlgorithm * CAlgorithmCollection::getDefaultAlgorithm | ( | ) | const |
A default algorithm for the default session This algorithm will be given by the ONE ALGORITHM which has the type "adefault"
Definition at line 272 of file CAlgorithmCollection.cc.
References mContent, and my_assert.
Referenced by makeDefaultAlgorithm().
00272 { 00273 //at present, take simply the first element 00274 //it might be an xml tag in the future 00275 00276 cout << "We have " 00277 << mContent.size() 00278 << " algorithms in the algorithm collection." 00279 << endl; 00280 00281 00282 CContent::const_iterator lFound=mContent.find(string("adefault")); 00283 00284 cout << __FILE__ << ":" << __LINE__ << ":default algorithm found" << endl; 00285 00286 my_assert(lFound!=mContent.end(), 00287 "There SHOULD be a 'adefault' algorithm in the config file!"); 00288 00289 00290 00291 return lFound->second; 00292 };
| CAlgorithm * CAlgorithmCollection::makeDefaultAlgorithm | ( | ) | const |
creates a copy of what you'd get with the above function get...
Definition at line 293 of file CAlgorithmCollection.cc.
References CXMLElement::check(), and getDefaultAlgorithm().
Referenced by CSessionManager::newSession().
00293 { 00294 //at present, take simply the first element 00295 //it might be an xml tag in the future 00296 00297 CAlgorithm* lDefaultAlgorithm(getDefaultAlgorithm()); 00298 if(lDefaultAlgorithm){ 00299 cout << __FILE__ << ":" << __LINE__ << ":going to check default algorithm" << endl; 00300 lDefaultAlgorithm->check(); 00301 } 00302 00303 cout << __FILE__ << ":" << __LINE__ << ":checked, now copying " << endl; 00304 CAlgorithm* lReturnValue(new CAlgorithm(*lDefaultAlgorithm)); 00305 cout << __FILE__ << ":" << __LINE__ << ":copied, now checking again " << endl; 00306 lReturnValue->check(); 00307 return lReturnValue; 00308 };
| CXMLElement * CAlgorithmCollection::getAlgorithmList | ( | const CXMLElement & | inGetAlgorithms | ) | const |
For handshaking: This makes you a list of all algorithms which work with a given query paradigm.
Definition at line 340 of file CAlgorithmCollection.cc.
| string CAlgorithmCollection::toXML | ( | bool | inIsPrivate = false |
) | const |
for shandshake and for state output
Reimplemented in CSessionManager.
Definition at line 310 of file CAlgorithmCollection.cc.
References mrml_const::algorithm_list, mContent, CXMLHelper::setEnd(), CXMLHelper::setName(), and CXMLHelper::toString().
Referenced by CSessionManager::toXML().
00310 { 00311 CXMLHelper lHelper; 00312 lHelper.setName(mrml_const::algorithm_list); 00313 string lReturnValue=lHelper.toString()+"\n"; 00314 00315 for(CContent::const_iterator i=mContent.begin(); 00316 i!=mContent.end(); 00317 i++){ 00318 i->second->toXML(lReturnValue); 00319 } 00320 lHelper.setEnd(); 00321 lReturnValue+=lHelper.toString()+"\n"; 00322 return lReturnValue; 00323 }
| CXMLElement * CAlgorithmCollection::toXMLElement | ( | ) | const |
for get-algorithms: the output is an CXMLElement, containing an algorithm-list element.
Definition at line 326 of file CAlgorithmCollection.cc.
References CXMLElement::addChild(), mrml_const::algorithm_list, end(), mContent, and CXMLElement::moveUp().
Referenced by CSessionManager::getAlgorithms().
00326 { 00327 CXMLElement* lReturnValue(new CXMLElement(mrml_const::algorithm_list,0)); 00328 00329 for(CContent::const_iterator i=mContent.begin(); 00330 i!=end(); 00331 i++){ 00332 CXMLElement* lNewChild=new CXMLElement(*i->second); 00333 lReturnValue->addChild(lNewChild); 00334 lReturnValue->moveUp(); 00335 } 00336 return lReturnValue; 00337 }
| CQuery * CAlgorithmCollection::makeQuery | ( | const string & | inBaseType, | |
| CAccessorAdminCollection & | inAccessorAdminCollection, | |||
| CAlgorithm & | inAlgorithm, | |||
| CStaticQueryFactory & | inFactory | |||
| ) |
handed through to the CStaticQueryFactory
Definition at line 355 of file CAlgorithmCollection.cc.
References CStaticQueryFactory::makeQuery().
00358 { 00359 00360 assert(!"this should not be called"); 00361 return inFactory.makeQuery(inBaseType, 00362 inAccessorAdminCollection, 00363 inAlgorithm); 00364 }
CAlgorithm* CAlgorithmCollection::mAlgorithmInConstruction [protected] |
as the name sais
Definition at line 61 of file CAlgorithmCollection.h.
Referenced by getAlgorithmInConstruction(), and startAlgorithmConstruction().
CContent CAlgorithmCollection::mContent [protected] |
Definition at line 70 of file CAlgorithmCollection.h.
Referenced by addAlgorithm(), begin(), containsAlgorithmByType(), end(), getAlgorithmByType(), getDefaultAlgorithm(), makeAlgorithmByType(), toXML(), toXMLElement(), and ~CAlgorithmCollection().
1.5.6