Bitcoin ABC  0.26.3
P2P Digital Currency
hash_type.h
Go to the documentation of this file.
1 // Copyright (c) 2020-2021 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_UTIL_HASH_TYPE_H
6 #define BITCOIN_UTIL_HASH_TYPE_H
7 
8 template <typename HashType> class BaseHash {
9 protected:
10  HashType m_hash;
11 
12 public:
13  BaseHash() : m_hash() {}
14  explicit BaseHash(const HashType &in) : m_hash(in) {}
15 
16  uint8_t *begin() { return m_hash.begin(); }
17 
18  const uint8_t *begin() const { return m_hash.begin(); }
19 
20  uint8_t *end() { return m_hash.end(); }
21 
22  const uint8_t *end() const { return m_hash.end(); }
23 
24  operator std::vector<uint8_t>() const {
25  return std::vector<uint8_t>{m_hash.begin(), m_hash.end()};
26  }
27 
28  std::string ToString() const { return m_hash.ToString(); }
29 
30  bool operator==(const BaseHash<HashType> &other) const noexcept {
31  return m_hash == other.m_hash;
32  }
33 
34  bool operator!=(const BaseHash<HashType> &other) const noexcept {
35  return !(m_hash == other.m_hash);
36  }
37 
38  bool operator<(const BaseHash<HashType> &other) const noexcept {
39  return m_hash < other.m_hash;
40  }
41 
42  size_t size() const { return m_hash.size(); }
43 
44  uint8_t *data() { return m_hash.data(); }
45  const uint8_t *data() const { return m_hash.data(); }
46 };
47 
48 #endif // BITCOIN_UTIL_HASH_TYPE_H
const uint8_t * begin() const
Definition: hash_type.h:18
std::string ToString() const
Definition: hash_type.h:28
size_t size() const
Definition: hash_type.h:42
HashType m_hash
Definition: hash_type.h:10
uint8_t * begin()
Definition: hash_type.h:16
const uint8_t * data() const
Definition: hash_type.h:45
uint8_t * end()
Definition: hash_type.h:20
uint8_t * data()
Definition: hash_type.h:44
bool operator==(const BaseHash< HashType > &other) const noexcept
Definition: hash_type.h:30
bool operator!=(const BaseHash< HashType > &other) const noexcept
Definition: hash_type.h:34
BaseHash(const HashType &in)
Definition: hash_type.h:14
const uint8_t * end() const
Definition: hash_type.h:22
bool operator<(const BaseHash< HashType > &other) const noexcept
Definition: hash_type.h:38
BaseHash()
Definition: hash_type.h:13