This commit is contained in:
@@ -31,22 +31,22 @@ END_AS_NAMESPACE
|
||||
class CStdStringFactory : public asIStringFactory
|
||||
{
|
||||
public:
|
||||
CStdStringFactory() {}
|
||||
~CStdStringFactory()
|
||||
CStdStringFactory() = default;
|
||||
~CStdStringFactory() override
|
||||
{
|
||||
// The script engine must release each string
|
||||
// constant that it has requested
|
||||
assert(stringCache.size() == 0);
|
||||
assert(stringCache.empty());
|
||||
}
|
||||
|
||||
const void *GetStringConstant(const char *data, asUINT length)
|
||||
const void *GetStringConstant(const char *data, asUINT length) override
|
||||
{
|
||||
// The string factory might be modified from multiple
|
||||
// threads, so it is necessary to use a mutex.
|
||||
asAcquireExclusiveLock();
|
||||
|
||||
string str(data, length);
|
||||
map_t::iterator it = stringCache.find(str);
|
||||
auto it = stringCache.find(str);
|
||||
if (it != stringCache.end())
|
||||
it->second++;
|
||||
else
|
||||
@@ -57,9 +57,9 @@ public:
|
||||
return reinterpret_cast<const void*>(&it->first);
|
||||
}
|
||||
|
||||
int ReleaseStringConstant(const void *str)
|
||||
int ReleaseStringConstant(const void *str) override
|
||||
{
|
||||
if (str == 0)
|
||||
if (str == nullptr)
|
||||
return asERROR;
|
||||
|
||||
int ret = asSUCCESS;
|
||||
@@ -68,7 +68,7 @@ public:
|
||||
// threads, so it is necessary to use a mutex.
|
||||
asAcquireExclusiveLock();
|
||||
|
||||
map_t::iterator it = stringCache.find(*reinterpret_cast<const string*>(str));
|
||||
auto it = stringCache.find(*reinterpret_cast<const string*>(str));
|
||||
if (it == stringCache.end())
|
||||
ret = asERROR;
|
||||
else
|
||||
@@ -83,9 +83,9 @@ public:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int GetRawStringData(const void *str, char *data, asUINT *length) const
|
||||
int GetRawStringData(const void *str, char *data, asUINT *length) const override
|
||||
{
|
||||
if (str == 0)
|
||||
if (str == nullptr)
|
||||
return asERROR;
|
||||
|
||||
if (length)
|
||||
@@ -98,17 +98,17 @@ public:
|
||||
}
|
||||
|
||||
// THe access to the string cache is protected with the common mutex provided by AngelScript
|
||||
map_t stringCache;
|
||||
map_t stringCache = {};
|
||||
};
|
||||
|
||||
static CStdStringFactory *stringFactory = 0;
|
||||
static CStdStringFactory *stringFactory = nullptr;
|
||||
|
||||
// TODO: Make this public so the application can also use the string
|
||||
// factory and share the string constants if so desired, or to
|
||||
// monitor the size of the string factory cache.
|
||||
CStdStringFactory *GetStdStringFactorySingleton()
|
||||
{
|
||||
if( stringFactory == 0 )
|
||||
if( stringFactory == nullptr )
|
||||
{
|
||||
// The following instance will be destroyed by the global
|
||||
// CStdStringFactoryCleaner instance upon application shutdown
|
||||
@@ -122,7 +122,7 @@ class CStdStringFactoryCleaner
|
||||
public:
|
||||
~CStdStringFactoryCleaner()
|
||||
{
|
||||
if (stringFactory)
|
||||
if (stringFactory != nullptr)
|
||||
{
|
||||
// Only delete the string factory if the stringCache is empty
|
||||
// If it is not empty, it means that someone might still attempt
|
||||
@@ -133,13 +133,13 @@ public:
|
||||
if (stringFactory->stringCache.empty())
|
||||
{
|
||||
delete stringFactory;
|
||||
stringFactory = 0;
|
||||
stringFactory = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static CStdStringFactoryCleaner cleaner;
|
||||
static CStdStringFactoryCleaner cleaner = {};
|
||||
|
||||
|
||||
static void ConstructString(string *thisPointer)
|
||||
@@ -461,12 +461,12 @@ static void StringResize(asUINT l, string &str)
|
||||
// string formatInt(int64 val, const string &in options, uint width)
|
||||
static string formatInt(asINT64 value, const string &options, asUINT width)
|
||||
{
|
||||
bool leftJustify = options.find("l") != string::npos;
|
||||
bool padWithZero = options.find("0") != string::npos;
|
||||
bool alwaysSign = options.find("+") != string::npos;
|
||||
bool spaceOnSign = options.find(" ") != string::npos;
|
||||
bool hexSmall = options.find("h") != string::npos;
|
||||
bool hexLarge = options.find("H") != string::npos;
|
||||
bool leftJustify = options.find('l') != string::npos;
|
||||
bool padWithZero = options.find('0') != string::npos;
|
||||
bool alwaysSign = options.find('+') != string::npos;
|
||||
bool spaceOnSign = options.find(' ') != string::npos;
|
||||
bool hexSmall = options.find('h') != string::npos;
|
||||
bool hexLarge = options.find('H') != string::npos;
|
||||
|
||||
string fmt = "%";
|
||||
if( leftJustify ) fmt += "-";
|
||||
@@ -505,12 +505,12 @@ static string formatInt(asINT64 value, const string &options, asUINT width)
|
||||
// string formatUInt(uint64 val, const string &in options, uint width)
|
||||
static string formatUInt(asQWORD value, const string &options, asUINT width)
|
||||
{
|
||||
bool leftJustify = options.find("l") != string::npos;
|
||||
bool padWithZero = options.find("0") != string::npos;
|
||||
bool alwaysSign = options.find("+") != string::npos;
|
||||
bool spaceOnSign = options.find(" ") != string::npos;
|
||||
bool hexSmall = options.find("h") != string::npos;
|
||||
bool hexLarge = options.find("H") != string::npos;
|
||||
bool leftJustify = options.find('l') != string::npos;
|
||||
bool padWithZero = options.find('0') != string::npos;
|
||||
bool alwaysSign = options.find('+') != string::npos;
|
||||
bool spaceOnSign = options.find(' ') != string::npos;
|
||||
bool hexSmall = options.find('h') != string::npos;
|
||||
bool hexLarge = options.find('H') != string::npos;
|
||||
|
||||
string fmt = "%";
|
||||
if( leftJustify ) fmt += "-";
|
||||
@@ -549,12 +549,12 @@ static string formatUInt(asQWORD value, const string &options, asUINT width)
|
||||
// string formatFloat(double val, const string &in options, uint width, uint precision)
|
||||
static string formatFloat(double value, const string &options, asUINT width, asUINT precision)
|
||||
{
|
||||
bool leftJustify = options.find("l") != string::npos;
|
||||
bool padWithZero = options.find("0") != string::npos;
|
||||
bool alwaysSign = options.find("+") != string::npos;
|
||||
bool spaceOnSign = options.find(" ") != string::npos;
|
||||
bool expSmall = options.find("e") != string::npos;
|
||||
bool expLarge = options.find("E") != string::npos;
|
||||
bool leftJustify = options.find('l') != string::npos;
|
||||
bool padWithZero = options.find('0') != string::npos;
|
||||
bool alwaysSign = options.find('+') != string::npos;
|
||||
bool spaceOnSign = options.find(' ') != string::npos;
|
||||
bool expSmall = options.find('e') != string::npos;
|
||||
bool expLarge = options.find('E') != string::npos;
|
||||
|
||||
string fmt = "%";
|
||||
if( leftJustify ) fmt += "-";
|
||||
@@ -734,7 +734,7 @@ static string StringSubString(asUINT start, int count, const string &str)
|
||||
// makro, so this wrapper was introduced as work around.
|
||||
static bool StringEquals(const std::string& lhs, const std::string& rhs)
|
||||
{
|
||||
return lhs == rhs;
|
||||
return lhs == rhs;
|
||||
}
|
||||
|
||||
void RegisterStdString_Native(asIScriptEngine *engine)
|
||||
|
||||
Reference in New Issue
Block a user