flatten 20260225
This commit is contained in:
233
tjp/core/string/Dictionary.inl
Normal file
233
tjp/core/string/Dictionary.inl
Normal file
@@ -0,0 +1,233 @@
|
||||
// License: Modified MIT (NON-AI)
|
||||
// See the LICENSE file in the root directory for license information.
|
||||
// Copyright 2025 Timothy Prepscius
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace tjp {
|
||||
namespace core {
|
||||
namespace string_dictionary {
|
||||
|
||||
// ----
|
||||
|
||||
inline
|
||||
Entry::Entry(const StrongPtr<Dictionary> &container_, std::string &&value_) :
|
||||
container(container_),
|
||||
value(std::move(value_))
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
Entry::~Entry ()
|
||||
{
|
||||
if (container)
|
||||
container->remove(this);
|
||||
}
|
||||
|
||||
// ----
|
||||
|
||||
inline
|
||||
Reference::operator const std::string &() const
|
||||
{
|
||||
return entry->value;
|
||||
}
|
||||
|
||||
inline
|
||||
Reference::operator const std::string_view () const
|
||||
{
|
||||
return entry->value;
|
||||
}
|
||||
|
||||
inline
|
||||
bool operator ==(const Reference &lhs, const Reference &rhs)
|
||||
{
|
||||
return (const std::string &)lhs == (const std::string &)rhs;
|
||||
}
|
||||
|
||||
inline
|
||||
bool operator ==(const Reference &lhs, const std::string &r)
|
||||
{
|
||||
return (const std::string &)lhs == r;
|
||||
}
|
||||
|
||||
inline
|
||||
bool operator ==(const Reference &lhs, const std::string_view &r)
|
||||
{
|
||||
return (const std::string &)lhs == r;
|
||||
}
|
||||
|
||||
inline
|
||||
bool operator ==(const Reference &lhs, const char *r)
|
||||
{
|
||||
return (const std::string &)lhs == r;
|
||||
}
|
||||
|
||||
inline
|
||||
bool operator ==(const std::string &l, const Reference &rhs)
|
||||
{
|
||||
return l == (const std::string &)rhs;
|
||||
}
|
||||
|
||||
inline
|
||||
bool operator ==(const std::string_view &l, const Reference &rhs)
|
||||
{
|
||||
return l == (const std::string &)rhs;
|
||||
}
|
||||
|
||||
inline
|
||||
bool operator ==(const char *l, const Reference &rhs)
|
||||
{
|
||||
return l == (const std::string &)rhs;
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline
|
||||
bool operator !=(const Reference &lhs, const Reference &rhs)
|
||||
{
|
||||
return (const std::string &)lhs != (const std::string &)rhs;
|
||||
}
|
||||
|
||||
inline
|
||||
bool operator !=(const Reference &lhs, const std::string &r)
|
||||
{
|
||||
return (const std::string &)lhs != r;
|
||||
}
|
||||
|
||||
inline
|
||||
bool operator !=(const Reference &lhs, const std::string_view &r)
|
||||
{
|
||||
return (const std::string &)lhs != r;
|
||||
}
|
||||
|
||||
inline
|
||||
bool operator !=(const Reference &lhs, const char *r)
|
||||
{
|
||||
return (const std::string &)lhs != r;
|
||||
}
|
||||
|
||||
inline
|
||||
bool operator !=(const std::string &l, const Reference &rhs)
|
||||
{
|
||||
return l != (const std::string &)rhs;
|
||||
}
|
||||
|
||||
inline
|
||||
bool operator !=(const std::string_view &l, const Reference &rhs)
|
||||
{
|
||||
return l != (const std::string &)rhs;
|
||||
}
|
||||
|
||||
inline
|
||||
bool operator !=(const char *l, const Reference &rhs)
|
||||
{
|
||||
return l != (const std::string &)rhs;
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline
|
||||
bool operator <(const Reference &lhs, const Reference &rhs)
|
||||
{
|
||||
return (const std::string &)lhs < (const std::string &)rhs;
|
||||
}
|
||||
|
||||
inline
|
||||
bool operator <(const Reference &lhs, const std::string &r)
|
||||
{
|
||||
return (const std::string &)lhs < r;
|
||||
}
|
||||
|
||||
inline
|
||||
bool operator <(const Reference &lhs, const std::string_view &r)
|
||||
{
|
||||
return (const std::string &)lhs < r;
|
||||
}
|
||||
|
||||
inline
|
||||
bool operator <(const Reference &lhs, const char *r)
|
||||
{
|
||||
return (const std::string &)lhs < r;
|
||||
}
|
||||
|
||||
inline
|
||||
bool operator <(const std::string &l, const Reference &rhs)
|
||||
{
|
||||
return l < (const std::string &)rhs;
|
||||
}
|
||||
|
||||
inline
|
||||
bool operator <(const std::string_view &l, const Reference &rhs)
|
||||
{
|
||||
return l < (const std::string &)rhs;
|
||||
}
|
||||
|
||||
inline
|
||||
bool operator <(const char *l, const Reference &rhs)
|
||||
{
|
||||
return l < (const std::string &)rhs;
|
||||
}
|
||||
|
||||
|
||||
// ----
|
||||
|
||||
inline
|
||||
void Dictionary::remove(Entry *entry)
|
||||
{
|
||||
auto i = entries.find(entry->value);
|
||||
if (i != entries.end())
|
||||
entries.erase(i);
|
||||
}
|
||||
|
||||
inline
|
||||
Reference Dictionary::get(const std::string_view &value)
|
||||
{
|
||||
auto i = entries.find(value);
|
||||
if (i != entries.end())
|
||||
return { strong(i->second) };
|
||||
|
||||
auto entry = strong<Entry>(Entry { strong_this(this), std::string(value) });
|
||||
entries.emplace(entry->value, entry);
|
||||
return { std::move(entry) };
|
||||
}
|
||||
|
||||
inline
|
||||
Reference Dictionary::get(const std::string &value)
|
||||
{
|
||||
auto i = entries.find(value);
|
||||
if (i != entries.end())
|
||||
return { strong(i->second) };
|
||||
|
||||
auto entry = strong<Entry>(strong_this(this), std::string(value));
|
||||
entries.emplace(entry->value, entry);
|
||||
return { std::move(entry) };
|
||||
}
|
||||
|
||||
inline
|
||||
Reference Dictionary::get(std::string &&value)
|
||||
{
|
||||
auto i = entries.find(value);
|
||||
if (i != entries.end())
|
||||
return { strong(i->second) };
|
||||
|
||||
auto entry = strong<Entry>(strong_this(this), std::move(value));
|
||||
entries.emplace(entry->value, entry);
|
||||
return { std::move(entry) };
|
||||
}
|
||||
|
||||
inline
|
||||
Reference Dictionary::get(const char *value)
|
||||
{
|
||||
auto i = entries.find(value);
|
||||
if (i != entries.end())
|
||||
return { strong(i->second) };
|
||||
|
||||
auto entry = strong<Entry>(strong_this(this), std::string(value));
|
||||
entries.emplace(entry->value, entry);
|
||||
return { std::move(entry) };
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user