Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions include/geode/basic/attribute_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#pragma once

#include <functional>
#include <memory>
#include <string>
#include <string_view>
Expand Down Expand Up @@ -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 >
Expand Down
40 changes: 34 additions & 6 deletions src/geode/basic/attribute_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,15 @@

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;
}
Expand All @@ -282,12 +285,15 @@

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;
}
Expand Down Expand Up @@ -319,7 +325,7 @@
}
}

void rename_attribute( std::string_view old_name,

Check warning on line 328 in src/geode/basic/attribute_manager.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/basic/attribute_manager.cpp:328:32 [bugprone-easily-swappable-parameters]

2 adjacent parameters of 'rename_attribute' of similar type ('std::string_view') are easily swapped by mistake
std::string_view new_name,
const AttributeBase::AttributeKey &key )
{
Expand Down Expand Up @@ -403,7 +409,7 @@
void AttributeManager::register_attribute(
std::shared_ptr< AttributeBase > attribute, std::string_view name )
{
return impl_->register_attribute( attribute, name, {} );

Check warning on line 412 in src/geode/basic/attribute_manager.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/basic/attribute_manager.cpp:412:9 [readability-avoid-return-with-void-value]

return statement within a void function should not have a specified return value
}

void AttributeManager::resize( index_t size )
Expand Down Expand Up @@ -508,13 +514,35 @@
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(
Expand Down
Loading