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
8 changes: 8 additions & 0 deletions include/geode/basic/attribute_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,17 @@ namespace geode
void import( const AttributeManager& attribute_manager,
absl::Span< const index_t > old2new );

void import( const AttributeManager& attribute_manager,
absl::Span< const index_t > old2new,
std::string_view attribute_name );

void import( const AttributeManager& attribute_manager,
const GenericMapping< index_t >& old2new_mapping );

void import( const AttributeManager& attribute_manager,
const GenericMapping< index_t >& old2new_mapping,
std::string_view attribute_name );

private:
friend class bitsery::Access;
template < typename Archive >
Expand Down
78 changes: 52 additions & 26 deletions src/geode/basic/attribute_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,9 @@ namespace geode
}
}

template < typename T >
void import( const AttributeManager::Impl &attribute_manager,
absl::Span< const index_t > old2new,
const T &old2new_mapping,
const AttributeBase::AttributeKey &key )
{
for( const auto &[attribute_name, attribute_from] :
Expand All @@ -270,43 +271,53 @@ namespace geode
continue;
}
this->attributes_.at( attribute_name )
->import( old2new, attribute_from, key );
->import( old2new_mapping, attribute_from, key );
}
else
{
attributes_.emplace( attribute_name,
attribute_from->extract( old2new, nb_elements_, key ) );
attribute_from->extract(
old2new_mapping, nb_elements_, key ) );
}
}
}

template < typename T >
void import( const AttributeManager::Impl &attribute_manager,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you reuse this code to import all attributes? I think there are code duplication here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sharing code for import all vs import one is not that simple, because of exception handling. But factorization is possible between the two import-all and import-one versions.

const GenericMapping< index_t > &old2new_mapping,
const T &old2new_mapping,
std::string_view attribute_name,
const AttributeBase::AttributeKey &key )
{
for( const auto &[attribute_name, attribute_from] :
attribute_manager.attributes_ )
auto it = attribute_manager.attributes_.find( attribute_name );
OpenGeodeBasicException::check_exception(
it != attribute_manager.attributes_.end(), nullptr,
OpenGeodeException::TYPE::data,
"[AttributeManager::import] Could not import attribute '",
attribute_name,
"'. No attribute with this name exists in the source "
"AttributeManager." );
OpenGeodeBasicException::check_exception(
it->second->properties().transferable, nullptr,
OpenGeodeException::TYPE::data,
"[AttributeManager::import] Could not import attribute '",
attribute_name, "'. The attribute is not transferable." );
if( attribute_exists( attribute_name ) )
{
if( !attribute_from->properties().transferable )
{
continue;
}
if( attribute_exists( attribute_name ) )
{
if( attribute_from->type()
!= this->attributes_.at( attribute_name )->type() )
{
continue;
}
this->attributes_.at( attribute_name )
->import( old2new_mapping, attribute_from, key );
}
else
{
attributes_.emplace( attribute_name,
attribute_from->extract(
old2new_mapping, nb_elements_, key ) );
}
OpenGeodeBasicException::check_exception(
it->second->type()
== this->attributes_.at( attribute_name )->type(),
nullptr, OpenGeodeException::TYPE::data,
"[AttributeManager::import] Could not import attribute '",
attribute_name,
"'. An attribute with the same name but a different type "
"already exists in the destination AttributeManager." );
this->attributes_.at( attribute_name )
->import( old2new_mapping, it->second, key );
}
else
{
attributes_.emplace( attribute_name,
it->second->extract( old2new_mapping, nb_elements_, key ) );
}
}

Expand Down Expand Up @@ -511,12 +522,27 @@ namespace geode
impl_->import( *attribute_manager.impl_, old2new, {} );
}

void AttributeManager::import( const AttributeManager &attribute_manager,
absl::Span< const index_t > old2new,
std::string_view attribute_name )
{
impl_->import( *attribute_manager.impl_, old2new, attribute_name, {} );
}

void AttributeManager::import( const AttributeManager &attribute_manager,
const GenericMapping< index_t > &old2new_mapping )
{
impl_->import( *attribute_manager.impl_, old2new_mapping, {} );
}

void AttributeManager::import( const AttributeManager &attribute_manager,
const GenericMapping< index_t > &old2new_mapping,
std::string_view attribute_name )
{
impl_->import(
*attribute_manager.impl_, old2new_mapping, attribute_name, {} );
}

void AttributeManager::rename_attribute(
std::string_view old_name, std::string_view new_name )
{
Expand Down
Loading