qxLib
include
qx
containers
string
string_hash.h
Go to the documentation of this file.
1
/**
2
3
@file string_hash.h
4
@author Khrapov
5
@date 13.11.2020
6
@copyright © Nick Khrapov, 2021. All right reserved.
7
8
**/
9
#pragma once
10
11
#include <
qx/containers/string/string_setup.h
>
12
#include <
qx/containers/string/string_traits.h
>
13
#include <
qx/meta/concepts.h
>
14
15
namespace
qx
16
{
17
18
namespace
details
19
{
20
21
template
<
class
T>
22
concept has_zero_termonated_hash_func_overload =
23
requires(
typename
T::const_pointer pszStr,
size_t
nSeed) { T::hash_function(pszStr, nSeed); };
24
25
};
26
27
/**
28
29
@class basic_string_hash
30
@brief String hash object
31
@tparam traits_t - char traits. \see string_traits.h
32
@author Khrapov
33
@date 13.11.2020
34
35
**/
36
template
<
class
traits_t>
37
class
basic_string_hash
38
{
39
public
:
40
using
const_pointer =
typename
traits_t::const_pointer;
41
using
size_type =
typename
traits_t::size_type;
42
43
constexpr
basic_string_hash
() noexcept =
default
;
44
45
/**
46
@brief basic_string_hash object constructor
47
@param pszString - string first char pointer
48
@param nSize - string size
49
**/
50
constexpr
basic_string_hash
(const_pointer pszString, size_type nSize) noexcept;
51
52
/**
53
@brief basic_string_hash object constructor
54
@param pszString - pointer to string zero terminated
55
**/
56
constexpr
basic_string_hash
(const_pointer pszString) noexcept;
57
58
/**
59
@brief basic_string_hash object constructor
60
@tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
61
@param sString - string-ish container
62
**/
63
template
<range_of_t_c<
typename
traits_t::value_type>
string
_t>
64
constexpr
basic_string_hash
(
const
string_t& sString) noexcept;
65
66
/**
67
@brief operator size_t
68
@retval - hash number
69
**/
70
constexpr
operator
size_t()
const
noexcept;
71
72
private
:
73
size_t
m_nHash = 0;
74
};
75
76
using
cstring_hash
=
basic_string_hash<string_traits::traits<char>
>;
77
using
wstring_hash
=
basic_string_hash<string_traits::traits<wchar_t>
>;
78
using
string_hash
=
basic_string_hash<string_traits::traits<char_type>
>;
79
80
#define QX_STRING_HASH(quote) qx::string_hash(QX_TEXT(quote))
81
82
namespace
literals
83
{
84
85
/**
86
@brief String hash literal for constexpr converting. Can be used with switch-case
87
@param pszStr - literal text pointer
88
@param nSize - literal text size
89
@retval - text hash value
90
**/
91
constexpr
basic_string_hash<string_traits::traits<char>
>
operator
""
_sh(
const
char
* pszStr,
size_t
nSize);
92
93
/**
94
@brief String hash literal for constexpr converting. Can be used with switch-case
95
@param pszStr - literal text pointer
96
@param nSize - literal text size
97
@retval - text hash value
98
**/
99
constexpr
basic_string_hash<string_traits::traits<wchar_t>
>
operator
""
_sh(
const
wchar_t
* pszStr,
size_t
nSize);
100
101
}
// namespace literals
102
103
}
// namespace qx
104
105
#include <
qx/containers/string/string_hash.inl
>
qx::basic_string_hash
String hash object.
Definition:
string_hash.h:38
concepts.h
string_hash.inl
string_setup.h
string_traits.h
Generated by
1.9.1