pub struct AttrStorageManager { /* private fields */ }
Expand description
Main attribute storage structure.
This structure is used to store all generic attributes that the user may add to the combinatorial map he’s building.
§Implementation
The structure uses hashmaps in order to store each attribute’s dedicated storage. Which storage
is used is determined by the associated type AttributeBind::StorageType
.
The key type used by the map is each attribute’s TypeId
. This implies that all attributes
must have a different (unique) type. For example, two decimal-valued attribute will need to be
wrapped in different dedicated structures.
Using the TypeId
as the key value for collections yields a cleaner API, where the only
argument passed to access methods is the ID of the cell of which they want the attribute. The
actual attribute type is specified by passing a generic to the method. This bypasses any issues
linked to literal-typed keys, such as typos, naming conventions, portability, etc.
Generics passed in access methods also have a secondary usage. To store heterogeneous
collections, the internal hashmaps uses Box<dyn UnknownAttributeStorage>
as their value type.
Some operations require us to downcast the stored object (implementing
UnknownAttributeStorage
) to the correct collection type. This is achieved by using the
downcast-rs
crate and the associated storage type AttributeBind::StorageType
. What
follows is a simplified version of that code:
pub struct Manager {
inner: HashMap<TypeId, Box<dyn UnknownAttributeStorage>>,
}
impl Manager {
pub fn add_storage<A: AttributeBind + 'static>(
&mut self,
size: usize,
) {
let typeid = TypeId::of::<A>();
let new_storage = <A as AttributeBind>::StorageType::new(size);
self.inner.insert(typeid, Box::new(new_storage));
}
pub fn get_storage<A: AttributeBind>(&self) -> &<A as AttributeBind>::StorageType {
let probably_storage = &self.inner[&TypeId::of::<A>()];
// downcast is possible because:
// - StorageType: AttributeStorage<A>
// - AttributeStorage<A>: UnknownAttributeStorage
probably_storage
.downcast_ref::<<A as AttributeBind>::StorageType>()
.expect("E: could not downcast generic storage to specified attribute type")
}
}
Implementations§
Source§impl AttrStorageManager
impl AttrStorageManager
Manager-wide methods
Sourcepub fn extend_storages(&mut self, length: usize)
pub fn extend_storages(&mut self, length: usize)
Extend the size of all storages in the manager.
§Arguments
length: usize
– Length by which storages should be extended.
Sourcepub fn merge_attributes(
&self,
orbit_policy: &OrbitPolicy,
id_out: DartIdType,
id_in_lhs: DartIdType,
id_in_rhs: DartIdType,
)
pub fn merge_attributes( &self, orbit_policy: &OrbitPolicy, id_out: DartIdType, id_in_lhs: DartIdType, id_in_rhs: DartIdType, )
Execute a merging operation on all attributes associated with a given orbit for specified cells.
§Arguments
orbit_policy: OrbitPolicy
– Orbit associated with affected attributes.id_out: DartIdentifier
– Identifier to write the result to.id_in_lhs: DartIdentifier
– Identifier of one attribute value to merge.id_in_rhs: DartIdentifier
– Identifier of the other attribute value to merge.
Sourcepub fn merge_vertex_attributes(
&self,
id_out: DartIdType,
id_in_lhs: DartIdType,
id_in_rhs: DartIdType,
)
pub fn merge_vertex_attributes( &self, id_out: DartIdType, id_in_lhs: DartIdType, id_in_rhs: DartIdType, )
Execute a merging operation on all attributes associated with vertices for specified cells.
§Arguments
id_out: DartIdentifier
– Identifier to write the result to.id_in_lhs: DartIdentifier
– Identifier of one attribute value to merge.id_in_rhs: DartIdentifier
– Identifier of the other attribute value to merge.
Sourcepub fn merge_edge_attributes(
&self,
id_out: DartIdType,
id_in_lhs: DartIdType,
id_in_rhs: DartIdType,
)
pub fn merge_edge_attributes( &self, id_out: DartIdType, id_in_lhs: DartIdType, id_in_rhs: DartIdType, )
Execute a merging operation on all attributes associated with edges for specified cells.
§Arguments
id_out: DartIdentifier
– Identifier to write the result to.id_in_lhs: DartIdentifier
– Identifier of one attribute value to merge.id_in_rhs: DartIdentifier
– Identifier of the other attribute value to merge.
Sourcepub fn merge_face_attributes(
&self,
id_out: DartIdType,
id_in_lhs: DartIdType,
id_in_rhs: DartIdType,
)
pub fn merge_face_attributes( &self, id_out: DartIdType, id_in_lhs: DartIdType, id_in_rhs: DartIdType, )
Execute a merging operation on all attributes associated with faces for specified cells.
§Arguments
id_out: DartIdentifier
– Identifier to write the result to.id_in_lhs: DartIdentifier
– Identifier of one attribute value to merge.id_in_rhs: DartIdentifier
– Identifier of the other attribute value to merge.
Sourcepub fn merge_other_attributes(
&self,
_orbit_policy: &OrbitPolicy,
_id_out: DartIdType,
_id_in_lhs: DartIdType,
_id_in_rhs: DartIdType,
)
pub fn merge_other_attributes( &self, _orbit_policy: &OrbitPolicy, _id_out: DartIdType, _id_in_lhs: DartIdType, _id_in_rhs: DartIdType, )
Execute a merging operation on all attributes associated with a given orbit for specified cells.
§Arguments
orbit_policy: OrbitPolicy
– Orbit associated with affected attributes.id_out: DartIdentifier
– Identifier to write the result to.id_in_lhs: DartIdentifier
– Identifier of one attribute value to merge.id_in_rhs: DartIdentifier
– Identifier of the other attribute value to merge.
Sourcepub fn split_attributes(
&self,
orbit_policy: &OrbitPolicy,
id_out_lhs: DartIdType,
id_out_rhs: DartIdType,
id_in: DartIdType,
)
pub fn split_attributes( &self, orbit_policy: &OrbitPolicy, id_out_lhs: DartIdType, id_out_rhs: DartIdType, id_in: DartIdType, )
Execute a splitting operation on all attributes associated with a given orbit for specified cells.
§Arguments
orbit_policy: OrbitPolicy
– Orbit associated with affected attributes.id_out_lhs: DartIdentifier
– Identifier to write the result to.id_out_rhs: DartIdentifier
– Identifier to write the result to.id_in: DartIdentifier
– Identifier of the attribute value to split.
Sourcepub fn split_vertex_attributes(
&self,
id_out_lhs: DartIdType,
id_out_rhs: DartIdType,
id_in: DartIdType,
)
pub fn split_vertex_attributes( &self, id_out_lhs: DartIdType, id_out_rhs: DartIdType, id_in: DartIdType, )
Execute a splitting operation on all attributes associated with vertices for specified cells.
§Arguments
orbit_policy: OrbitPolicy
– Orbit associated with affected attributes.id_out_lhs: DartIdentifier
– Identifier to write the result to.id_out_rhs: DartIdentifier
– Identifier to write the result to.id_in: DartIdentifier
– Identifier of the attribute value to split.
Sourcepub fn split_edge_attributes(
&self,
id_out_lhs: DartIdType,
id_out_rhs: DartIdType,
id_in: DartIdType,
)
pub fn split_edge_attributes( &self, id_out_lhs: DartIdType, id_out_rhs: DartIdType, id_in: DartIdType, )
Execute a splitting operation on all attributes associated with edges for specified cells.
§Arguments
orbit_policy: OrbitPolicy
– Orbit associated with affected attributes.id_out_lhs: DartIdentifier
– Identifier to write the result to.id_out_rhs: DartIdentifier
– Identifier to write the result to.id_in: DartIdentifier
– Identifier of the attribute value to split.
Sourcepub fn split_face_attributes(
&self,
id_out_lhs: DartIdType,
id_out_rhs: DartIdType,
id_in: DartIdType,
)
pub fn split_face_attributes( &self, id_out_lhs: DartIdType, id_out_rhs: DartIdType, id_in: DartIdType, )
Execute a splitting operation on all attributes associated with faces for specified cells.
§Arguments
orbit_policy: OrbitPolicy
– Orbit associated with affected attributes.id_out_lhs: DartIdentifier
– Identifier to write the result to.id_out_rhs: DartIdentifier
– Identifier to write the result to.id_in: DartIdentifier
– Identifier of the attribute value to split.
Sourcepub fn split_other_attributes(
&self,
_orbit_policy: &OrbitPolicy,
_id_out_lhs: DartIdType,
_id_out_rhs: DartIdType,
_id_in: DartIdType,
)
pub fn split_other_attributes( &self, _orbit_policy: &OrbitPolicy, _id_out_lhs: DartIdType, _id_out_rhs: DartIdType, _id_in: DartIdType, )
Execute a splitting operation on all attributes associated with a given orbit for specified cells.
§Arguments
orbit_policy: OrbitPolicy
– Orbit associated with affected attributes.id_out_lhs: DartIdentifier
– Identifier to write the result to.id_out_rhs: DartIdentifier
– Identifier to write the result to.id_in: DartIdentifier
– Identifier of the attribute value to split.
Source§impl AttrStorageManager
impl AttrStorageManager
Attribute-specific methods
Sourcepub fn add_storage<A: AttributeBind + 'static>(&mut self, size: usize)
pub fn add_storage<A: AttributeBind + 'static>(&mut self, size: usize)
Add a new storage to the manager.
For a breakdown of the principles used for implementation, refer to the Explanation
section of the AttrStorageManager
documentation entry.
§Arguments
size: usize
– Initial size of the new storage.
§Generic
A: AttributeBind + 'static
– Type of the attribute that will be stored.
§Panics
This function will panic if there is already a storage of attribute A
in the manager.
Sourcepub fn extend_storage<A: AttributeBind>(&mut self, length: usize)
pub fn extend_storage<A: AttributeBind>(&mut self, length: usize)
Sourcepub fn get_storage<A: AttributeBind>(
&self,
) -> Option<&<A as AttributeBind>::StorageType>
pub fn get_storage<A: AttributeBind>( &self, ) -> Option<&<A as AttributeBind>::StorageType>
Get a reference to the storage of a given attribute.
§Generic
A: AttributeBind
– Attribute stored by the fetched storage.
§Panics
This method may panic if:
- there’s no storage associated with the specified attribute
- downcasting
Box<dyn UnknownAttributeStorage>
to<A as AttributeBind>::StorageType
fails
Sourcepub fn remove_storage<A: AttributeBind>(&mut self)
pub fn remove_storage<A: AttributeBind>(&mut self)
Remove an entire attribute storage from the manager.
This method is useful when implementing routines that uses attributes to run; Those can then be removed before the final result is returned.
§Generic
A: AttributeBind
– Attribute stored by the fetched storage.
Sourcepub fn set_attribute<A: AttributeBind>(&self, id: A::IdentifierType, val: A)
pub fn set_attribute<A: AttributeBind>(&self, id: A::IdentifierType, val: A)
Set the value of an attribute.
§Arguments
id: A::IdentifierType
– Cell ID to which the attribute is associated.val: A
– New value of the attribute for the given ID.
§Generic
A: AttributeBind
– Type of the attribute being set.
§Panics
This method may panic if:
- there’s no storage associated with the specified attribute
- downcasting
Box<dyn UnknownAttributeStorage>
to<A as AttributeBind>::StorageType
fails - the index lands out of bounds
Sourcepub fn insert_attribute<A: AttributeBind>(&self, id: A::IdentifierType, val: A)
pub fn insert_attribute<A: AttributeBind>(&self, id: A::IdentifierType, val: A)
Set the value of an attribute.
§Arguments
id: A::IdentifierType
– Cell ID to which the attribute is associated.val: A
– New value of the attribute for the given ID.
§Generic
A: AttributeBind
– Type of the attribute being set.
§Panics
This method may panic if:
- there already is a value associated to the given ID for the specified attribute
- there’s no storage associated with the specified attribute
- downcasting
Box<dyn UnknownAttributeStorage>
to<A as AttributeBind>::StorageType
fails - the index lands out of bounds
Sourcepub fn get_attribute<A: AttributeBind>(
&self,
id: A::IdentifierType,
) -> Option<A>
pub fn get_attribute<A: AttributeBind>( &self, id: A::IdentifierType, ) -> Option<A>
Get the value of an attribute.
§Arguments
id: A::IdentifierType
– Cell ID to which the attribute is associated.
§Generic
A: AttributeBind
– Type of the attribute fetched.
§Return
The method may return:
Some(val: A)
if there is an attribute associated with the specified index,None
if there is not.
§Panics
This method may panic if:
- there’s no storage associated with the specified attribute
- downcasting
Box<dyn UnknownAttributeStorage>
to<A as AttributeBind>::StorageType
fails - the index lands out of bounds
Sourcepub fn replace_attribute<A: AttributeBind>(
&self,
id: A::IdentifierType,
val: A,
) -> Option<A>
pub fn replace_attribute<A: AttributeBind>( &self, id: A::IdentifierType, val: A, ) -> Option<A>
Set the value of an attribute.
§Arguments
id: A::IdentifierType
– ID of the cell to which the attribute is associated.val: A
– New value of the attribute for the given ID.
§Generic
A: AttributeBind
– Type of the attribute being set.
§Return
The method should return:
Some(val_old: A)
if there was an attribute associated with the specified index,None
if there was not.
§Panics
This method may panic if:
- there’s no storage associated with the specified attribute
- downcasting
Box<dyn UnknownAttributeStorage>
to<A as AttributeBind>::StorageType
fails - the index lands out of bounds
Sourcepub fn remove_attribute<A: AttributeBind>(
&self,
id: A::IdentifierType,
) -> Option<A>
pub fn remove_attribute<A: AttributeBind>( &self, id: A::IdentifierType, ) -> Option<A>
Remove the an item from an attribute storage.
§Arguments
id: A::IdentifierType
– Cell ID to which the attribute is associated.
§Generic
A: AttributeBind
– Type of the attribute fetched.
§Return
The method may return:
Some(val: A)
if was is an attribute associated with the specified index,None
if there was not.
§Panics
This method may panic if:
- there’s no storage associated with the specified attribute
- downcasting
Box<dyn UnknownAttributeStorage>
to<A as AttributeBind>::StorageType
fails - the index lands out of bounds
Sourcepub fn merge_attribute<A: AttributeBind>(
&self,
id_out: DartIdType,
id_in_lhs: DartIdType,
id_in_rhs: DartIdType,
)
pub fn merge_attribute<A: AttributeBind>( &self, id_out: DartIdType, id_in_lhs: DartIdType, id_in_rhs: DartIdType, )
Merge given attribute values.
§Arguments
id_out: DartIdentifier
– Identifier to write the result to.id_in_lhs: DartIdentifier
– Identifier of one attribute value to merge.id_in_rhs: DartIdentifier
– Identifier of the other attribute value to merge.
Sourcepub fn split_attribute<A: AttributeBind>(
&self,
id_out_lhs: DartIdType,
id_out_rhs: DartIdType,
id_in: DartIdType,
)
pub fn split_attribute<A: AttributeBind>( &self, id_out_lhs: DartIdType, id_out_rhs: DartIdType, id_in: DartIdType, )
Split given attribute value.
§Arguments
id_out_lhs: DartIdentifier
– Identifier to write the result to.id_out_rhs: DartIdentifier
– Identifier to write the result to.id_in: DartIdentifier
– Identifier of the attribute value to split.
Trait Implementations§
Source§impl Default for AttrStorageManager
impl Default for AttrStorageManager
Source§fn default() -> AttrStorageManager
fn default() -> AttrStorageManager
impl Send for AttrStorageManager
impl Sync for AttrStorageManager
Auto Trait Implementations§
impl Freeze for AttrStorageManager
impl !RefUnwindSafe for AttrStorageManager
impl Unpin for AttrStorageManager
impl !UnwindSafe for AttrStorageManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.