Move GetRelativePath to C4Language

C4Language is the only consumer of GetRelativePath. It cannot handle
arbitrarily sized paths, so discourage new code from using it by moving
it to C4Language.cpp.

Also remove the buffer size parameter which was always defaulted anyway
and use template parameter deduction to always get the correct size.
alut-include-path
Nicolas Hake 2017-03-11 13:47:18 +01:00
parent 333cf9c4b6
commit e3d6486f2a
3 changed files with 11 additions and 11 deletions

View File

@ -31,6 +31,17 @@
#include "config/C4Config.h"
#include "game/C4Game.h"
template<size_t iBufferSize>
static bool GetRelativePath(const char *strPath, const char *strRelativeTo, char(&strBuffer)[iBufferSize])
{
// Specified path is relative to base path
// Copy relative section
const char *szCpy;
SCopy(szCpy = GetRelativePathS(strPath, strRelativeTo), strBuffer, iBufferSize);
// return whether it was made relative
return szCpy != strPath;
}
C4Language Languages;
C4Language::C4Language()

View File

@ -218,16 +218,6 @@ bool GetParentPath(const char *szFilename, StdStrBuf *outBuf)
return true;
}
bool GetRelativePath(const char *strPath, const char *strRelativeTo, char *strBuffer, int iBufferSize)
{
// Specified path is relative to base path
// Copy relative section
const char *szCpy;
SCopy(szCpy=GetRelativePathS(strPath, strRelativeTo), strBuffer, iBufferSize);
// return whether it was made relative
return szCpy!=strPath;
}
const char *GetRelativePathS(const char *strPath, const char *strRelativeTo)
{
// Specified path is relative to base path

View File

@ -54,7 +54,6 @@ bool TruncatePath(char *szPath);
// szBuffer has to be of at least _MAX_PATH length.
bool GetParentPath(const char *szFilename, char *szBuffer);
bool GetParentPath(const char *szFilename, StdStrBuf *outBuf);
bool GetRelativePath(const char *strPath, const char *strRelativeTo, char *strBuffer, int iBufferSize=_MAX_PATH);
const char *GetRelativePathS(const char *strPath, const char *strRelativeTo);
bool IsGlobalPath(const char *szPath);