Files
MapLibreParticleLab/include/mln/util/string_indexer.hpp
Bart Louwers 2a8ebc4906 core: rename mbgl directories to mln (#4511)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2026-08-22 20:50:14 +02:00

46 lines
914 B
C++

#pragma once
#include <cstdint>
#include <cstddef>
#include <string>
#include <string_view>
#include <unordered_map>
#include <vector>
#include <mutex>
#include <shared_mutex>
namespace mln {
using StringIdentity = std::size_t;
class StringIndexer {
protected:
StringIndexer();
public:
StringIndexer(StringIndexer const&) = delete;
StringIndexer(StringIndexer&&) = delete;
void operator=(StringIndexer const&) = delete;
~StringIndexer() = default;
StringIdentity get(std::string_view);
std::string get(const StringIdentity id);
size_t size();
protected:
friend StringIndexer& stringIndexer();
std::unordered_map<std::string_view, StringIdentity> stringToIdentity;
std::vector<StringIdentity> identityToString;
std::vector<char> buffer;
std::shared_mutex sharedMutex;
};
/// StringIndexer singleton
StringIndexer& stringIndexer();
} // namespace mln