@ -30,35 +30,30 @@
using namespace std ;
# ifdef DEBUG_NEW
# define new DEBUG_NEW
# define new DEBUG_NEW
# endif
namespace NLMISC {
namespace NLMISC
{
CSheetId : : CChar CSheetId : : _AllStrings ;
CStaticMap < uint32 , CSheetId : : CChar > CSheetId : : _SheetIdToName ;
CStaticMap < CSheetId : : CChar , uint32 , CSheetId : : CCharComp > CSheetId : : _SheetNameToId ;
CStaticMap < uint32 , CSheetId : : CChar > CSheetId : : _SheetIdToName ;
CStaticMap < CSheetId : : CChar , uint32 , CSheetId : : CCharComp > CSheetId : : _SheetNameToId ;
//map<uint32,std::string> CSheetId::_SheetIdToName;
//map<std::string,uint32> CSheetId::_SheetNameToId;
vector < std : : string > CSheetId : : _FileExtensions ;
bool CSheetId : : _Initialised = false ;
bool CSheetId : : _RemoveUnknownSheet = true ;
bool CSheetId : : _Initialised = false ;
bool CSheetId : : _RemoveUnknownSheet = true ;
bool CSheetId : : _DontHaveSheetKnowledge = false ;
std : : map < std : : string , uint32 > CSheetId : : _DevTypeNameToId ;
std : : vector < std : : vector < std : : string > > CSheetId : : _DevSheetIdToName ;
std : : vector < std : : vector < std : : string > > CSheetId : : _DevSheetIdToName ;
std : : map < std : : string , uint32 > CSheetId : : _DevSheetNameToId ;
# define NL_TEMP_YUBO_NO_SOUND_SHEET_ID
# ifdef NL_TEMP_YUBO_NO_SOUND_SHEET_ID
namespace { bool a_NoSoundSheetId = false ; const uint32 a_NoSoundSheetType = 80 ; }
# endif
const CSheetId CSheetId : : Unknown ( 0 ) ;
void CSheetId : : cbFileChange ( const std : : string & filename )
void CSheetId : : cbFileChange ( const std : : string & filename )
{
nlinfo ( " SHEETID: %s changed, reload it " , filename . c_str ( ) ) ;
nlinfo ( " SHEETID: %s changed, reload it " , filename . c_str ( ) ) ;
loadSheetId ( ) ;
}
@ -67,14 +62,14 @@ void CSheetId::cbFileChange (const std::string &filename)
// CSheetId
//
//-----------------------------------------------
CSheetId : : CSheetId ( uint32 sheetRef )
CSheetId : : CSheetId ( uint32 sheetRef )
{
_Id . Id = sheetRef ;
# ifdef NL_DEBUG_SHEET_ID
// Yoyo: don't access the static map, because of order of static ctor call.
// For now, all static CSheetId are 0 (eg: CSheetId::Unknown)
if ( sheetRef )
if ( sheetRef )
{
CStaticMap < uint32 , CChar > : : iterator it ( _SheetIdToName . find ( sheetRef ) ) ;
if ( it ! = _SheetIdToName . end ( ) )
@ -91,19 +86,18 @@ CSheetId::CSheetId( uint32 sheetRef)
# endif
}
//-----------------------------------------------
// CSheetId
//
//-----------------------------------------------
CSheetId : : CSheetId ( const string & sheetName )
CSheetId : : CSheetId ( const string & sheetName )
{
if ( ! buildSheetId ( sheetName ) )
{
if ( sheetName . empty ( ) )
if ( sheetName . empty ( ) )
nlwarning ( " SHEETID: Try to create an CSheetId with empty name. TODO: check why. " ) ;
else
nlwarning ( " SHEETID: The sheet '%s' is not in sheet_id.bin, setting it to Unknown " , sheetName . c_str ( ) ) ;
nlwarning ( " SHEETID: The sheet '%s' is not in sheet_id.bin, setting it to Unknown " , sheetName . c_str ( ) ) ;
//std::string stack;
//NLMISC::getCallStack(stack);
//std::vector<std::string> contexts;
@ -118,7 +112,7 @@ CSheetId::CSheetId( const string& sheetName )
} // CSheetId //
CSheetId : : CSheetId ( const std : : string & sheetName , const std : : string & defaultType )
CSheetId : : CSheetId ( const std : : string & sheetName , const std : : string & defaultType )
{
// Don't use this function without defaultType, use the one above.
nlassert ( defaultType . size ( ) ! = 0 ) ;
@ -135,12 +129,11 @@ CSheetId::CSheetId( const std::string& sheetName, const std::string &defaultType
}
}
//-----------------------------------------------
// Build
//
//-----------------------------------------------
bool CSheetId : : buildSheetId ( const std : : string & sheetName )
bool CSheetId : : buildSheetId ( const std : : string & sheetName )
{
nlassert ( _Initialised ) ;
@ -188,15 +181,15 @@ bool CSheetId::buildSheetId(const std::string& sheetName)
}
// try looking up the sheet name in _SheetNameToId
CStaticMap < CChar , uint32 , CCharComp > : : const_iterator itId ;
CStaticMap < CChar , uint32 , CCharComp > : : const_iterator itId ;
CChar c ;
c . Ptr = new char [ sheetName . size ( ) + 1 ] ;
c . Ptr = new char [ sheetName . size ( ) + 1 ] ;
strcpy ( c . Ptr , sheetName . c_str ( ) ) ;
toLower ( c . Ptr ) ;
itId = _SheetNameToId . find ( c ) ;
delete [ ] c . Ptr ;
if ( itId ! = _SheetNameToId . end ( ) )
itId = _SheetNameToId . find ( c ) ;
delete [ ] c . Ptr ;
if ( itId ! = _SheetNameToId . end ( ) )
{
_Id . Id = itId - > second ;
# ifdef NL_DEBUG_SHEET_ID
@ -207,40 +200,21 @@ bool CSheetId::buildSheetId(const std::string& sheetName)
}
// we failed to find the sheet name in the sheetname map so see if the string is numeric
if ( sheetName . size ( ) > 1 & & sheetName [ 0 ] = = ' # ' )
if ( sheetName . size ( ) > 1 & & sheetName [ 0 ] = = ' # ' )
{
uint32 numericId ;
NLMISC : : fromString ( ( const char * ) ( sheetName . c_str ( ) + 1 ) , numericId ) ;
if ( NLMISC : : toString ( " #%u " , numericId ) = = sheetName )
NLMISC : : fromString ( ( const char * ) ( sheetName . c_str ( ) + 1 ) , numericId ) ;
if ( NLMISC : : toString ( " #%u " , numericId ) = = sheetName )
{
_Id . Id = numericId ;
_Id . Id = numericId ;
return true ;
}
}
# ifdef NL_TEMP_YUBO_NO_SOUND_SHEET_ID
if ( a_NoSoundSheetId & & sheetName . find ( " .sound " ) ! = std : : string : : npos )
{
std : : string sheetNameLc = toLower ( sheetName ) ;
std : : map < std : : string , uint32 > : : iterator it = _DevSheetNameToId . find ( sheetNameLc ) ;
if ( it = = _DevSheetNameToId . end ( ) )
{
// nldebug("SHEETID: Creating a temporary sheet id for '%s'", sheetName.c_str());
_DevSheetIdToName [ 0 ] . push_back ( sheetName ) ;
_Id . IdInfos . Type = a_NoSoundSheetType ;
_Id . IdInfos . Id = _DevSheetIdToName [ 0 ] . size ( ) - 1 ;
_DevSheetNameToId [ sheetNameLc ] = _Id . Id ;
return true ;
}
_Id . Id = it - > second ;
return true ;
}
# endif
return false ;
}
void CSheetId : : loadSheetId ( )
void CSheetId : : loadSheetId ( )
{
H_AUTO ( CSheetIdInit ) ;
//nldebug("Loading sheet_id.bin");
@ -248,18 +222,18 @@ void CSheetId::loadSheetId ()
// Open the sheet id to sheet file name association
CIFile file ;
std : : string path = CPath : : lookup ( " sheet_id.bin " , false , false ) ;
if ( ! path . empty ( ) & & file . open ( path ) )
if ( ! path . empty ( ) & & file . open ( path ) )
{
// clear entries
_FileExtensions . clear ( ) ;
_SheetIdToName . clear ( ) ;
_SheetNameToId . clear ( ) ;
_FileExtensions . clear ( ) ;
_SheetIdToName . clear ( ) ;
_SheetNameToId . clear ( ) ;
// reserve space for the vector of file extensions
_FileExtensions . resize ( 1 < < ( NL_SHEET_ID_TYPE_BITS ) ) ;
// Get the map from the file
map < uint32 , string > tempMap ;
map < uint32 , string > tempMap ;
contReset ( tempMap ) ;
file . serialCont ( tempMap ) ;
file . close ( ) ;
@ -270,23 +244,23 @@ void CSheetId::loadSheetId ()
uint32 nbfiles = ( uint32 ) tempMap . size ( ) ;
// now we remove all files that not available
map < uint32 , string > : : iterator itStr2 ;
for ( itStr2 = tempMap . begin ( ) ; itStr2 ! = tempMap . end ( ) ; )
map < uint32 , string > : : iterator itStr2 ;
for ( itStr2 = tempMap . begin ( ) ; itStr2 ! = tempMap . end ( ) ; )
{
if ( CPath : : exists ( ( * itStr2 ) . second ) )
if ( CPath : : exists ( ( * itStr2 ) . second ) )
{
+ + itStr2 ;
}
else
{
map < uint32 , string > : : iterator olditStr = itStr2 ;
map < uint32 , string > : : iterator olditStr = itStr2 ;
//nldebug ("Removing file '%s' from CSheetId because the file not exists", (*olditStr).second.c_str ());
itStr2 + + ;
tempMap . erase ( olditStr ) ;
tempMap . erase ( olditStr ) ;
removednbfiles + + ;
}
}
nlinfo ( " SHEETID: Removed %d files on %d from CSheetId because these files don't exist " , removednbfiles , nbfiles ) ;
nlinfo ( " SHEETID: Removed %d files on %d from CSheetId because these files don't exist " , removednbfiles , nbfiles ) ;
}
// Convert the map to one big string and 1 static map (id to name)
@ -295,10 +269,10 @@ void CSheetId::loadSheetId ()
vector < CChar > tempVec ; // Used to initialise the first map
uint32 nNb = 0 ;
uint32 nSize = 0 ;
map < uint32 , string > : : const_iterator it = tempMap . begin ( ) ;
map < uint32 , string > : : const_iterator it = tempMap . begin ( ) ;
while ( it ! = tempMap . end ( ) )
{
nSize + = ( uint32 ) it - > second . size ( ) + 1 ;
nSize + = ( uint32 ) it - > second . size ( ) + 1 ;
nNb + + ;
it + + ;
}
@ -311,10 +285,10 @@ void CSheetId::loadSheetId ()
nNb = 0 ;
while ( it ! = tempMap . end ( ) )
{
tempVec [ nNb ] . Ptr = _AllStrings . Ptr + nSize ;
strcpy ( _AllStrings . Ptr + nSize , it - > second . c_str ( ) ) ;
toLower ( _AllStrings . Ptr + nSize ) ;
nSize + = ( uint32 ) it - > second . size ( ) + 1 ;
tempVec [ nNb ] . Ptr = _AllStrings . Ptr + nSize ;
strcpy ( _AllStrings . Ptr + nSize , it - > second . c_str ( ) ) ;
toLower ( _AllStrings . Ptr + nSize ) ;
nSize + = ( uint32 ) it - > second . size ( ) + 1 ;
nNb + + ;
it + + ;
}
@ -339,15 +313,15 @@ void CSheetId::loadSheetId ()
{
uint32 nSize = ( uint32 ) _SheetIdToName . size ( ) ;
_SheetNameToId . reserve ( nSize ) ;
CStaticMap < uint32 , CChar > : : iterator itStr ;
for ( itStr = _SheetIdToName . begin ( ) ; itStr ! = _SheetIdToName . end ( ) ; + + itStr )
CStaticMap < uint32 , CChar > : : iterator itStr ;
for ( itStr = _SheetIdToName . begin ( ) ; itStr ! = _SheetIdToName . end ( ) ; + + itStr )
{
// add entry to the inverse map
_SheetNameToId . add ( make_pair ( ( * itStr ) . second , ( * itStr ) . first ) ) ;
_SheetNameToId . add ( make_pair ( ( * itStr ) . second , ( * itStr ) . first ) ) ;
// work out the type value for this entry in the map
TSheetId sheetId ;
sheetId . Id = ( * itStr ) . first ;
sheetId . Id = ( * itStr ) . first ;
uint32 type = sheetId . IdInfos . Type ;
// check whether we need to add an entry to the file extensions vector
@ -365,10 +339,9 @@ void CSheetId::loadSheetId ()
{
nlerror ( " <CSheetId::init> Can't open the file sheet_id.bin " ) ;
}
nldebug ( " Finished loading sheet_id.bin: %u entries read " , _SheetIdToName . size ( ) ) ;
nldebug ( " Finished loading sheet_id.bin: %u entries read " , _SheetIdToName . size ( ) ) ;
}
//-----------------------------------------------
// init
//
@ -383,30 +356,12 @@ void CSheetId::init(bool removeUnknownSheet)
return ;
}
// CFile::addFileChangeCallback ("sheet_id.bin", cbFileChange);
// CFile::addFileChangeCallback ("sheet_id.bin", cbFileChange);
_RemoveUnknownSheet = removeUnknownSheet ;
loadSheetId ( ) ;
_Initialised = true ;
# ifdef NL_TEMP_YUBO_NO_SOUND_SHEET_ID
if ( typeFromFileExtension ( " sound " ) = = std : : numeric_limits < uint32 > : : max ( ) )
{
nlwarning ( " SHEETID: Loading without known sound sheet id, please update sheet_id.bin with .sound sheets " ) ;
nlassert ( _FileExtensions . size ( ) = = 1 < < ( NL_SHEET_ID_TYPE_BITS ) ) ;
nlassert ( _FileExtensions [ a_NoSoundSheetType ] . empty ( ) ) ;
_FileExtensions [ a_NoSoundSheetType ] = " sound " ;
_DevSheetIdToName . push_back ( std : : vector < std : : string > ( ) ) ;
_DevSheetIdToName [ 0 ] . push_back ( " unknown.sound " ) ;
TSheetId id ;
id . IdInfos . Type = a_NoSoundSheetType ;
id . IdInfos . Id = _DevSheetIdToName [ 0 ] . size ( ) - 1 ;
nlassert ( id . IdInfos . Id = = 0 ) ;
_DevSheetNameToId [ " unknown.sound " ] = id . Id ;
a_NoSoundSheetId = true ;
}
# endif
loadSheetId ( ) ;
_Initialised = true ;
} // init //
@ -422,19 +377,17 @@ void CSheetId::initWithoutSheet()
_DontHaveSheetKnowledge = true ;
// Initialize id 0,0 as unknown.unknown
CSheetId unknown u nknown = CSheetId ( " unknown.unknown " ) ;
nlassert ( unknown u nknown = = CSheetId : : Unknown ) ;
CSheetId unknown U nknown = CSheetId ( " unknown.unknown " ) ;
nlassert ( unknown U nknown = = CSheetId : : Unknown ) ;
}
//-----------------------------------------------
// uninit
//
//-----------------------------------------------
void CSheetId : : uninit ( )
{
delete [ ] _AllStrings . Ptr ;
delete [ ] _AllStrings . Ptr ;
_FileExtensions . clear ( ) ;
_DevTypeNameToId . clear ( ) ;
_DevSheetIdToName . clear ( ) ;
@ -445,11 +398,12 @@ void CSheetId::uninit()
// operator=
//
//-----------------------------------------------
CSheetId & CSheetId : : operator = ( const CSheetId & sheetId )
CSheetId & CSheetId : : operator = ( const CSheetId & sheetId )
{
if ( ! _Initialised ) init ( false ) ;
if ( ! _Initialised )
init ( false ) ;
if ( this = = & sheetId )
if ( this = = & sheetId )
{
return * this ;
}
@ -462,15 +416,13 @@ CSheetId& CSheetId::operator=( const CSheetId& sheetId )
return * this ;
} // operator= //
//-----------------------------------------------
// operator=
//
//-----------------------------------------------
CSheetId & CSheetId : : operator = ( const string & sheetName )
CSheetId & CSheetId : : operator = ( const string & sheetName )
{
if ( ! buildSheetId ( sheetName ) )
@ -482,14 +434,14 @@ CSheetId& CSheetId::operator=( const string& sheetName )
} // operator= //
//-----------------------------------------------
// operator=
//
//-----------------------------------------------
CSheetId & CSheetId : : operator = ( uint32 sheetRef )
CSheetId & CSheetId : : operator = ( uint32 sheetRef )
{
if ( ! _Initialised ) init ( false ) ;
if ( ! _Initialised )
init ( false ) ;
_Id . Id = sheetRef ;
@ -497,15 +449,14 @@ CSheetId& CSheetId::operator=( uint32 sheetRef )
} // operator= //
//-----------------------------------------------
// operator<
//
//-----------------------------------------------
bool CSheetId : : operator < ( const CSheetId & sheetRef ) const
bool CSheetId : : operator < ( const CSheetId & sheetRef ) const
{
if ( ! _Initialised ) init ( false ) ;
if ( ! _Initialised )
init ( false ) ;
if ( _Id . Id < sheetRef . asInt ( ) )
{
@ -516,46 +467,52 @@ bool CSheetId::operator < (const CSheetId& sheetRef ) const
} // operator< //
//-----------------------------------------------
// toString
//
//-----------------------------------------------
string CSheetId : : toString ( bool ifNotFoundUseNumericId ) const
{
if ( ! _Initialised ) init ( false ) ;
if ( ! _Initialised )
init ( false ) ;
if ( _DontHaveSheetKnowledge )
{
// FIXME: When someone punches in a fake sheet id this will
// fail.
if ( _Id . IdInfos . Type < _DevSheetIdToName . size ( )
& & _Id . IdInfos . Id < _DevSheetIdToName [ _Id . IdInfos . Type ] . size ( ) )
{
return _DevSheetIdToName [ _Id . IdInfos . Type ] [ _Id . IdInfos . Id ] ;
}
CStaticMap < uint32 , CChar > : : const_iterator itStr = _SheetIdToName . find ( _Id . Id ) ;
if ( itStr ! = _SheetIdToName . end ( ) )
else
{
return string ( ( * itStr ) . second . Ptr ) ;
if ( ifNotFoundUseNumericId )
{
return NLMISC : : toString ( " #%u " , _Id . Id ) ;
}
else
{
# ifdef NL_TEMP_YUBO_NO_SOUND_SHEET_ID
if ( a_NoSoundSheetId & & _Id . IdInfos . Type = = a_NoSoundSheetType )
return NLMISC : : toString ( " <Sheet %u not found in loaded sheets> " , _Id . Id ) ;
}
}
}
CStaticMap < uint32 , CChar > : : const_iterator itStr = _SheetIdToName . find ( _Id . Id ) ;
if ( itStr ! = _SheetIdToName . end ( ) )
{
return _DevSheetIdToName [ 0 ] [ _Id . IdInfos . Id ] ;
return string ( ( * itStr ) . second . Ptr ) ;
}
# endif
else
{
// This nlwarning is commented out because the loggers are mutexed, therefore
// you couldn't use toString() within a nlwarning().
//nlwarning("<CSheetId::toString> The sheet %08x is not in sheet_id.bin",_Id.Id);
if ( ifNotFoundUseNumericId )
{
return NLMISC : : toString ( " #%u " , _Id . Id ) ;
return NLMISC : : toString ( " #%u " , _Id . Id ) ;
}
else
{
return NLMISC : : toString ( " <Sheet %u not found in sheet_id.bin> " , _Id . Id ) ;
return NLMISC : : toString ( " <Sheet %u not found in sheet_id.bin> " , _Id . Id ) ;
}
}
@ -565,7 +522,7 @@ void CSheetId::serial(NLMISC::IStream &f)
{
nlassert ( ! _DontHaveSheetKnowledge ) ;
f . serial ( _Id . Id ) ;
f . serial ( _Id . Id ) ;
# ifdef NL_DEBUG_SHEET_ID
CStaticMap < uint32 , CChar > : : iterator it ( _SheetIdToName . find ( _Id . Id ) ) ;
@ -595,90 +552,88 @@ void CSheetId::serialString(NLMISC::IStream &f, const std::string &defaultType)
}
}
//-----------------------------------------------
// display
//
//-----------------------------------------------
void CSheetId : : display ( )
{
if ( ! _Initialised ) init ( false ) ;
if ( ! _Initialised )
init ( false ) ;
CStaticMap < uint32 , CChar > : : const_iterator itStr ;
for ( itStr = _SheetIdToName . begin ( ) ; itStr ! = _SheetIdToName . end ( ) ; + + itStr )
CStaticMap < uint32 , CChar > : : const_iterator itStr ;
for ( itStr = _SheetIdToName . begin ( ) ; itStr ! = _SheetIdToName . end ( ) ; + + itStr )
{
//nlinfo("%d %s",(*itStr).first,(*itStr).second.c_str());
nlinfo ( " SHEETID: (%08x %d) %s " , ( * itStr ) . first , ( * itStr ) . first , ( * itStr ) . second . Ptr ) ;
nlinfo ( " SHEETID: (%08x %d) %s " , ( * itStr ) . first , ( * itStr ) . first , ( * itStr ) . second . Ptr ) ;
}
} // display //
//-----------------------------------------------
// display
//
//-----------------------------------------------
void CSheetId : : display ( uint32 type )
{
if ( ! _Initialised ) init ( false ) ;
if ( ! _Initialised )
init ( false ) ;
CStaticMap < uint32 , CChar > : : const_iterator itStr ;
for ( itStr = _SheetIdToName . begin ( ) ; itStr ! = _SheetIdToName . end ( ) ; + + itStr )
CStaticMap < uint32 , CChar > : : const_iterator itStr ;
for ( itStr = _SheetIdToName . begin ( ) ; itStr ! = _SheetIdToName . end ( ) ; + + itStr )
{
// work out the type value for this entry in the map
TSheetId sheetId ;
sheetId . Id = ( * itStr ) . first ;
sheetId . Id = ( * itStr ) . first ;
// decide whether or not to display the entry
if ( type = = sheetId . IdInfos . Type )
if ( type = = sheetId . IdInfos . Type )
{
//nlinfo("%d %s",(*itStr).first,(*itStr).second.c_str());
nlinfo ( " SHEETID: (%08x %d) %s " , ( * itStr ) . first , ( * itStr ) . first , ( * itStr ) . second . Ptr ) ;
nlinfo ( " SHEETID: (%08x %d) %s " , ( * itStr ) . first , ( * itStr ) . first , ( * itStr ) . second . Ptr ) ;
}
}
} // display //
//-----------------------------------------------
// buildIdVector
//
//-----------------------------------------------
void CSheetId : : buildIdVector ( std : : vector < CSheetId > & result )
void CSheetId : : buildIdVector ( std : : vector < CSheetId > & result )
{
if ( ! _Initialised ) init ( false ) ;
if ( ! _Initialised )
init ( false ) ;
CStaticMap < uint32 , CChar > : : const_iterator itStr ;
for ( itStr = _SheetIdToName . begin ( ) ; itStr ! = _SheetIdToName . end ( ) ; + + itStr )
CStaticMap < uint32 , CChar > : : const_iterator itStr ;
for ( itStr = _SheetIdToName . begin ( ) ; itStr ! = _SheetIdToName . end ( ) ; + + itStr )
{
result . push_back ( ( CSheetId ) ( * itStr ) . first ) ;
result . push_back ( ( CSheetId ) ( * itStr ) . first ) ;
}
} // buildIdVector //
//-----------------------------------------------
// buildIdVector
//
//-----------------------------------------------
void CSheetId : : buildIdVector ( std : : vector < CSheetId > & result , uint32 type )
void CSheetId : : buildIdVector ( std : : vector < CSheetId > & result , uint32 type )
{
if ( ! _Initialised ) init ( false ) ;
if ( ! _Initialised )
init ( false ) ;
nlassert ( type < ( 1 < < ( NL_SHEET_ID_TYPE_BITS ) ) ) ;
CStaticMap < uint32 , CChar > : : const_iterator itStr ;
for ( itStr = _SheetIdToName . begin ( ) ; itStr ! = _SheetIdToName . end ( ) ; + + itStr )
CStaticMap < uint32 , CChar > : : const_iterator itStr ;
for ( itStr = _SheetIdToName . begin ( ) ; itStr ! = _SheetIdToName . end ( ) ; + + itStr )
{
// work out the type value for this entry in the map
TSheetId sheetId ;
sheetId . Id = ( * itStr ) . first ;
sheetId . Id = ( * itStr ) . first ;
// decide whether or not to use the entry
if ( type = = sheetId . IdInfos . Type )
if ( type = = sheetId . IdInfos . Type )
{
result . push_back ( ( CSheetId ) sheetId . Id ) ;
result . push_back ( ( CSheetId ) sheetId . Id ) ;
}
}
@ -688,23 +643,24 @@ void CSheetId::buildIdVector(std::vector <CSheetId> &result, uint32 type)
// buildIdVector
//
//-----------------------------------------------
void CSheetId : : buildIdVector ( std : : vector < CSheetId > & result , std : : vector < std : : string > & resultFilenames , uint32 type )
void CSheetId : : buildIdVector ( std : : vector < CSheetId > & result , std : : vector < std : : string > & resultFilenames , uint32 type )
{
if ( ! _Initialised ) init ( false ) ;
if ( ! _Initialised )
init ( false ) ;
nlassert ( type < ( 1 < < ( NL_SHEET_ID_TYPE_BITS ) ) ) ;
CStaticMap < uint32 , CChar > : : const_iterator itStr ;
for ( itStr = _SheetIdToName . begin ( ) ; itStr ! = _SheetIdToName . end ( ) ; + + itStr )
CStaticMap < uint32 , CChar > : : const_iterator itStr ;
for ( itStr = _SheetIdToName . begin ( ) ; itStr ! = _SheetIdToName . end ( ) ; + + itStr )
{
// work out the type value for this entry in the map
TSheetId sheetId ;
sheetId . Id = ( * itStr ) . first ;
sheetId . Id = ( * itStr ) . first ;
// decide whether or not to use the entry
if ( type = = sheetId . IdInfos . Type )
if ( type = = sheetId . IdInfos . Type )
{
result . push_back ( ( CSheetId ) sheetId . Id ) ;
resultFilenames . push_back ( ( * itStr ) . second . Ptr ) ;
result . push_back ( ( CSheetId ) sheetId . Id ) ;
resultFilenames . push_back ( ( * itStr ) . second . Ptr ) ;
}
}
@ -714,9 +670,9 @@ void CSheetId::buildIdVector(std::vector <CSheetId> &result, std::vector <std::s
// buildIdVector
//
//-----------------------------------------------
void CSheetId : : buildIdVector ( std : : vector < CSheetId > & result , const std : : string & fileExtension )
void CSheetId : : buildIdVector ( std : : vector < CSheetId > & result , const std : : string & fileExtension )
{
uint32 type = typeFromFileExtension ( fileExtension ) ;
uint32 type = typeFromFileExtension ( fileExtension ) ;
if ( type ! = std : : numeric_limits < uint32 > : : max ( ) )
buildIdVector ( result , type ) ;
@ -726,40 +682,40 @@ void CSheetId::buildIdVector(std::vector <CSheetId> &result,const std::string &f
// buildIdVector
//
//-----------------------------------------------
void CSheetId : : buildIdVector ( std : : vector < CSheetId > & result , std : : vector < std : : string > & resultFilenames , const std : : string & fileExtension )
void CSheetId : : buildIdVector ( std : : vector < CSheetId > & result , std : : vector < std : : string > & resultFilenames , const std : : string & fileExtension )
{
uint32 type = typeFromFileExtension ( fileExtension ) ;
uint32 type = typeFromFileExtension ( fileExtension ) ;
if ( type ! = std : : numeric_limits < uint32 > : : max ( ) )
buildIdVector ( result , resultFilenames , type ) ;
buildIdVector ( result , resultFilenames , type ) ;
} // buildIdVector //
//-----------------------------------------------
// typeFromFileExtension
//
//-----------------------------------------------
uint32 CSheetId : : typeFromFileExtension ( const std : : string & fileExtension )
{
if ( ! _Initialised ) init ( false ) ;
if ( ! _Initialised )
init ( false ) ;
uint i ;
for ( i = 0 ; i < _FileExtensions . size ( ) ; i + + )
if ( toLower ( fileExtension ) = = _FileExtensions [ i ] )
for ( i = 0 ; i < _FileExtensions . size ( ) ; i + + )
if ( toLower ( fileExtension ) = = _FileExtensions [ i ] )
return i ;
return std : : numeric_limits < uint32 > : : max ( ) ;
} // typeFromFileExtension //
//-----------------------------------------------
// fileExtensionFromType
//
//-----------------------------------------------
const std : : string & CSheetId : : fileExtensionFromType ( uint32 type )
{
if ( ! _Initialised ) init ( false ) ;
nlassert ( type < ( 1 < < ( NL_SHEET_ID_TYPE_BITS ) ) ) ;
if ( ! _Initialised )
init ( false ) ;
nlassert ( type < ( 1 < < ( NL_SHEET_ID_TYPE_BITS ) ) ) ;
return _FileExtensions [ type ] ;
@ -771,11 +727,11 @@ const std::string &CSheetId::fileExtensionFromType(uint32 type)
//-----------------------------------------------
void CSheetId : : buildSheetId ( uint32 shortId , uint32 type )
{
nlassert ( shortId < ( 1 < < NL_SHEET_ID_ID_BITS ) ) ;
nlassert ( type < ( 1 < < ( NL_SHEET_ID_TYPE_BITS ) ) ) ;
nlassert ( shortId < ( 1 < < NL_SHEET_ID_ID_BITS ) ) ;
nlassert ( type < ( 1 < < ( NL_SHEET_ID_TYPE_BITS ) ) ) ;
_Id . IdInfos . Id = shortId ;
_Id . IdInfos . Type = type ;
_Id . IdInfos . Id = shortId ;
_Id . IdInfos . Type = type ;
# ifdef NL_DEBUG_SHEET_ID
CStaticMap < uint32 , CChar > : : iterator it ( _SheetIdToName . find ( _Id . Id ) ) ;
@ -786,7 +742,6 @@ void CSheetId::buildSheetId(uint32 shortId, uint32 type)
else
_DebugSheetName = NULL ;
# endif
}
} // NLMISC