Blender V5.0
BLI_generic_key.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
10
11#include <cstdint>
12#include <memory>
13
14#include "BLI_assert.h"
15
16namespace blender {
17
27 public:
28 virtual ~GenericKey() = default;
29
31 virtual uint64_t hash() const = 0;
32
37 virtual bool equal_to(const GenericKey &other) const = 0;
38
44 virtual std::unique_ptr<GenericKey> to_storable() const = 0;
45
46 friend bool operator==(const GenericKey &a, const GenericKey &b)
47 {
48 const bool are_equal = a.equal_to(b);
49 /* Ensure that equality check is symmetric. */
50 BLI_assert(are_equal == b.equal_to(a));
51 return are_equal;
52 }
53
54 friend bool operator!=(const GenericKey &a, const GenericKey &b)
55 {
56 return !(a == b);
57 }
58};
59
60} // namespace blender
#define BLI_assert(a)
Definition BLI_assert.h:46
unsigned long long int uint64_t
virtual uint64_t hash() const =0
virtual std::unique_ptr< GenericKey > to_storable() const =0
friend bool operator==(const GenericKey &a, const GenericKey &b)
virtual bool equal_to(const GenericKey &other) const =0
virtual ~GenericKey()=default
friend bool operator!=(const GenericKey &a, const GenericKey &b)