StdCompiler: Add support for std::string

alut-include-path
Nicolas Hake 2017-03-13 17:34:41 +01:00
parent b9a4345071
commit 78b43e2182
5 changed files with 60 additions and 0 deletions

View File

@ -1494,6 +1494,7 @@ protected:
virtual void ProcessChar(char &rChar) = 0;
virtual void ProcessString(char *szString, size_t iMaxLength, bool fIsID) = 0;
virtual void ProcessString(char **pszString, bool fIsID) = 0;
virtual void ProcessString(std::string &str, bool isID) = 0;
public:
// value functions
@ -1511,6 +1512,8 @@ public:
{ if (haveCompleteMatch()) if (!iEntryNr--) ProcessString(szString, iMaxLength, eType == StdCompiler::RCT_ID); }
virtual void String(char **pszString, RawCompileType eType)
{ if (haveCompleteMatch()) if (!iEntryNr--) ProcessString(pszString, eType == StdCompiler::RCT_ID); }
virtual void String(std::string &str, RawCompileType type) override
{ if (haveCompleteMatch()) if (!iEntryNr--) ProcessString(str, type == StdCompiler::RCT_ID); }
virtual void Raw(void *pData, size_t iSize, RawCompileType eType = RCT_Escaped)
{ /* C4Script can't handle this */ }
@ -1558,6 +1561,8 @@ protected:
{ Res = (fIsID ? C4VPropList(C4Id2Def(C4ID(szString))) : C4VString(szString)); }
virtual void ProcessString(char **pszString, bool fIsID)
{ Res = (fIsID ? C4VPropList(C4Id2Def(C4ID(*pszString))) : C4VString(*pszString)); }
virtual void ProcessString(std::string &str, bool fIsID)
{ Res = (fIsID ? C4VPropList(C4Id2Def(C4ID(str.c_str()))) : C4VString(str.c_str())); }
};
// Use the compiler to find a named value in a structure

View File

@ -77,6 +77,11 @@ void StdCompilerBinWrite::String(char **pszString, RawCompileType eType)
WriteValue('\0');
}
void StdCompilerBinWrite::String(std::string &str, RawCompileType type)
{
WriteData(str.c_str(), str.size() + 1);
}
template <class T>
void StdCompilerBinWrite::WriteValue(const T &rValue)
{
@ -152,6 +157,24 @@ void StdCompilerBinRead::String(char **pszString, RawCompileType eType)
memcpy(*pszString, Buf.getPtr(iStart), iPos - iStart);
}
void StdCompilerBinRead::String(std::string &str, RawCompileType type)
{
// At least one byte data needed
if (iPos >= Buf.getSize())
{
excEOF(); return;
}
int iStart = iPos;
// Search string end
while (*getBufPtr<char>(Buf, iPos++))
if (iPos >= Buf.getSize())
{
excEOF(); return;
}
// Copy data
str.assign(getBufPtr<char>(Buf, iStart), getBufPtr<char>(Buf, iPos));
}
void StdCompilerBinRead::Raw(void *pData, size_t iSize, RawCompileType eType)
{
if (iPos + iSize > Buf.getSize())
@ -311,6 +334,10 @@ void StdCompilerINIWrite::Raw(void *pData, size_t iSize, RawCompileType eType)
}
}
void StdCompilerINIWrite::String(std::string &str, RawCompileType type)
{
Raw(&str[0], str.size(), type);
}
void StdCompilerINIWrite::Begin()
{
@ -636,6 +663,14 @@ void StdCompilerINIRead::String(char **pszString, RawCompileType eType)
// Set
*pszString = reinterpret_cast<char *>(Buf.GrabPointer());
}
void StdCompilerINIRead::String(std::string &str, RawCompileType type)
{
// Get length
size_t iLength = GetStringLength(type);
// Read data
StdBuf Buf = ReadString(iLength, type, true);
str = getBufPtr<char>(Buf);
}
void StdCompilerINIRead::Raw(void *pData, size_t iSize, RawCompileType eType)
{
// Read data

View File

@ -153,6 +153,7 @@ public:
// Note that string won't allow '\0' inside the buffer, even with escaped compiling!
virtual void String(char *szString, size_t iMaxLength, RawCompileType eType = RCT_Escaped) = 0;
virtual void String(char **pszString, RawCompileType eType = RCT_Escaped) = 0;
virtual void String(std::string &str, RawCompileType type = RCT_Escaped) = 0;
virtual void Raw(void *pData, size_t iSize, RawCompileType eType = RCT_Escaped) = 0;
// * Position
@ -434,6 +435,7 @@ public:
virtual void Character(char &rChar) { }
virtual void String(char *szString, size_t iMaxLength, RawCompileType eType = RCT_Escaped) { }
virtual void String(char **pszString, RawCompileType eType = RCT_Escaped) { }
virtual void String(std::string &str, RawCompileType eType = RCT_Escaped) override {}
virtual void Raw(void *pData, size_t iSize, RawCompileType eType = RCT_Escaped) { }
};
@ -466,6 +468,7 @@ public:
virtual void Character(char &rChar);
virtual void String(char *szString, size_t iMaxLength, RawCompileType eType = RCT_Escaped);
virtual void String(char **pszString, RawCompileType eType = RCT_Escaped);
virtual void String(std::string &str, RawCompileType eType = RCT_Escaped) override;
virtual void Raw(void *pData, size_t iSize, RawCompileType eType = RCT_Escaped);
// Passes
@ -506,6 +509,7 @@ public:
virtual void Character(char &rChar);
virtual void String(char *szString, size_t iMaxLength, RawCompileType eType = RCT_Escaped);
virtual void String(char **pszString, RawCompileType eType = RCT_Escaped);
virtual void String(std::string &str, RawCompileType eType = RCT_Escaped) override;
virtual void Raw(void *pData, size_t iSize, RawCompileType eType = RCT_Escaped);
// Position
@ -584,6 +588,7 @@ public:
virtual void Character(char &rChar);
virtual void String(char *szString, size_t iMaxLength, RawCompileType eType = RCT_Escaped);
virtual void String(char **pszString, RawCompileType eType = RCT_Escaped);
virtual void String(std::string &str, RawCompileType eType = RCT_Escaped) override;
virtual void Raw(void *pData, size_t iSize, RawCompileType eType = RCT_Escaped);
// Passes
@ -656,6 +661,7 @@ public:
virtual void Character(char &rChar);
virtual void String(char *szString, size_t iMaxLength, RawCompileType eType = RCT_Escaped);
virtual void String(char **pszString, RawCompileType eType = RCT_Escaped);
virtual void String(std::string &str, RawCompileType eType = RCT_Escaped) override;
virtual void Raw(void *pData, size_t iSize, RawCompileType eType = RCT_Escaped);
// Position

