Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenlib/BLI_cpp_type_make.hh
- This file was moved from source/blender/functions/FN_cpp_type_make.hh.
| /* SPDX-License-Identifier: GPL-2.0-or-later */ | /* SPDX-License-Identifier: GPL-2.0-or-later */ | ||||
| #pragma once | #pragma once | ||||
| /** \file | /** \file | ||||
| * \ingroup fn | * \ingroup bli | ||||
| */ | */ | ||||
| #include "BLI_cpp_type.hh" | |||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "FN_cpp_type.hh" | |||||
| namespace blender::fn::cpp_type_util { | namespace blender::cpp_type_util { | ||||
| template<typename T> void default_construct_cb(void *ptr) | template<typename T> void default_construct_cb(void *ptr) | ||||
| { | { | ||||
| new (ptr) T; | new (ptr) T; | ||||
| } | } | ||||
| template<typename T> void default_construct_indices_cb(void *ptr, IndexMask mask) | template<typename T> void default_construct_indices_cb(void *ptr, IndexMask mask) | ||||
| { | { | ||||
| mask.foreach_index([&](int64_t i) { new (static_cast<T *>(ptr) + i) T; }); | mask.foreach_index([&](int64_t i) { new (static_cast<T *>(ptr) + i) T; }); | ||||
| ▲ Show 20 Lines • Show All 143 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| template<typename T> uint64_t hash_cb(const void *value) | template<typename T> uint64_t hash_cb(const void *value) | ||||
| { | { | ||||
| const T &value_ = *static_cast<const T *>(value); | const T &value_ = *static_cast<const T *>(value); | ||||
| return get_default_hash(value_); | return get_default_hash(value_); | ||||
| } | } | ||||
| } // namespace blender::fn::cpp_type_util | } // namespace blender::cpp_type_util | ||||
| namespace blender::fn { | namespace blender { | ||||
| template<typename T, CPPTypeFlags Flags> | template<typename T, CPPTypeFlags Flags> | ||||
| CPPType::CPPType(CPPTypeParam<T, Flags> /* unused */, StringRef debug_name) | CPPType::CPPType(CPPTypeParam<T, Flags> /* unused */, StringRef debug_name) | ||||
| { | { | ||||
| using namespace cpp_type_util; | using namespace cpp_type_util; | ||||
| debug_name_ = debug_name; | debug_name_ = debug_name; | ||||
| size_ = (int64_t)sizeof(T); | size_ = (int64_t)sizeof(T); | ||||
| ▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | if constexpr ((bool)(Flags & CPPTypeFlags::EqualityComparable)) { | ||||
| is_equal_ = is_equal_cb<T>; | is_equal_ = is_equal_cb<T>; | ||||
| } | } | ||||
| alignment_mask_ = (uintptr_t)alignment_ - (uintptr_t)1; | alignment_mask_ = (uintptr_t)alignment_ - (uintptr_t)1; | ||||
| has_special_member_functions_ = (default_construct_ && copy_construct_ && copy_assign_ && | has_special_member_functions_ = (default_construct_ && copy_construct_ && copy_assign_ && | ||||
| move_construct_ && move_assign_ && destruct_); | move_construct_ && move_assign_ && destruct_); | ||||
| } | } | ||||
| } // namespace blender::fn | } // namespace blender | ||||
| #define MAKE_CPP_TYPE(IDENTIFIER, TYPE_NAME, FLAGS) \ | #define MAKE_CPP_TYPE(IDENTIFIER, TYPE_NAME, FLAGS) \ | ||||
campbellbarton: Since these aren't in a namespace, I'd prefer a more unique prefix `CPP_TYPE_MAKE` or… | |||||
| template<> const blender::fn::CPPType &blender::fn::CPPType::get_impl<TYPE_NAME>() \ | template<> const blender::CPPType &blender::CPPType::get_impl<TYPE_NAME>() \ | ||||
| { \ | { \ | ||||
| static CPPType cpp_type{blender::fn::CPPTypeParam<TYPE_NAME, FLAGS>(), \ | static CPPType cpp_type{blender::CPPTypeParam<TYPE_NAME, FLAGS>(), STRINGIFY(IDENTIFIER)}; \ | ||||
| STRINGIFY(IDENTIFIER)}; \ | |||||
| return cpp_type; \ | return cpp_type; \ | ||||
| } | } | ||||
Since these aren't in a namespace, I'd prefer a more unique prefix CPP_TYPE_MAKE or BLI_CPP_TYPE_MAKEidentifiers (complete more usefully if others are added).