From a2c2d78fe80e7f1f2cd0e2825a1857902e897119 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sat, 2 Jun 2012 15:21:03 +0200 Subject: [PATCH] Added: Additional constructor for CSheetId with default type, in case the user did not put the type with the sheet name --- code/nel/include/nel/misc/sheet_id.h | 6 ++++++ code/nel/src/misc/sheet_id.cpp | 19 +++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/code/nel/include/nel/misc/sheet_id.h b/code/nel/include/nel/misc/sheet_id.h index 9c13b6189..869a61af6 100644 --- a/code/nel/include/nel/misc/sheet_id.h +++ b/code/nel/include/nel/misc/sheet_id.h @@ -60,6 +60,12 @@ public : */ explicit CSheetId( const std::string& sheetName ); + /** + * Constructor, uses defaultType as extension when sheetName + * contains no file extension. + */ + explicit CSheetId( const std::string& sheetName, const std::string &defaultType ); + // build from a string and returns true if the build succeed bool buildSheetId(const std::string& sheetName); diff --git a/code/nel/src/misc/sheet_id.cpp b/code/nel/src/misc/sheet_id.cpp index 28d6498b0..e76f66656 100644 --- a/code/nel/src/misc/sheet_id.cpp +++ b/code/nel/src/misc/sheet_id.cpp @@ -106,6 +106,14 @@ CSheetId::CSheetId( const string& sheetName ) } // CSheetId // +CSheetId::CSheetId( const std::string& sheetName, const std::string &defaultType ) +{ + if (CFile::getExtension(sheetName) == "" && defaultType != "") + *this = CSheetId(sheetName + "." + defaultType); + else + *this = CSheetId(sheetName); +} + //----------------------------------------------- // Build @@ -522,16 +530,7 @@ void CSheetId::serialString(NLMISC::IStream &f, const std::string &defaultType) { std::string sheetName; f.serial(sheetName); - if (CFile::getExtension(sheetName) == "" && defaultType != "") - sheetName += std::string(".") + defaultType; - if (!buildSheetId(sheetName)) - { - 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()); - *this = Unknown; - } + *this = CSheetId(sheetName, defaultType); } else {