diff options
Diffstat (limited to 'source/Utils.cpp')
-rw-r--r-- | source/Utils.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/source/Utils.cpp b/source/Utils.cpp index 1062843..53b3863 100644 --- a/source/Utils.cpp +++ b/source/Utils.cpp @@ -73,3 +73,15 @@ bool Utils::LineContains(glm::ivec2 p1, glm::ivec2 p2, glm::ivec2 candidate) { bool Utils::IsColinear(glm::ivec2 p1, glm::ivec2 p2) { return p1.x == p2.x || p1.y == p2.y; } + +std::string Utils::MakeRandomNumberedName(const char* tag) { + int n = std::rand(); +#define RNG_NAME_PATTERN "Unnamed %s #%d", tag, n + // NOTE: does not include null-terminator + int size = snprintf(nullptr, 0, RNG_NAME_PATTERN); + std::string result; + result.resize(size); // std::string::resize handles storage for null-terminator alreaedy + snprintf(result.data(), size, RNG_NAME_PATTERN); +#undef RNG_NAME_PATTERN + return result; +} |