36 lines
1.6 KiB
C++
36 lines
1.6 KiB
C++
|
#ifndef ARBUTILS_BASICSTRINGVIEW_HPP
|
||
|
#define ARBUTILS_BASICSTRINGVIEW_HPP
|
||
|
#include <string>
|
||
|
|
||
|
namespace ArbUt {
|
||
|
class BasicStringView {
|
||
|
protected:
|
||
|
size_t _length;
|
||
|
uint32_t _hash;
|
||
|
|
||
|
constexpr BasicStringView(size_t length, uint32_t hash) : _length(length), _hash(hash) {}
|
||
|
public:
|
||
|
|
||
|
[[nodiscard]] inline constexpr size_t Length() const noexcept { return _length; }
|
||
|
[[nodiscard]] inline constexpr uint32_t GetHash() const noexcept { return _hash; }
|
||
|
[[nodiscard]] inline constexpr std::size_t operator()(BasicStringView const& s) const noexcept { return _hash; }
|
||
|
[[nodiscard]] inline constexpr operator uint32_t() const noexcept { return _hash; }
|
||
|
[[nodiscard]] inline constexpr bool operator==(const BasicStringView& rhs) const noexcept {
|
||
|
return _hash == rhs._hash;
|
||
|
}
|
||
|
inline constexpr bool operator!=(const BasicStringView& rhs) const noexcept { return _hash != rhs._hash; }
|
||
|
inline constexpr bool Empty() const noexcept { return Length() == 0; }
|
||
|
|
||
|
[[nodiscard]] virtual constexpr const char* c_str() const noexcept = 0;
|
||
|
[[nodiscard]] virtual constexpr std::string_view std_str() const noexcept = 0;
|
||
|
|
||
|
virtual constexpr bool operator==(const std::string_view& rhs) const noexcept = 0;
|
||
|
virtual constexpr bool operator!=(const std::string_view& rhs) const noexcept = 0;
|
||
|
virtual constexpr bool operator==(const char* rhs) const noexcept = 0;
|
||
|
virtual constexpr bool operator!=(const char* rhs) const noexcept = 0;
|
||
|
|
||
|
};
|
||
|
}
|
||
|
|
||
|
#endif // ARBUTILS_BASICSTRINGVIEW_HPP
|