Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update manager methods #239

Closed
wants to merge 2 commits into from
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
37 changes: 13 additions & 24 deletions honeycomb-core/src/attributes/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use stm::{StmResult, Transaction};

use super::{AttributeBind, AttributeStorage, AttributeUpdate, UnknownAttributeStorage};
use crate::{
cmap::CMapResult,
cmap::{CMapError, CMapResult},
prelude::{DartIdType, OrbitPolicy},
};
use std::{any::TypeId, collections::HashMap};
Expand Down Expand Up @@ -162,7 +162,7 @@ impl AttrStorageManager {
/// # Panics
///
/// This function will panic if there is already a storage of attribute `A` in the manager.
pub fn add_storage<A: AttributeBind + 'static>(&mut self, size: usize) {
pub fn add_storage<A: AttributeBind + 'static>(&mut self, size: usize) -> CMapResult<()> {
let typeid = TypeId::of::<A>();
let new_storage = <A as AttributeBind>::StorageType::new(size);
if match A::BIND_POLICY {
Expand All @@ -177,12 +177,9 @@ impl AttrStorageManager {
}
.is_some()
{
eprintln!(
"W: Storage of attribute `{}` already exists in the attribute storage manager",
std::any::type_name::<A>()
);
eprintln!(" Continuing...");
return Err(CMapError::DuplicateAttribute(std::any::type_name::<A>()));
}
Ok(())
}

/// Extend the size of the storage of a given attribute.
Expand All @@ -194,15 +191,13 @@ impl AttrStorageManager {
/// ## Generic
///
/// - `A: AttributeBind` -- Attribute of which the storage should be extended.
pub fn extend_storage<A: AttributeBind>(&mut self, length: usize) {
pub fn extend_storage<A: AttributeBind>(&mut self, length: usize) -> CMapResult<()> {
get_storage_mut!(self, storage);
if let Some(st) = storage {
st.extend(length);
Ok(())
} else {
eprintln!(
"W: could not extend storage of attribute {} - storage not found",
std::any::type_name::<A>()
);
Err(CMapError::UnknownAttribute(std::any::type_name::<A>()))
}
}

Expand All @@ -218,14 +213,16 @@ impl AttrStorageManager {
/// - there's no storage associated with the specified attribute
/// - downcasting `Box<dyn UnknownAttributeStorage>` to `<A as AttributeBind>::StorageType` fails
#[must_use = "unused getter result - please remove this method call"]
pub fn get_storage<A: AttributeBind>(&self) -> Option<&<A as AttributeBind>::StorageType> {
pub fn get_storage<A: AttributeBind>(&self) -> CMapResult<&<A as AttributeBind>::StorageType> {
let probably_storage = match A::BIND_POLICY {
OrbitPolicy::Vertex | OrbitPolicy::VertexLinear => &self.vertices[&TypeId::of::<A>()],
OrbitPolicy::Edge => &self.edges[&TypeId::of::<A>()],
OrbitPolicy::Face | OrbitPolicy::FaceLinear => &self.faces[&TypeId::of::<A>()],
OrbitPolicy::Custom(_) => &self.others[&TypeId::of::<A>()],
};
probably_storage.downcast_ref::<<A as AttributeBind>::StorageType>()
probably_storage
.downcast_ref::<<A as AttributeBind>::StorageType>()
.ok_or(CMapError::UnknownAttribute(std::any::type_name::<A>()))
}

/// Remove an entire attribute storage from the manager.
Expand Down Expand Up @@ -627,11 +624,7 @@ impl AttrStorageManager {
if let Some(st) = storage {
st.try_merge(trans, id_out, id_in_lhs, id_in_rhs)
} else {
eprintln!(
"W: could not update storage of attribute {} - storage not found",
std::any::type_name::<A>()
);
Ok(())
Err(CMapError::UnknownAttribute(std::any::type_name::<A>()))
}
}
}
Expand Down Expand Up @@ -1018,11 +1011,7 @@ impl AttrStorageManager {
if let Some(st) = storage {
st.try_split(trans, id_out_lhs, id_out_rhs, id_in)
} else {
eprintln!(
"W: could not update storage of attribute {} - storage not found",
std::any::type_name::<A>()
);
Ok(())
Err(CMapError::UnknownAttribute(std::any::type_name::<A>()))
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions honeycomb-core/src/cmap/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ pub enum CMapError {
/// Geometry check failed.
#[error("operation incompatible with map geometry: {0}")]
IncorrectGeometry(&'static str),
/// Attribute already in the map storage.
#[error("duplicate attribute: {0}")]
DuplicateAttribute(&'static str),
/// Accessed attribute isn't in the map storage.
#[error("unknown attribute: {0}")]
UnknownAttribute(&'static str),
Expand Down
Loading