aboutsummaryrefslogtreecommitdiff
path: root/primedev/util
diff options
context:
space:
mode:
Diffstat (limited to 'primedev/util')
-rw-r--r--primedev/util/printcommands.cpp4
-rw-r--r--primedev/util/printmaps.cpp4
-rw-r--r--primedev/util/utils.h20
3 files changed, 24 insertions, 4 deletions
diff --git a/primedev/util/printcommands.cpp b/primedev/util/printcommands.cpp
index 34d56666..20ebfffc 100644
--- a/primedev/util/printcommands.cpp
+++ b/primedev/util/printcommands.cpp
@@ -52,12 +52,12 @@ void PrintCommandHelpDialogue(const ConCommandBase* command, const char* name)
void TryPrintCvarHelpForCommand(const char* pCommand)
{
// try to display help text for an inputted command string from the console
- int pCommandLen = strlen(pCommand);
+ size_t pCommandLen = strlen(pCommand);
char* pCvarStr = new char[pCommandLen];
strcpy(pCvarStr, pCommand);
// trim whitespace from right
- for (int i = pCommandLen - 1; i; i--)
+ for (size_t i = pCommandLen - 1; i; i--)
{
if (isspace(pCvarStr[i]))
pCvarStr[i] = '\0';
diff --git a/primedev/util/printmaps.cpp b/primedev/util/printmaps.cpp
index d3253605..906bed06 100644
--- a/primedev/util/printmaps.cpp
+++ b/primedev/util/printmaps.cpp
@@ -136,9 +136,9 @@ int, __fastcall, (const char *const cmdname, const char *const partial, char com
RefreshMapList();
// use a custom autocomplete func for all map loading commands
- const int cmdLength = strlen(cmdname);
+ const size_t cmdLength = strlen(cmdname);
const char* query = partial + cmdLength;
- const int queryLength = strlen(query);
+ const size_t queryLength = strlen(query);
int numMaps = 0;
for (int i = 0; i < vMapList.size() && numMaps < COMMAND_COMPLETION_MAXITEMS; i++)
diff --git a/primedev/util/utils.h b/primedev/util/utils.h
index 85922692..1a419607 100644
--- a/primedev/util/utils.h
+++ b/primedev/util/utils.h
@@ -1,3 +1,23 @@
#pragma once
void RemoveAsciiControlSequences(char* str, bool allow_color_codes);
+
+class ScopeGuard
+{
+public:
+ auto operator=(ScopeGuard&) = delete;
+ ScopeGuard(ScopeGuard&) = delete;
+
+ ScopeGuard(std::function<void()> callback) : m_callback(callback) {}
+ ~ScopeGuard()
+ {
+ m_callback();
+ }
+ void Dismiss()
+ {
+ m_callback = [] {};
+ }
+
+private:
+ std::function<void()> m_callback;
+};