91 lines
2.4 KiB
C++
91 lines
2.4 KiB
C++
// License: Modified MIT (NON-AI)
|
|
// See the LICENSE file in the root directory for license information.
|
|
// Copyright 2025 Timothy Prepscius
|
|
|
|
#pragma once
|
|
|
|
#include <map>
|
|
#include <string>
|
|
#include <string_view>
|
|
|
|
#include "../threads/Lock.hpp"
|
|
#include "../ptr/Ptr.hpp"
|
|
|
|
namespace tjp {
|
|
namespace core {
|
|
namespace string_dictionary {
|
|
|
|
struct Instance;
|
|
struct Entry;
|
|
struct Dictionary;
|
|
|
|
struct Reference
|
|
{
|
|
StrongPtr<Entry> entry;
|
|
|
|
operator const std::string &() const;
|
|
operator const std::string_view () const;
|
|
} ;
|
|
|
|
struct Entry
|
|
{
|
|
StrongPtr<Dictionary> container;
|
|
const std::string value;
|
|
|
|
Entry(const StrongPtr<Dictionary> &container, std::string &&string);
|
|
|
|
~Entry ();
|
|
} ;
|
|
|
|
bool operator ==(const Reference &lhs, const Reference &rhs);
|
|
bool operator ==(const Reference &lhs, const std::string &r);
|
|
bool operator ==(const Reference &lhs, const std::string_view &r);
|
|
bool operator ==(const Reference &lhs, const char *r);
|
|
|
|
bool operator ==(const std::string &l, const Reference &rhs);
|
|
bool operator ==(const std::string_view &l, const Reference &rhs);
|
|
bool operator ==(const char *l, const Reference &rhs);
|
|
|
|
bool operator !=(const Reference &lhs, const Reference &rhs);
|
|
bool operator !=(const Reference &lhs, const std::string &r);
|
|
bool operator !=(const Reference &lhs, const std::string_view &r);
|
|
bool operator !=(const Reference &lhs, const char *r);
|
|
|
|
bool operator !=(const std::string &l, const Reference &rhs);
|
|
bool operator !=(const std::string_view &l, const Reference &rhs);
|
|
bool operator !=(const char *l, const Reference &rhs);
|
|
|
|
bool operator <(const Reference &lhs, const Reference &rhs);
|
|
bool operator <(const Reference &lhs, const std::string &r);
|
|
bool operator <(const Reference &lhs, const std::string_view &r);
|
|
bool operator <(const Reference &lhs, const char *r);
|
|
|
|
bool operator <(const std::string &l, const Reference &rhs);
|
|
bool operator <(const std::string_view &l, const Reference &rhs);
|
|
bool operator <(const char *l, const Reference &rhs);
|
|
|
|
// ----
|
|
|
|
struct Dictionary : StrongThis<Dictionary>
|
|
{
|
|
Mutex mutex;
|
|
std::map<std::string_view, WeakPtr<Entry>> entries;
|
|
|
|
void remove(Entry *entry);
|
|
|
|
Reference get(const std::string_view &value);
|
|
Reference get(const std::string &value);
|
|
Reference get(std::string &&value);
|
|
Reference get(const char *value);
|
|
} ;
|
|
|
|
} // namespace
|
|
|
|
using StringDictionary = string_dictionary::Dictionary;
|
|
using StringRef = string_dictionary::Reference;
|
|
|
|
} // namespace
|
|
} // namespace
|
|
|
|
#include "Dictionary.inl"
|