From 5ef77d8283b6cf845270750e8ffa752c11a37465 Mon Sep 17 00:00:00 2001 From: Yoann Le Montagner Date: Thu, 28 May 2026 19:00:55 +0200 Subject: [PATCH] feat(Attribute): attribute filtering on import --- include/geode/basic/attribute_manager.hpp | 19 +++++++++++ src/geode/basic/attribute_manager.cpp | 40 +++++++++++++++++++---- 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/include/geode/basic/attribute_manager.hpp b/include/geode/basic/attribute_manager.hpp index 5d8b23d3c..a110ffd12 100644 --- a/include/geode/basic/attribute_manager.hpp +++ b/include/geode/basic/attribute_manager.hpp @@ -23,6 +23,7 @@ #pragma once +#include #include #include #include @@ -260,9 +261,27 @@ namespace geode void import( const AttributeManager& attribute_manager, absl::Span< const index_t > old2new ); + /*! + * @param[in] attribute_filter Filter the attributes to import based on + * their name. Must return true for an attribute to be imported. + */ + void import( const AttributeManager& attribute_manager, + absl::Span< const index_t > old2new, + const std::function< bool( const std::string& ) >& + attribute_filter ); + void import( const AttributeManager& attribute_manager, const GenericMapping< index_t >& old2new_mapping ); + /*! + * @param[in] attribute_filter Filter the attributes to import based on + * their name. Must return true for an attribute to be imported. + */ + void import( const AttributeManager& attribute_manager, + const GenericMapping< index_t >& old2new_mapping, + const std::function< bool( const std::string& ) >& + attribute_filter ); + private: friend class bitsery::Access; template < typename Archive > diff --git a/src/geode/basic/attribute_manager.cpp b/src/geode/basic/attribute_manager.cpp index 03ca8b4f9..df04601cd 100644 --- a/src/geode/basic/attribute_manager.cpp +++ b/src/geode/basic/attribute_manager.cpp @@ -253,12 +253,15 @@ namespace geode void import( const AttributeManager::Impl &attribute_manager, absl::Span< const index_t > old2new, - const AttributeBase::AttributeKey &key ) + const AttributeBase::AttributeKey &key, + const std::function< bool( const std::string & ) > + &attribute_filter ) { for( const auto &[attribute_name, attribute_from] : attribute_manager.attributes_ ) { - if( !attribute_from->properties().transferable ) + if( !attribute_filter( attribute_name ) + || !attribute_from->properties().transferable ) { continue; } @@ -282,12 +285,15 @@ namespace geode void import( const AttributeManager::Impl &attribute_manager, const GenericMapping< index_t > &old2new_mapping, - const AttributeBase::AttributeKey &key ) + const AttributeBase::AttributeKey &key, + const std::function< bool( const std::string & ) > + &attribute_filter ) { for( const auto &[attribute_name, attribute_from] : attribute_manager.attributes_ ) { - if( !attribute_from->properties().transferable ) + if( !attribute_filter( attribute_name ) + || !attribute_from->properties().transferable ) { continue; } @@ -508,13 +514,35 @@ namespace geode void AttributeManager::import( const AttributeManager &attribute_manager, absl::Span< const index_t > old2new ) { - impl_->import( *attribute_manager.impl_, old2new, {} ); + impl_->import( + *attribute_manager.impl_, old2new, {}, []( const std::string & ) { + return true; + } ); + } + + void AttributeManager::import( const AttributeManager &attribute_manager, + absl::Span< const index_t > old2new, + const std::function< bool( const std::string & ) > &attribute_filter ) + { + impl_->import( + *attribute_manager.impl_, old2new, {}, attribute_filter ); } void AttributeManager::import( const AttributeManager &attribute_manager, const GenericMapping< index_t > &old2new_mapping ) { - impl_->import( *attribute_manager.impl_, old2new_mapping, {} ); + impl_->import( *attribute_manager.impl_, old2new_mapping, {}, + []( const std::string & ) { + return true; + } ); + } + + void AttributeManager::import( const AttributeManager &attribute_manager, + const GenericMapping< index_t > &old2new_mapping, + const std::function< bool( const std::string & ) > &attribute_filter ) + { + impl_->import( + *attribute_manager.impl_, old2new_mapping, {}, attribute_filter ); } void AttributeManager::rename_attribute(