Skip to content
Merged
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 @@ 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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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(
Expand Down
Loading