static quintptr theId(const char *str, int n = 0) { static quintptr firstUnusedId = 10 * 1000 * 1000; QTC_ASSERT(str && *str, return 0); StringHolder sh(str, n); int res = idFromString.value(sh, 0); if (res == 0) { res = firstUnusedId++; sh.str = qstrdup(sh.str); idFromString[sh] = res; stringFromId[res] = sh; } return res; }
struct IdCache : public QHash<StringHolder, int> { #ifndef QTC_ALLOW_STATIC_LEAKS ~IdCache() { for (IdCache::iterator it = begin(); it != end(); ++it) delete[](const_cast<char *>(it.key().str)); } #endif }; static int firstUnusedId = Id::IdsPerPlugin * Id::ReservedPlugins; static QHash<int, StringHolder> stringFromId; static IdCache idFromString; static int theId(const char *str, int n = 0) { QTC_ASSERT(str && *str, return 0); StringHolder sh(str, n); int res = idFromString.value(sh, 0); if (res == 0) { res = firstUnusedId++; sh.str = qstrdup(sh.str); idFromString[sh] = res; stringFromId[res] = sh; } return res; }