Files
MapLibreParticleLab/include/mbgl/util/string_indexer.hpp
Stefan Karschti 48b9804ca9 String Indexer refactor (#1644)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-09-19 15:25:13 +02:00

48 lines
982 B
C++

#pragma once
#include <cstdint>
#include <cstddef>
#include <string>
#include <string_view>
#include <unordered_map>
#include <vector>
#include <mutex>
#include <shared_mutex>
namespace mbgl {
using StringIdentity = size_t;
class StringIndexer {
public:
StringIndexer(StringIndexer const&) = delete;
StringIndexer(StringIndexer&&) = delete;
void operator=(StringIndexer const&) = delete;
static StringIdentity get(std::string_view);
static const std::string& get(const StringIdentity id);
static void clear();
static size_t size();
protected:
StringIndexer();
~StringIndexer() = default;
using MapType = std::unordered_map<std::string_view, StringIdentity>;
using VectorType = std::vector<std::string>;
static StringIndexer& instance() {
static StringIndexer inst;
return inst;
}
MapType stringToIdentity;
VectorType identityToString;
std::shared_mutex sharedMutex;
};
} // namespace mbgl