View File

@ -366,6 +366,12 @@ void StdCompilerConfigWrite::String(char **pszString, RawCompileType eType)
WriteString(pszString ? *pszString : "");
}
void StdCompilerConfigWrite::String(std::string &str, RawCompileType eType)
{
assert(eType != RCT_Idtf && eType != RCT_IdtfAllowEmpty);
WriteString(str.c_str());
}
void StdCompilerConfigWrite::Raw(void *pData, size_t iSize, RawCompileType eType)
{
excCorrupt("Raw values aren't supported for registry compilers!");
@ -562,6 +568,12 @@ void StdCompilerConfigRead::String(char **pszString, RawCompileType eType)
*pszString = ReadString().GrabPointer();
}
void StdCompilerConfigRead::String(std::string &str, RawCompileType type)
{
assert(type != RCT_Idtf && type != RCT_IdtfAllowEmpty);
str = ReadString().getData();
}
void StdCompilerConfigRead::Raw(void *pData, size_t iSize, RawCompileType eType)
{
excCorrupt(0, "Raw values aren't supported for registry compilers!");

View File

@ -80,6 +80,7 @@ public:
virtual void Character(char &rChar);
virtual void String(char *szString, size_t iMaxLength, RawCompileType eType = RCT_Escaped);
virtual void String(char **pszString, RawCompileType eType = RCT_Escaped);
virtual void String(std::string &str, RawCompileType type = RCT_Escaped) override;
virtual void Raw(void *pData, size_t iSize, RawCompileType eType = RCT_Escaped);
// Passes
@ -139,6 +140,7 @@ public:
virtual void Character(char &rChar);
virtual void String(char *szString, size_t iMaxLength, RawCompileType eType = RCT_Escaped);
virtual void String(char **pszString, RawCompileType eType = RCT_Escaped);
virtual void String(std::string &str, RawCompileType type = RCT_Escaped) override;
virtual void Raw(void *pData, size_t iSize, RawCompileType eType = RCT_Escaped);
// Passes