Fix Error.cpp compile for Windows

develop
Ben Lubar 2018-02-07 10:40:52 -06:00
parent a37ac2c349
commit 7426f08504
No known key found for this signature in database
GPG Key ID: 018BAB45DB2D2B24
2 changed files with 7 additions and 26 deletions

@ -3,33 +3,33 @@
using namespace DFHack::Error; using namespace DFHack::Error;
inline const char *safe_str(const char *s) inline std::string safe_str(const char *s)
{ {
return s ? s : "(NULL)"; return s ? s : "(NULL)";
} }
NullPointer::NullPointer(const char *varname) NullPointer::NullPointer(const char *varname)
:All(stl_concat("NULL pointer: ", safe_str(varname))), :All("NULL pointer: " + safe_str(varname)),
varname(varname) varname(varname)
{} {}
InvalidArgument::InvalidArgument(const char *expr) InvalidArgument::InvalidArgument(const char *expr)
:All(stl_concat("Invalid argument; expected: ", safe_str(expr))), :All("Invalid argument; expected: " + safe_str(expr)),
expr(expr) expr(expr)
{} {}
VTableMissing::VTableMissing(const char *name) VTableMissing::VTableMissing(const char *name)
:All(stl_concat("Missing vtable address: ", safe_str(name))), :All("Missing vtable address: " + safe_str(name)),
name(name) name(name)
{} {}
SymbolsXmlParse::SymbolsXmlParse(const char* desc, int id, int row, int col) SymbolsXmlParse::SymbolsXmlParse(const char* desc, int id, int row, int col)
:AllSymbols(stl_concat("error ", id, ": ", desc, ", at row ", row, " col ", col)), :AllSymbols(stl_sprintf("error %d: %s, at row %d col %d", id, desc, row, col)),
desc(safe_str(desc)), id(id), row(row), col(col) desc(safe_str(desc)), id(id), row(row), col(col)
{} {}
SymbolsXmlBadAttribute::SymbolsXmlBadAttribute(const char *attr) SymbolsXmlBadAttribute::SymbolsXmlBadAttribute(const char *attr)
:AllSymbols(stl_concat("attribute is either missing or invalid: ", safe_str(attr))), :AllSymbols("attribute is either missing or invalid: " + safe_str(attr)),
attr(safe_str(attr)) attr(safe_str(attr))
{} {}
@ -38,7 +38,6 @@ SymbolsXmlNoRoot::SymbolsXmlNoRoot()
{} {}
SymbolsXmlUnderspecifiedEntry::SymbolsXmlUnderspecifiedEntry(const char *where) SymbolsXmlUnderspecifiedEntry::SymbolsXmlUnderspecifiedEntry(const char *where)
:AllSymbols(stl_concat("Underspecified symbol file entry, each entry needs to set both the name attribute and have a value. parent: ", :AllSymbols("Underspecified symbol file entry, each entry needs to set both the name attribute and have a value. parent: " + safe_str(where)),
safe_str(where))),
where(safe_str(where)) where(safe_str(where))
{} {}

@ -349,24 +349,6 @@ DFHACK_EXPORT uint64_t GetTimeMs64();
DFHACK_EXPORT std::string stl_sprintf(const char *fmt, ...); DFHACK_EXPORT std::string stl_sprintf(const char *fmt, ...);
DFHACK_EXPORT std::string stl_vsprintf(const char *fmt, va_list args); DFHACK_EXPORT std::string stl_vsprintf(const char *fmt, va_list args);
// https://stackoverflow.com/questions/27375089/what-is-the-easiest-way-to-print-a-variadic-parameter-pack-using-stdostream
template<typename... Args>
inline std::string stl_concat(Args... args)
{
std::ostringstream os;
(void)(int[]){0, (void(os << std::forward<Args>(args)), 0)...};
return os.str();
}
template<typename... Args>
inline std::string stl_concat(const std::string &sep, Args... args)
{
std::ostringstream os;
(void)(int[]){0, (void(os << sep << std::forward<Args>(args)), 0)...};
return os.str();
}
// Conversion between CP437 and UTF-8 // Conversion between CP437 and UTF-8
DFHACK_EXPORT std::string UTF2DF(const std::string &in); DFHACK_EXPORT std::string UTF2DF(const std::string &in);
DFHACK_EXPORT std::string DF2UTF(const std::string &in); DFHACK_EXPORT std::string DF2UTF(const std::string &in);