When using clangd or running clang-tidy on headers there are currently many errors. These are noisy in IDEs, make auto fixes impossible, and break features like code completion, refactoring and navigation. This makes source/blender headers work by themselves, which is generally the goal anyway. But #includes and forward declarations were often incomplete. * Add #includes and forward declarations * Add IWYU pragma: export in a few places * Remove some unused #includes (but there are many more) * Tweak ShaderCreateInfo macros to work better with clangd Some types of headers still have errors, these could be fixed or worked around with more investigation. Mostly preprocessor template headers like NOD_static_types.h. Note that that disabling WITH_UNITY_BUILD is required for clangd to work properly, otherwise compile_commands.json does not contain the information for the relevant source files. For more details see the developer docs: https://developer.blender.org/docs/handbook/tooling/clangd/ Pull Request: https://projects.blender.org/blender/blender/pulls/132608
60 lines
1.5 KiB
C++
60 lines
1.5 KiB
C++
/* SPDX-FileCopyrightText: 2024 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
#pragma once
|
|
|
|
/** \file
|
|
* \ingroup bli
|
|
*/
|
|
|
|
#include <memory>
|
|
|
|
#include "BLI_assert.h"
|
|
|
|
namespace blender {
|
|
|
|
/**
|
|
* A #GenericKey allows different kinds of keys to be used in the same data-structure like a #Set
|
|
* or #Map.
|
|
*
|
|
* Typically, the key is stored as `std::reference_wrapper<const GenericKey>` in the
|
|
* data-structure. That implies that one has to make sure that the key is not destructed while it's
|
|
* still in use.
|
|
*/
|
|
class GenericKey {
|
|
public:
|
|
virtual ~GenericKey() = default;
|
|
|
|
/** The hash function has to be implemented by the non-abstract subclass. */
|
|
virtual uint64_t hash() const = 0;
|
|
|
|
/**
|
|
* Check if the other key is equal to this one. Usually that involves a dynamic_cast to check if
|
|
* it has the same type.
|
|
*/
|
|
virtual bool equal_to(const GenericKey &other) const = 0;
|
|
|
|
/**
|
|
* For efficiency, it can be good to not always allocate the key if it's just used for lookup.
|
|
* This method allows the key to be converted into a heap-allocated version that can be stored
|
|
* safely if necessary.
|
|
*/
|
|
virtual std::unique_ptr<GenericKey> to_storable() const = 0;
|
|
|
|
friend bool operator==(const GenericKey &a, const GenericKey &b)
|
|
{
|
|
const bool are_equal = a.equal_to(b);
|
|
/* Ensure that equality check is symmetric. */
|
|
BLI_assert(are_equal == b.equal_to(a));
|
|
return are_equal;
|
|
}
|
|
|
|
friend bool operator!=(const GenericKey &a, const GenericKey &b)
|
|
{
|
|
return !(a == b);
|
|
}
|
|
};
|
|
|
|
} // namespace blender
|