From 111a77e81827705119fb82f8191a41dd8752a888 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Sun, 7 Mar 2021 17:03:20 +0100 Subject: Cleanup: remove dead code --- source/blender/blenkernel/intern/simulation.cc | 1 - source/blender/functions/CMakeLists.txt | 3 - source/blender/functions/FN_attributes_ref.hh | 341 --------------------- source/blender/functions/intern/attributes_ref.cc | 78 ----- .../functions/tests/FN_attributes_ref_test.cc | 97 ------ 5 files changed, 520 deletions(-) delete mode 100644 source/blender/functions/FN_attributes_ref.hh delete mode 100644 source/blender/functions/intern/attributes_ref.cc delete mode 100644 source/blender/functions/tests/FN_attributes_ref_test.cc (limited to 'source/blender') diff --git a/source/blender/blenkernel/intern/simulation.cc b/source/blender/blenkernel/intern/simulation.cc index 6b46804c251..216563b860d 100644 --- a/source/blender/blenkernel/intern/simulation.cc +++ b/source/blender/blenkernel/intern/simulation.cc @@ -54,7 +54,6 @@ #include "BLI_map.hh" #include "BLT_translation.h" -#include "FN_attributes_ref.hh" #include "FN_multi_function_network_evaluation.hh" #include "FN_multi_function_network_optimization.hh" diff --git a/source/blender/functions/CMakeLists.txt b/source/blender/functions/CMakeLists.txt index 429959f9c33..e4a0b154a07 100644 --- a/source/blender/functions/CMakeLists.txt +++ b/source/blender/functions/CMakeLists.txt @@ -27,7 +27,6 @@ set(INC_SYS ) set(SRC - intern/attributes_ref.cc intern/cpp_types.cc intern/multi_function.cc intern/multi_function_builder.cc @@ -36,7 +35,6 @@ set(SRC intern/multi_function_network_optimization.cc FN_array_spans.hh - FN_attributes_ref.hh FN_cpp_type.hh FN_generic_pointer.hh FN_generic_value_map.hh @@ -63,7 +61,6 @@ blender_add_lib(bf_functions "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") if(WITH_GTESTS) set(TEST_SRC tests/FN_array_spans_test.cc - tests/FN_attributes_ref_test.cc tests/FN_cpp_type_test.cc tests/FN_generic_vector_array_test.cc tests/FN_multi_function_network_test.cc diff --git a/source/blender/functions/FN_attributes_ref.hh b/source/blender/functions/FN_attributes_ref.hh deleted file mode 100644 index a9236f73549..00000000000 --- a/source/blender/functions/FN_attributes_ref.hh +++ /dev/null @@ -1,341 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#pragma once - -/** \file - * \ingroup fn - * - * An AttributesRef references multiple arrays of equal length. Each array has a corresponding name - * and index. - */ - -#include - -#include "FN_spans.hh" - -#include "BLI_linear_allocator.hh" -#include "BLI_map.hh" -#include "BLI_utility_mixins.hh" -#include "BLI_vector_set.hh" - -namespace blender::fn { - -class AttributesInfo; - -class AttributesInfoBuilder : NonCopyable, NonMovable { - private: - LinearAllocator<> allocator_; - VectorSet names_; - Vector types_; - Vector defaults_; - - friend AttributesInfo; - - public: - AttributesInfoBuilder() = default; - ~AttributesInfoBuilder(); - - template bool add(StringRef name, const T &default_value) - { - return this->add(name, CPPType::get(), static_cast(&default_value)); - } - - bool add(StringRef name, const CPPType &type, const void *default_value = nullptr); -}; - -/** - * Stores which attributes are in an AttributesRef. Every attribute has a unique index, a unique - * name, a type and a default value. - */ -class AttributesInfo : NonCopyable, NonMovable { - private: - LinearAllocator<> allocator_; - Map index_by_name_; - Vector name_by_index_; - Vector type_by_index_; - Vector defaults_; - - public: - AttributesInfo() = default; - AttributesInfo(const AttributesInfoBuilder &builder); - ~AttributesInfo(); - - int size() const - { - return name_by_index_.size(); - } - - IndexRange index_range() const - { - return name_by_index_.index_range(); - } - - StringRefNull name_of(int index) const - { - return name_by_index_[index]; - } - - int index_of(StringRef name) const - { - return index_by_name_.lookup_as(name); - } - - const void *default_of(int index) const - { - return defaults_[index]; - } - - const void *default_of(StringRef name) const - { - return this->default_of(this->index_of(name)); - } - - template const T &default_of(int index) const - { - BLI_assert(type_by_index_[index]->is()); - return *static_cast(defaults_[index]); - } - - template const T &default_of(StringRef name) const - { - return this->default_of(this->index_of(name)); - } - - const CPPType &type_of(int index) const - { - return *type_by_index_[index]; - } - - const CPPType &type_of(StringRef name) const - { - return this->type_of(this->index_of(name)); - } - - bool has_attribute(StringRef name, const CPPType &type) const - { - return this->try_index_of(name, type) >= 0; - } - - int try_index_of(StringRef name) const - { - return index_by_name_.lookup_default_as(name, -1); - } - - int try_index_of(StringRef name, const CPPType &type) const - { - int index = this->try_index_of(name); - if (index == -1) { - return -1; - } - else if (this->type_of(index) == type) { - return index; - } - else { - return -1; - } - } -}; - -/** - * References multiple arrays that match the description of an AttributesInfo instance. This class - * is supposed to be relatively cheap to copy. It does not own any of the arrays itself. - */ -class MutableAttributesRef { - private: - const AttributesInfo *info_; - Span buffers_; - IndexRange range_; - - friend class AttributesRef; - - public: - MutableAttributesRef(const AttributesInfo &info, Span buffers, int64_t size) - : MutableAttributesRef(info, buffers, IndexRange(size)) - { - } - - MutableAttributesRef(const AttributesInfo &info, Span buffers, IndexRange range) - : info_(&info), buffers_(buffers), range_(range) - { - } - - int64_t size() const - { - return range_.size(); - } - - IndexRange index_range() const - { - return IndexRange(this->size()); - } - - const AttributesInfo &info() const - { - return *info_; - } - - GMutableSpan get(int index) const - { - const CPPType &type = info_->type_of(index); - void *ptr = POINTER_OFFSET(buffers_[index], type.size() * range_.start()); - return GMutableSpan(type, ptr, range_.size()); - } - - GMutableSpan get(StringRef name) const - { - return this->get(info_->index_of(name)); - } - - template MutableSpan get(int index) const - { - BLI_assert(info_->type_of(index).is()); - return MutableSpan(static_cast(buffers_[index]) + range_.start(), range_.size()); - } - - template MutableSpan get(StringRef name) const - { - return this->get(info_->index_of(name)); - } - - std::optional try_get(StringRef name, const CPPType &type) const - { - int index = info_->try_index_of(name, type); - if (index == -1) { - return {}; - } - else { - return this->get(index); - } - } - - template std::optional> try_get(StringRef name) const - { - int index = info_->try_index_of(name); - if (index == -1) { - return {}; - } - else if (info_->type_of(index).is()) { - return this->get(index); - } - else { - return {}; - } - } - - MutableAttributesRef slice(IndexRange range) const - { - return this->slice(range.start(), range.size()); - } - - MutableAttributesRef slice(int64_t start, int64_t size) const - { - return MutableAttributesRef(*info_, buffers_, range_.slice(start, size)); - } -}; - -class AttributesRef { - private: - const AttributesInfo *info_; - Span buffers_; - IndexRange range_; - - public: - AttributesRef(const AttributesInfo &info, Span buffers, int64_t size) - : AttributesRef(info, buffers, IndexRange(size)) - { - } - - AttributesRef(const AttributesInfo &info, Span buffers, IndexRange range) - : info_(&info), buffers_(buffers), range_(range) - { - } - - AttributesRef(MutableAttributesRef attributes) - : info_(attributes.info_), buffers_(attributes.buffers_), range_(attributes.range_) - { - } - - int64_t size() const - { - return range_.size(); - } - - const AttributesInfo &info() const - { - return *info_; - } - - GSpan get(int index) const - { - const CPPType &type = info_->type_of(index); - const void *ptr = POINTER_OFFSET(buffers_[index], type.size() * range_.start()); - return GSpan(type, ptr, range_.size()); - } - - GSpan get(StringRef name) const - { - return this->get(info_->index_of(name)); - } - - template Span get(int index) const - { - BLI_assert(info_->type_of(index).is()); - return Span(static_cast(buffers_[index]) + range_.start(), range_.size()); - } - - template Span get(StringRef name) const - { - return this->get(info_->index_of(name)); - } - - std::optional try_get(StringRef name, const CPPType &type) const - { - int64_t index = info_->try_index_of(name, type); - if (index == -1) { - return {}; - } - else { - return this->get(index); - } - } - - template std::optional> try_get(StringRef name) const - { - int index = info_->try_index_of(name); - if (index == -1) { - return {}; - } - else if (info_->type_of(index).is()) { - return this->get(index); - } - else { - return {}; - } - } - - AttributesRef slice(IndexRange range) const - { - return this->slice(range.start(), range.size()); - } - - AttributesRef slice(int64_t start, int64_t size) const - { - return AttributesRef(*info_, buffers_, range_.slice(start, size)); - } -}; - -} // namespace blender::fn diff --git a/source/blender/functions/intern/attributes_ref.cc b/source/blender/functions/intern/attributes_ref.cc deleted file mode 100644 index 9f1e7fa65e5..00000000000 --- a/source/blender/functions/intern/attributes_ref.cc +++ /dev/null @@ -1,78 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "FN_attributes_ref.hh" - -namespace blender::fn { - -AttributesInfoBuilder::~AttributesInfoBuilder() -{ - for (int i : defaults_.index_range()) { - types_[i]->destruct(defaults_[i]); - } -} - -bool AttributesInfoBuilder::add(StringRef name, const CPPType &type, const void *default_value) -{ - if (name.size() == 0) { - std::cout << "Warning: Tried to add an attribute with empty name.\n"; - return false; - } - if (names_.add_as(name)) { - types_.append(&type); - - if (default_value == nullptr) { - default_value = type.default_value(); - } - void *dst = allocator_.allocate(type.size(), type.alignment()); - type.copy_to_uninitialized(default_value, dst); - defaults_.append(dst); - return true; - } - - const CPPType &stored_type = *types_[names_.index_of_as(name)]; - if (stored_type != type) { - std::cout << "Warning: Tried to add an attribute twice with different types (" << name << ": " - << stored_type.name() << ", " << type.name() << ").\n"; - } - return false; -} - -AttributesInfo::AttributesInfo(const AttributesInfoBuilder &builder) -{ - for (int i : builder.types_.index_range()) { - StringRefNull name = allocator_.copy_string(builder.names_[i]); - const CPPType &type = *builder.types_[i]; - const void *default_value = builder.defaults_[i]; - - index_by_name_.add_new(name, i); - name_by_index_.append(name); - type_by_index_.append(&type); - - void *dst = allocator_.allocate(type.size(), type.alignment()); - type.copy_to_uninitialized(default_value, dst); - defaults_.append(dst); - } -} - -AttributesInfo::~AttributesInfo() -{ - for (int i : defaults_.index_range()) { - type_by_index_[i]->destruct(defaults_[i]); - } -} - -} // namespace blender::fn diff --git a/source/blender/functions/tests/FN_attributes_ref_test.cc b/source/blender/functions/tests/FN_attributes_ref_test.cc deleted file mode 100644 index 3a5e4743c1e..00000000000 --- a/source/blender/functions/tests/FN_attributes_ref_test.cc +++ /dev/null @@ -1,97 +0,0 @@ -/* Apache License, Version 2.0 */ - -#include "BLI_float3.hh" -#include "FN_attributes_ref.hh" - -#include "testing/testing.h" - -namespace blender::fn::tests { - -TEST(attributes_info, BuildEmpty) -{ - AttributesInfoBuilder info_builder; - AttributesInfo info{info_builder}; - - EXPECT_EQ(info.size(), 0); -} - -TEST(attributes_info, AddSameNameTwice) -{ - AttributesInfoBuilder info_builder; - info_builder.add("A", 4); - info_builder.add("A", 5); - AttributesInfo info{info_builder}; - EXPECT_EQ(info.size(), 1); - EXPECT_TRUE(info.has_attribute("A", CPPType::get())); - EXPECT_FALSE(info.has_attribute("B", CPPType::get())); - EXPECT_FALSE(info.has_attribute("A", CPPType::get())); - EXPECT_EQ(info.default_of("A"), 4); - EXPECT_EQ(info.name_of(0), "A"); - EXPECT_EQ(info.index_range().start(), 0); - EXPECT_EQ(info.index_range().one_after_last(), 1); -} - -TEST(attributes_info, BuildWithDefaultString) -{ - AttributesInfoBuilder info_builder; - info_builder.add("A", CPPType::get()); - AttributesInfo info{info_builder}; - EXPECT_EQ(info.default_of("A"), ""); -} - -TEST(attributes_info, BuildWithGivenDefault) -{ - AttributesInfoBuilder info_builder; - info_builder.add("A", "hello world"); - AttributesInfo info{info_builder}; - const void *default_value = info.default_of("A"); - EXPECT_EQ(*(const std::string *)default_value, "hello world"); - EXPECT_EQ(info.type_of("A"), CPPType::get()); -} - -TEST(mutable_attributes_ref, ComplexTest) -{ - AttributesInfoBuilder info_builder; - info_builder.add("Position", {0, 0, 10}); - info_builder.add("ID", 0); - info_builder.add("Size", 0.5f); - info_builder.add("Name", ""); - AttributesInfo info{info_builder}; - - int amount = 5; - Array positions(amount); - Array ids(amount, 0); - Array sizes(amount); - Array names(amount); - - Array buffers = {positions.data(), ids.data(), sizes.data(), names.data()}; - MutableAttributesRef attributes{info, buffers, IndexRange(1, 3)}; - EXPECT_EQ(attributes.size(), 3); - EXPECT_EQ(attributes.info().size(), 4); - EXPECT_EQ(attributes.get("Position").data(), positions.data() + 1); - EXPECT_EQ(attributes.get("ID").data(), ids.data() + 1); - EXPECT_EQ(attributes.get("Size").data(), sizes.data() + 1); - EXPECT_EQ(attributes.get("Name").data(), names.data() + 1); - - EXPECT_EQ(attributes.get("ID").size(), 3); - EXPECT_EQ(attributes.get("ID").size(), 3); - - EXPECT_EQ(ids[2], 0); - MutableSpan ids_span = attributes.get("ID"); - ids_span[1] = 42; - EXPECT_EQ(ids[2], 42); - - EXPECT_FALSE(attributes.try_get("not existant").has_value()); - EXPECT_FALSE(attributes.try_get("Position").has_value()); - EXPECT_TRUE(attributes.try_get("Position").has_value()); - EXPECT_FALSE(attributes.try_get("not existant", CPPType::get()).has_value()); - EXPECT_FALSE(attributes.try_get("Position", CPPType::get()).has_value()); - EXPECT_TRUE(attributes.try_get("Position", CPPType::get()).has_value()); - - MutableAttributesRef sliced = attributes.slice(IndexRange(1, 2)); - EXPECT_EQ(sliced.size(), 2); - sliced.get("ID")[0] = 100; - EXPECT_EQ(ids[2], 100); -} - -} // namespace blender::fn::tests -- cgit v1.2.3