#include <sheet_id.h>
Nevrax France
Definition at line 47 of file sheet_id.h.
Public Member Functions | |
uint32 | asInt () const |
void | build (uint32 shortId, uint8 type) |
bool | build (const std::string &sheetName) |
CSheetId (const std::string &sheetName) | |
CSheetId (uint32 sheetRef=0) | |
uint32 | getShortId () const |
uint8 | getType () const |
bool | operator!= (const CSheetId &sheetRef) const |
bool | operator< (const CSheetId &sheetRef) const |
CSheetId & | operator= (uint32 sheetRef) |
CSheetId & | operator= (const std::string &sheetName) |
CSheetId & | operator= (const CSheetId &sheetId) |
bool | operator== (const CSheetId &sheetRef) const |
void | serial (NLMISC::IStream &f) throw (NLMISC::EStream) |
std::string | toString () const |
Static Public Member Functions | |
void | buildIdVector (std::vector< CSheetId > &result, std::vector< std::string > &resultFilenames, const std::string &fileExtension) |
void | buildIdVector (std::vector< CSheetId > &result, const std::string &fileExtension) |
void | buildIdVector (std::vector< CSheetId > &result, std::vector< std::string > &resultFilenames, uint8 type) |
void | buildIdVector (std::vector< CSheetId > &result, uint8 type) |
void | buildIdVector (std::vector< CSheetId > &result) |
void | display (uint8 type) |
void | display () |
const std::string & | fileExtensionFromType (uint8 type) |
void | init (bool removeUnknownSheet=true) |
uint32 | typeFromFileExtension (const std::string &fileExtension) |
void | uninit () |
Static Public Attributes | |
const CSheetId | Unknown |
Unknow CSheetId is similar as an NULL pointer. | |
Static Private Member Functions | |
void | cbFileChange (const std::string &filename) |
void | loadSheetAlias () |
void | loadSheetId () |
Private Attributes | |
TSheetId | _Id |
Static Private Attributes | |
CChar | _AllStrings |
std::vector< std::string > | _FileExtensions |
bool | _Initialised = false |
bool | _RemoveUnknownSheet = true |
std::map< std::string, uint32 > | _SheetAliasToId |
std::map< uint32, std::string > | _SheetIdToAlias |
CStaticMap< uint32, CChar > | _SheetIdToName |
CStaticMap< CChar, uint32, CCharComp > | _SheetNameToId |
|
Constructor Definition at line 57 of file sheet_id.h. References NLMISC::CSheetId::TSheetId::Id, and uint32. Referenced by loadSheetAlias().
|
|
Constructor Definition at line 66 of file sheet_id.cpp. References build(), and nlwarning.
|
|
Return the **whole** sheet id (id+type) Definition at line 83 of file sheet_id.h. References NLMISC::CSheetId::TSheetId::Id, and uint32. Referenced by NLMISC::CHashBySheetId::operator()(), operator<(), and operator=().
|
|
Definition at line 620 of file sheet_id.cpp. References NLMISC::CSheetId::TSheetId::IdInfos, type, uint32, and uint8.
|
|
Definition at line 81 of file sheet_id.cpp. References _Initialised, _SheetAliasToId, _SheetNameToId, NLMISC::CStaticMap< CChar, uint32, CCharComp >::end(), NLMISC::CStaticMap< CChar, uint32, CCharComp >::find(), NLMISC::CSheetId::TSheetId::Id, nlassert, NLMISC::CSheetId::CChar::Ptr, and NLMISC::strlwr(). Referenced by CSheetId().
00082 { 00083 nlassert(_Initialised); 00084 00085 map<string,uint32>::const_iterator itIdAlias; 00086 00087 itIdAlias = _SheetAliasToId.find( strlwr(sheetName) ); 00088 if( itIdAlias != _SheetAliasToId.end() ) 00089 { 00090 _Id.Id = (*itIdAlias).second; 00091 return true; 00092 } 00093 00094 00095 CStaticMap<CChar,uint32,CCharComp>::const_iterator itId; 00096 CChar c; 00097 c.Ptr = new char [sheetName.size()+1]; 00098 strcpy(c.Ptr, sheetName.c_str()); 00099 strlwr(c.Ptr); 00100 00101 itId = _SheetNameToId.find (c); 00102 delete [] c.Ptr; 00103 if( itId != _SheetNameToId.end() ) 00104 { 00105 _Id.Id = (*itId).second; 00106 return true; 00107 } 00108 return false; 00109 00110 } |
|
Definition at line 577 of file sheet_id.cpp. References buildIdVector(), type, typeFromFileExtension(), uint32, and uint8.
00578 { 00579 uint32 type=typeFromFileExtension(fileExtension); 00580 if (type!=(uint32)~0) 00581 buildIdVector(result,resultFilenames, (uint8)type); 00582 00583 } // buildIdVector // |
|
Definition at line 565 of file sheet_id.cpp. References buildIdVector(), type, typeFromFileExtension(), uint32, and uint8.
00566 { 00567 uint32 type=typeFromFileExtension(fileExtension); 00568 if (type!=(uint32)~0) 00569 buildIdVector(result,(uint8)type); 00570 00571 } // buildIdVector // |
|
Definition at line 540 of file sheet_id.cpp. References _Initialised, _SheetIdToName, NLMISC::CStaticMap< uint32, CChar >::begin(), NLMISC::CStaticMap< uint32, CChar >::end(), NLMISC::CSheetId::TSheetId::Id, NLMISC::CSheetId::TSheetId::IdInfos, nlassert, type, and uint8.
00541 { 00542 nlassert(_Initialised); 00543 00544 CStaticMap<uint32,CChar>::const_iterator itStr; 00545 for( itStr = _SheetIdToName.begin(); itStr != _SheetIdToName.end(); ++itStr ) 00546 { 00547 // work out the type value for this entry in the map 00548 TSheetId sheetId; 00549 sheetId.Id=(*itStr).first; 00550 00551 // decide whether or not to use the entry 00552 if (type==sheetId.IdInfos.Type) 00553 { 00554 result.push_back( (CSheetId)sheetId.Id ); 00555 resultFilenames.push_back( (*itStr).second.Ptr ); 00556 } 00557 } 00558 00559 } // buildIdVector // |
|
Definition at line 516 of file sheet_id.cpp. References _Initialised, _SheetIdToName, NLMISC::CStaticMap< uint32, CChar >::begin(), NLMISC::CStaticMap< uint32, CChar >::end(), NLMISC::CSheetId::TSheetId::Id, NLMISC::CSheetId::TSheetId::IdInfos, nlassert, type, and uint8.
00517 { 00518 nlassert(_Initialised); 00519 00520 CStaticMap<uint32,CChar>::const_iterator itStr; 00521 for( itStr = _SheetIdToName.begin(); itStr != _SheetIdToName.end(); ++itStr ) 00522 { 00523 // work out the type value for this entry in the map 00524 TSheetId sheetId; 00525 sheetId.Id=(*itStr).first; 00526 00527 // decide whether or not to use the entry 00528 if (type==sheetId.IdInfos.Type) 00529 { 00530 result.push_back( (CSheetId)sheetId.Id ); 00531 } 00532 } 00533 00534 } // buildIdVector // |
|
Generate a vector of all the sheet ids of a given type This operation is non-destructive, the new entries are appended to the result vector note: fileExtension *not* include the '.' eg "bla" and *not* ".bla" Definition at line 499 of file sheet_id.cpp. References _Initialised, _SheetIdToName, NLMISC::CStaticMap< uint32, CChar >::begin(), NLMISC::CStaticMap< uint32, CChar >::end(), and nlassert. Referenced by buildIdVector(), and loadForm().
00500 { 00501 nlassert(_Initialised); 00502 00503 CStaticMap<uint32,CChar>::const_iterator itStr; 00504 for( itStr = _SheetIdToName.begin(); itStr != _SheetIdToName.end(); ++itStr ) 00505 { 00506 result.push_back( (CSheetId)(*itStr).first ); 00507 } 00508 00509 } // buildIdVector // |
|
Definition at line 55 of file sheet_id.cpp. References loadSheetId(), and nlinfo. Referenced by init().
00056 { 00057 nlinfo ("SHEETID: %s changed, reload it", filename.c_str()); 00058 00059 loadSheetId(); 00060 } |
|
Definition at line 472 of file sheet_id.cpp. References _Initialised, _SheetIdToName, NLMISC::CStaticMap< uint32, CChar >::begin(), NLMISC::CStaticMap< uint32, CChar >::end(), NLMISC::CSheetId::TSheetId::Id, NLMISC::CSheetId::TSheetId::IdInfos, nlassert, nlinfo, type, and uint8.
00473 { 00474 nlassert(_Initialised); 00475 00476 CStaticMap<uint32,CChar>::const_iterator itStr; 00477 for( itStr = _SheetIdToName.begin(); itStr != _SheetIdToName.end(); ++itStr ) 00478 { 00479 // work out the type value for this entry in the map 00480 TSheetId sheetId; 00481 sheetId.Id=(*itStr).first; 00482 00483 // decide whether or not to dsiplay the entry 00484 if (type==sheetId.IdInfos.Type) 00485 { 00486 //nlinfo("%d %s",(*itStr).first,(*itStr).second.c_str()); 00487 nlinfo("SHEETID: (%08x %d) %s",(*itStr).first,(*itStr).first,(*itStr).second.Ptr); 00488 } 00489 } 00490 00491 } // display // |
|
Display the list of valid sheet ids with their associated file names if (type != -1) then restrict list to given type Definition at line 453 of file sheet_id.cpp. References _Initialised, _SheetIdToName, NLMISC::CStaticMap< uint32, CChar >::begin(), NLMISC::CStaticMap< uint32, CChar >::end(), nlassert, and nlinfo.
00454 { 00455 nlassert(_Initialised); 00456 00457 CStaticMap<uint32,CChar>::const_iterator itStr; 00458 for( itStr = _SheetIdToName.begin(); itStr != _SheetIdToName.end(); ++itStr ) 00459 { 00460 //nlinfo("%d %s",(*itStr).first,(*itStr).second.c_str()); 00461 nlinfo("SHEETID: (%08x %d) %s",(*itStr).first,(*itStr).first,(*itStr).second.Ptr); 00462 } 00463 00464 } // display // |
|
Convert between file extensions and numeric sheet types note: fileExtension *not* include the '.' eg "bla" and *not* ".bla" Definition at line 607 of file sheet_id.cpp. References _FileExtensions, _Initialised, nlassert, type, and uint8.
00608 { 00609 nlassert(_Initialised); 00610 nlassert(type<256); 00611 00612 return _FileExtensions[type]; 00613 00614 } // fileExtensionFromType // |
|
Return the sheet sub id (sub part of the sheetid) Definition at line 93 of file sheet_id.h. References NLMISC::CSheetId::TSheetId::IdInfos, and uint32.
|
|
Return the sheet type (sub part of the sheetid) Definition at line 88 of file sheet_id.h. References NLMISC::CSheetId::TSheetId::IdInfos, and uint8.
|
|
Load the association sheet ref / sheet name Definition at line 304 of file sheet_id.cpp. References _Initialised, _RemoveUnknownSheet, cbFileChange(), loadSheetAlias(), and loadSheetId(). Referenced by loadForm().
00305 { 00306 // allow multiple calls to init in case libraries depending on sheetid call this init from their own 00307 if (_Initialised) 00308 return; 00309 00310 CFile::addFileChangeCallback ("sheet_id.bin", cbFileChange); 00311 00312 _RemoveUnknownSheet = removeUnknownSheet; 00313 00314 loadSheetId (); 00315 _Initialised=true; 00316 loadSheetAlias (); 00317 00318 00319 } // init // |
|
Definition at line 236 of file sheet_id.cpp. References _RemoveUnknownSheet, _SheetAliasToId, _SheetIdToAlias, CSheetId(), file, nlinfo, NLMISC::strlwr(), uint, and uint32. Referenced by init().
00237 { 00238 // Open the sheet id to sheet alias association 00239 CIFile file; 00240 if(file.open(CPath::lookup("alias.packed_sheets", false, false))) 00241 { 00242 // clear entries 00243 _SheetIdToAlias.clear (); 00244 _SheetAliasToId.clear (); 00245 00246 // Get the map. 00247 uint32 nbEntries; 00248 file.serial (nbEntries); 00249 file.setVersionException (false, false); 00250 uint ver = 1; 00251 file.serialVersion(ver); 00252 file.serialCont(_SheetIdToAlias); 00253 00254 // Close the file. 00255 file.close(); 00256 00257 if (_RemoveUnknownSheet) 00258 { 00259 //uint32 nbfiles = _SheetIdToAlias.size(); 00260 00261 // now we remove all files that not available 00262 map<uint32,string>::iterator itStr2; 00263 for( itStr2 = _SheetIdToAlias.begin(); itStr2 != _SheetIdToAlias.end(); ) 00264 { 00265 if (CPath::exists (CSheetId((*itStr2).first).toString())) 00266 { 00267 ++itStr2; 00268 } 00269 else 00270 { 00271 map<uint32,string>::iterator olditStr = itStr2; 00272 itStr2++; 00273 _SheetIdToAlias.erase (olditStr); 00274 } 00275 } 00276 } 00277 00278 // build the invert map 00279 map<uint32,string>::iterator itStr; 00280 for( itStr = _SheetIdToAlias.begin(); itStr != _SheetIdToAlias.end(); ++itStr ) 00281 { 00282 // add entry to the inverse map 00283 if( !(*itStr).second.empty() ) 00284 { 00285 _SheetAliasToId.insert( make_pair(strlwr((*itStr).second),(*itStr).first) ); 00286 } 00287 else 00288 { 00289 //nlwarning("<CSheetId::loadSheetAlias> The sheet %s doesn't have alias",CSheetId((*itStr).first).toString().c_str()); 00290 } 00291 } 00292 } 00293 else 00294 { 00295 nlinfo("SHEETID: Can't open the file alias.packed_sheets"); 00296 } 00297 } |
|
Definition at line 112 of file sheet_id.cpp. References _AllStrings, _FileExtensions, _RemoveUnknownSheet, _SheetIdToName, _SheetNameToId, NLMISC::CStaticMap< CChar, uint32, CCharComp >::add(), NLMISC::CStaticMap< uint32, CChar >::add(), NLMISC::CStaticMap< uint32, CChar >::begin(), NLMISC::CStaticMap< CChar, uint32, CCharComp >::clear(), NLMISC::CStaticMap< uint32, CChar >::clear(), NLMISC::contReset(), NLMISC::CStaticMap< uint32, CChar >::end(), NLMISC::CStaticMap< CChar, uint32, CCharComp >::endAdd(), file, NLMISC::CSheetId::TSheetId::Id, NLMISC::CSheetId::TSheetId::IdInfos, nlerror, nlinfo, NLMISC::CSheetId::CChar::Ptr, NLMISC::CStaticMap< CChar, uint32, CCharComp >::reserve(), NLMISC::CStaticMap< uint32, CChar >::reserve(), NLMISC::CStaticMap< uint32, CChar >::size(), NLMISC::strlwr(), type, uint32, and uint8. Referenced by cbFileChange(), and init().
00113 { 00114 // Open the sheet id to sheet file name association 00115 CIFile file; 00116 std::string path = CPath::lookup("sheet_id.bin", false, false); 00117 if(!path.empty() && file.open(path)) 00118 { 00119 // clear entries 00120 _FileExtensions.clear (); 00121 _SheetIdToName.clear (); 00122 _SheetNameToId.clear (); 00123 00124 // reserve space for the vector of file extensions 00125 _FileExtensions.resize(256); 00126 00127 // Get the map from the file 00128 map<uint32,string> tempMap; 00129 contReset(tempMap); 00130 file.serialCont(tempMap); 00131 file.close(); 00132 00133 if (_RemoveUnknownSheet) 00134 { 00135 uint32 removednbfiles = 0; 00136 uint32 nbfiles = tempMap.size(); 00137 00138 // now we remove all files that not available 00139 map<uint32,string>::iterator itStr2; 00140 for( itStr2 = tempMap.begin(); itStr2 != tempMap.end(); ) 00141 { 00142 if (CPath::exists ((*itStr2).second)) 00143 { 00144 ++itStr2; 00145 } 00146 else 00147 { 00148 map<uint32,string>::iterator olditStr = itStr2; 00149 //nldebug ("Removing file '%s' from CSheetId because the file not exists", (*olditStr).second.c_str ()); 00150 itStr2++; 00151 tempMap.erase (olditStr); 00152 removednbfiles++; 00153 } 00154 } 00155 nlinfo ("SHEETID: Removed %d files on %d from CSheetId because these files doesn't exists", removednbfiles, nbfiles); 00156 } 00157 00158 // Convert the map to one big string and 1 static map (id to name) 00159 { 00160 // Get the number and size of all strings 00161 vector<CChar> tempVec; // Used to initialise the first map 00162 uint32 nNb = 0; 00163 uint32 nSize = 0; 00164 map<uint32,string>::const_iterator it = tempMap.begin(); 00165 while (it != tempMap.end()) 00166 { 00167 nSize += it->second.size()+1; 00168 nNb++; 00169 it++; 00170 } 00171 00172 // Make the big string (composed of all strings) and a vector referencing each string 00173 tempVec.resize(nNb); 00174 _AllStrings.Ptr = new char[nSize]; 00175 it = tempMap.begin(); 00176 nSize = 0; 00177 nNb = 0; 00178 while (it != tempMap.end()) 00179 { 00180 tempVec[nNb].Ptr = _AllStrings.Ptr+nSize; 00181 strcpy(_AllStrings.Ptr+nSize, it->second.c_str()); 00182 strlwr(_AllStrings.Ptr+nSize); 00183 nSize += it->second.size()+1; 00184 nNb++; 00185 it++; 00186 } 00187 00188 // Finally build the static map (id to name) 00189 _SheetIdToName.reserve(tempVec.size()); 00190 it = tempMap.begin(); 00191 nNb = 0; 00192 while (it != tempMap.end()) 00193 { 00194 _SheetIdToName.add(pair<uint32, CChar>::pair(it->first, CChar(tempVec[nNb]))); 00195 00196 nNb++; 00197 it++; 00198 } 00199 00200 // The vector of all small string is not needed anymore we have all the info in 00201 // the static map and with the pointer AllStrings referencing the beginning. 00202 } 00203 00204 // Build the invert map (Name to Id) & file extension vector 00205 { 00206 uint32 nSize = _SheetIdToName.size(); 00207 _SheetNameToId.reserve(nSize); 00208 CStaticMap<uint32,CChar>::iterator itStr; 00209 for( itStr = _SheetIdToName.begin(); itStr != _SheetIdToName.end(); ++itStr ) 00210 { 00211 // add entry to the inverse map 00212 _SheetNameToId.add( make_pair((*itStr).second, (*itStr).first) ); 00213 00214 // work out the type value for this entry in the map 00215 TSheetId sheetId; 00216 sheetId.Id=(*itStr).first; 00217 uint8 type= sheetId.IdInfos.Type; 00218 00219 // check whether we need to add an entry to the file extensions vector 00220 if (_FileExtensions[type].empty()) 00221 { 00222 // find the file extension part of the given file name 00223 _FileExtensions[type]=strlwr(CFile::getExtension((*itStr).second.Ptr)); 00224 } 00225 nSize--; 00226 } 00227 _SheetNameToId.endAdd(); 00228 } 00229 } 00230 else 00231 { 00232 nlerror("<CSheetId::init> Can't open the file sheet_id.bin"); 00233 } 00234 } |
|
Operator != Definition at line 123 of file sheet_id.h. References _Id, and NLMISC::CSheetId::TSheetId::Id.
|
|
Operator< Definition at line 409 of file sheet_id.cpp. References _Initialised, asInt(), NLMISC::CSheetId::TSheetId::Id, and nlassert.
|
|
Operator= Definition at line 393 of file sheet_id.cpp. References _Initialised, NLMISC::CSheetId::TSheetId::Id, nlassert, and uint32.
|
|
Operator= Definition at line 356 of file sheet_id.cpp. References _Initialised, _SheetAliasToId, _SheetNameToId, NLMISC::CStaticMap< CChar, uint32, CCharComp >::end(), NLMISC::CStaticMap< CChar, uint32, CCharComp >::find(), NLMISC::CSheetId::TSheetId::Id, nlassert, NLMISC::CSheetId::CChar::Ptr, and NLMISC::strlwr().
00357 { 00358 nlassert(_Initialised); 00359 00360 map<string,uint32>::const_iterator itIdAlias; 00361 00362 itIdAlias = _SheetAliasToId.find( strlwr(sheetName) ); 00363 if( itIdAlias != _SheetAliasToId.end() ) 00364 { 00365 _Id.Id = (*itIdAlias).second; 00366 return *this; 00367 } 00368 00369 00370 CStaticMap<CChar,uint32,CCharComp>::const_iterator itId; 00371 CChar c; 00372 c.Ptr = new char [sheetName.size()+1]; 00373 strcpy(c.Ptr, sheetName.c_str()); 00374 strlwr(c.Ptr); 00375 00376 itId = _SheetNameToId.find (c); 00377 delete [] c.Ptr; 00378 if( itId != _SheetNameToId.end() ) 00379 { 00380 _Id.Id = (*itId).second; 00381 return *this; 00382 } 00383 *this = Unknown; 00384 return *this; 00385 00386 } // operator= // |
|
Operator= Definition at line 335 of file sheet_id.cpp. References _Initialised, asInt(), NLMISC::CSheetId::TSheetId::Id, and nlassert.
|
|
Operator== Definition at line 118 of file sheet_id.h. References _Id, and NLMISC::CSheetId::TSheetId::Id.
|
|
Serial Definition at line 137 of file sheet_id.h. References NLMISC::CSheetId::TSheetId::Id.
|
|
Return the sheet id as a string If the sheet id is not found, the returned string is "<Sheet %d not found in sheet_id.bin>" with the id in d Definition at line 428 of file sheet_id.cpp. References _Initialised, _SheetIdToName, NLMISC::CStaticMap< uint32, CChar >::end(), NLMISC::CStaticMap< uint32, CChar >::find(), NLMISC::CSheetId::TSheetId::Id, nlassert, and NLMISC::toString().
00429 { 00430 nlassert(_Initialised); 00431 00432 CStaticMap<uint32,CChar>::const_iterator itStr = _SheetIdToName.find (_Id.Id); 00433 if( itStr != _SheetIdToName.end() ) 00434 { 00435 return string((*itStr).second.Ptr); 00436 } 00437 else 00438 { 00439 // This nlwarning is commented out because the loggers are mutexed, therefore 00440 // you couldn't use toString() within a nlwarning(). 00441 //nlwarning("<CSheetId::toString> The sheet %08x is not in sheet_id.bin",_Id.Id); 00442 return NLMISC::toString( "<Sheet %d not found in sheet_id.bin>", _Id.Id ); 00443 } 00444 00445 } // toString // |
|
Definition at line 590 of file sheet_id.cpp. References _FileExtensions, _Initialised, nlassert, NLMISC::strlwr(), and uint32. Referenced by buildIdVector().
00591 { 00592 nlassert(_Initialised); 00593 00594 unsigned i; 00595 for (i=0;i<_FileExtensions.size();i++) 00596 if (strlwr(fileExtension)==_FileExtensions[i]) 00597 return i; 00598 00599 return ~0; 00600 } // typeFromFileExtension // |
|
Remove all allocated memory Definition at line 326 of file sheet_id.cpp. References _AllStrings, and NLMISC::CSheetId::CChar::Ptr.
00327 { 00328 delete [] _AllStrings.Ptr; 00329 } // uninit // |
|
Definition at line 42 of file sheet_id.cpp. Referenced by loadSheetId(), and uninit(). |
|
Definition at line 49 of file sheet_id.cpp. Referenced by fileExtensionFromType(), loadSheetId(), and typeFromFileExtension(). |
|
Definition at line 181 of file sheet_id.h. Referenced by operator!=(), and operator==(). |
|
Definition at line 50 of file sheet_id.cpp. Referenced by build(), buildIdVector(), display(), fileExtensionFromType(), init(), operator<(), operator=(), toString(), and typeFromFileExtension(). |
|
Definition at line 51 of file sheet_id.cpp. Referenced by init(), loadSheetAlias(), and loadSheetId(). |
|
Definition at line 48 of file sheet_id.cpp. Referenced by build(), loadSheetAlias(), and operator=(). |
|
Definition at line 47 of file sheet_id.cpp. Referenced by loadSheetAlias(). |
|
Definition at line 43 of file sheet_id.cpp. Referenced by buildIdVector(), display(), loadSheetId(), and toString(). |
|
Definition at line 44 of file sheet_id.cpp. Referenced by build(), loadSheetId(), and operator=(). |
|
Unknow CSheetId is similar as an NULL pointer.
|