pub struct PropertyManager {
dyn_properties: HashMap<DynPropertyId, DynProperty>,
stat_properties: HashMap<StatPropertyId, StatProperty>,
}
Expand description
Class to manage all properties of the sketch.
PropertyManager
can be managed through its classical Rust API, as well as
through the external events (as it implements the SessionState
trait).
Fields§
§dyn_properties: HashMap<DynPropertyId, DynProperty>
§stat_properties: HashMap<StatPropertyId, StatProperty>
Implementations§
source§impl PropertyManager
impl PropertyManager
Methods for safely generating new valid (unique) instances of identifiers for
the current PropertyManager
.
sourcepub fn generate_dyn_property_id(
&self,
ideal_id: &str,
start_index: Option<usize>,
) -> DynPropertyId
pub fn generate_dyn_property_id( &self, ideal_id: &str, start_index: Option<usize>, ) -> DynPropertyId
Generate valid DynPropertyId
that’s currently not used by any dynamic property in this
PropertyManager
.
First, the given ideal_id
or its transformation by replacing invalid characters are tried.
If they are both invalid (non-unique), a numerical identifier is added at the end.
By specifying start_index
, the index search starts directly at that number (e.g., when
ideal ID is “prop” and start index is 3, search for ID starts with “prop_3”, “prop_4”, …)
Warning: Do not use this to pre-generate more than one id at a time, as the process is deterministic and might generate the same IDs. Always generate an Id, add that property, and then repeat for other properties.
sourcepub fn generate_stat_property_id(
&self,
ideal_id: &str,
start_index: Option<usize>,
) -> StatPropertyId
pub fn generate_stat_property_id( &self, ideal_id: &str, start_index: Option<usize>, ) -> StatPropertyId
Generate valid StatPropertyId
that’s currently not used by any static property in this
PropertyManager
.
First, the given ideal_id
or its transformation by replacing invalid characters are tried.
If they are both invalid (non-unique), a numerical identifier is added at the end.
By specifying start_index
, the index search starts directly at that number (e.g., when
ideal ID is “prop” and start index is 3, search for ID starts with “prop_3”, “prop_4”, …)
Warning: Do not use this to pre-generate more than one id at a time, as the process is deterministic and might generate the same IDs. Always generate an Id, add that property, and then repeat for other properties.
source§impl PropertyManager
impl PropertyManager
Creating new instances of PropertyManager
.
sourcepub fn new_empty() -> PropertyManager
pub fn new_empty() -> PropertyManager
Instantiate PropertyManager
with empty sets of properties.
sourcepub fn new_from_properties(
dyn_properties: Vec<(&str, DynProperty)>,
stat_properties: Vec<(&str, StatProperty)>,
) -> Result<PropertyManager, String>
pub fn new_from_properties( dyn_properties: Vec<(&str, DynProperty)>, stat_properties: Vec<(&str, StatProperty)>, ) -> Result<PropertyManager, String>
Instantiate PropertyManager
with dynamic and static properties given as a list
of ID-property pairs.
source§impl PropertyManager
impl PropertyManager
Editing PropertyManager
.
sourcepub fn add_dynamic(
&mut self,
id: DynPropertyId,
prop: DynProperty,
) -> Result<(), String>
pub fn add_dynamic( &mut self, id: DynPropertyId, prop: DynProperty, ) -> Result<(), String>
Add pre-generated dynamic property.
sourcepub fn add_dynamic_by_str(
&mut self,
id: &str,
prop: DynProperty,
) -> Result<(), String>
pub fn add_dynamic_by_str( &mut self, id: &str, prop: DynProperty, ) -> Result<(), String>
Add pre-generated dynamic property with id given by str.
sourcepub fn add_static(
&mut self,
id: StatPropertyId,
prop: StatProperty,
) -> Result<(), String>
pub fn add_static( &mut self, id: StatPropertyId, prop: StatProperty, ) -> Result<(), String>
Add pre-generated static property.
sourcepub fn add_static_by_str(
&mut self,
id: &str,
prop: StatProperty,
) -> Result<(), String>
pub fn add_static_by_str( &mut self, id: &str, prop: StatProperty, ) -> Result<(), String>
Add pre-generated static property with id given by str.
sourcepub fn set_dyn_name(
&mut self,
id: &DynPropertyId,
new_name: &str,
) -> Result<(), String>
pub fn set_dyn_name( &mut self, id: &DynPropertyId, new_name: &str, ) -> Result<(), String>
Set name for given dynamic property.
sourcepub fn set_stat_name(
&mut self,
id: &StatPropertyId,
new_name: &str,
) -> Result<(), String>
pub fn set_stat_name( &mut self, id: &StatPropertyId, new_name: &str, ) -> Result<(), String>
Set name for given static property.
sourcepub fn set_dyn_dataset(
&mut self,
id: &DynPropertyId,
new_dataset: DatasetId,
) -> Result<(), String>
pub fn set_dyn_dataset( &mut self, id: &DynPropertyId, new_dataset: DatasetId, ) -> Result<(), String>
Update dynamic property’s sub-field dataset
where applicable.
If not applicable, return Err
.
sourcepub fn set_dyn_observation(
&mut self,
id: &DynPropertyId,
new_obs: ObservationId,
) -> Result<(), String>
pub fn set_dyn_observation( &mut self, id: &DynPropertyId, new_obs: ObservationId, ) -> Result<(), String>
Update dynamic property’s sub-field observation
where applicable.
If not applicable, return Err
.
sourcepub fn set_dyn_formula(
&mut self,
id: &DynPropertyId,
new_formula: &str,
) -> Result<(), String>
pub fn set_dyn_formula( &mut self, id: &DynPropertyId, new_formula: &str, ) -> Result<(), String>
Update generic dynamic property’s formula.
If not applicable (different variant), return Err
.
sourcepub fn set_dyn_none_observation(
&mut self,
id: &DynPropertyId,
) -> Result<(), String>
pub fn set_dyn_none_observation( &mut self, id: &DynPropertyId, ) -> Result<(), String>
Update dynamic property’s sub-field observation
to None where applicable.
If not applicable, return Err
.
sourcepub fn set_dyn_attr_count(
&mut self,
id: &DynPropertyId,
minimal: usize,
maximal: usize,
) -> Result<(), String>
pub fn set_dyn_attr_count( &mut self, id: &DynPropertyId, minimal: usize, maximal: usize, ) -> Result<(), String>
Update dynamic property’s sub-fields, if the property is of AttractorCount
variant.
If not applicable, return Err
.
sourcepub fn set_dyn_trap_space_details(
&mut self,
id: &DynPropertyId,
is_minimal: bool,
non_percolable: bool,
) -> Result<(), String>
pub fn set_dyn_trap_space_details( &mut self, id: &DynPropertyId, is_minimal: bool, non_percolable: bool, ) -> Result<(), String>
Update dynamic property’s sub-fields, if the property is of ExistsTrapSpace
variant.
If not applicable, return Err
.
sourcepub fn set_stat_formula(
&mut self,
id: &StatPropertyId,
new_formula: &str,
) -> Result<(), String>
pub fn set_stat_formula( &mut self, id: &StatPropertyId, new_formula: &str, ) -> Result<(), String>
Update generic static property’s formula.
If not applicable (different variant), return Err
.
sourcepub fn set_stat_input_var(
&mut self,
id: &StatPropertyId,
new_var: VarId,
) -> Result<(), String>
pub fn set_stat_input_var( &mut self, id: &StatPropertyId, new_var: VarId, ) -> Result<(), String>
Update static property’s sub-field for input variable (of an update fn), where applicable.
If not applicable, return Err
.
sourcepub fn set_stat_input_index(
&mut self,
id: &StatPropertyId,
new_idx: usize,
) -> Result<(), String>
pub fn set_stat_input_index( &mut self, id: &StatPropertyId, new_idx: usize, ) -> Result<(), String>
Update static property’s sub-field for index of input (of an uninterpreted fn),
where applicable. If not applicable, return Err
.
sourcepub fn set_stat_target_fn(
&mut self,
id: &StatPropertyId,
new_target: UninterpretedFnId,
) -> Result<(), String>
pub fn set_stat_target_fn( &mut self, id: &StatPropertyId, new_target: UninterpretedFnId, ) -> Result<(), String>
Update static property’s sub-field for target uninterpreted fn, where applicable.
If not applicable, return Err
.
sourcepub fn set_stat_target_var(
&mut self,
id: &StatPropertyId,
new_target: VarId,
) -> Result<(), String>
pub fn set_stat_target_var( &mut self, id: &StatPropertyId, new_target: VarId, ) -> Result<(), String>
Update static property’s sub-field for target variable, where applicable.
If not applicable, return Err
.
sourcepub fn set_stat_monotonicity(
&mut self,
id: &StatPropertyId,
monotonicity: Monotonicity,
) -> Result<(), String>
pub fn set_stat_monotonicity( &mut self, id: &StatPropertyId, monotonicity: Monotonicity, ) -> Result<(), String>
Update static property’s sub-field for monotonicity, where applicable.
If not applicable, return Err
.
sourcepub fn set_stat_essentiality(
&mut self,
id: &StatPropertyId,
essentiality: Essentiality,
) -> Result<(), String>
pub fn set_stat_essentiality( &mut self, id: &StatPropertyId, essentiality: Essentiality, ) -> Result<(), String>
Update static property’s sub-field for essentiality, where applicable.
If not applicable, return Err
.
sourcepub fn set_stat_context(
&mut self,
id: &StatPropertyId,
context: String,
) -> Result<(), String>
pub fn set_stat_context( &mut self, id: &StatPropertyId, context: String, ) -> Result<(), String>
Update static property’s sub-field for context, where applicable.
If not applicable, return Err
.
sourcepub fn swap_dyn_content(
&mut self,
id: &DynPropertyId,
new_content: DynProperty,
) -> Result<(), String>
pub fn swap_dyn_content( &mut self, id: &DynPropertyId, new_content: DynProperty, ) -> Result<(), String>
Swap content of a dynamic property with given id
. The ID must be valid identifier.
The variant of the prop. must stay the same (i.e., we only change attributes, not variant).
sourcepub fn swap_dyn_content_by_str(
&mut self,
id: &str,
new_content: DynProperty,
) -> Result<(), String>
pub fn swap_dyn_content_by_str( &mut self, id: &str, new_content: DynProperty, ) -> Result<(), String>
Swap content of a dynamic property with given id
. The ID must be valid identifier.
The variant of the prop. must stay the same (i.e., we only change attributes, not variant).
sourcepub fn swap_stat_content(
&mut self,
id: &StatPropertyId,
new_content: StatProperty,
) -> Result<(), String>
pub fn swap_stat_content( &mut self, id: &StatPropertyId, new_content: StatProperty, ) -> Result<(), String>
Swap content of a static property with given id
. The ID must be valid identifier.
The variant of the prop. must stay the same (i.e., we only change attributes, not variant).
sourcepub fn swap_stat_content_by_str(
&mut self,
id: &str,
new_content: StatProperty,
) -> Result<(), String>
pub fn swap_stat_content_by_str( &mut self, id: &str, new_content: StatProperty, ) -> Result<(), String>
Swap content of a static property with given id
. The ID must be valid identifier.
The variant of the prop. must stay the same (i.e., we only change attributes, not variant).
sourcepub fn set_dyn_id(
&mut self,
original_id: &DynPropertyId,
new_id: DynPropertyId,
) -> Result<(), String>
pub fn set_dyn_id( &mut self, original_id: &DynPropertyId, new_id: DynPropertyId, ) -> Result<(), String>
Change ID of a dynamic property.
sourcepub fn set_dyn_id_by_str(
&mut self,
original_id: &str,
new_id: &str,
) -> Result<(), String>
pub fn set_dyn_id_by_str( &mut self, original_id: &str, new_id: &str, ) -> Result<(), String>
Change ID of a dynamic property, with IDs given as string slices.
sourcepub fn set_stat_id(
&mut self,
original_id: &StatPropertyId,
new_id: StatPropertyId,
) -> Result<(), String>
pub fn set_stat_id( &mut self, original_id: &StatPropertyId, new_id: StatPropertyId, ) -> Result<(), String>
Change ID of a static property.
sourcepub fn set_stat_id_by_str(
&mut self,
original_id: &str,
new_id: &str,
) -> Result<(), String>
pub fn set_stat_id_by_str( &mut self, original_id: &str, new_id: &str, ) -> Result<(), String>
Change ID of a static property, with IDs given as string slices.
sourcepub fn remove_dynamic(&mut self, id: &DynPropertyId) -> Result<(), String>
pub fn remove_dynamic(&mut self, id: &DynPropertyId) -> Result<(), String>
Remove dynamic property.
sourcepub fn remove_static(&mut self, id: &StatPropertyId) -> Result<(), String>
pub fn remove_static(&mut self, id: &StatPropertyId) -> Result<(), String>
Remove static property.
sourcepub fn make_generated_reg_prop_ids_consistent(&mut self)
pub fn make_generated_reg_prop_ids_consistent(&mut self)
Go through all static properties that are automatically generated from the regulation graph and make their IDs consistent with the variables they reference.
This is useful after we change the variable’s ID, e.g., to ensure that monotonicity
properties still have IDs like monotonicity_REGULATOR_TARGET
.
source§impl PropertyManager
impl PropertyManager
Internal assertion utilities.
sourcefn assert_no_dynamic(&self, id: &DynPropertyId) -> Result<(), String>
fn assert_no_dynamic(&self, id: &DynPropertyId) -> Result<(), String>
(internal) Utility method to ensure there is no dynamic property with given ID yet.
sourcefn assert_valid_dynamic(&self, id: &DynPropertyId) -> Result<(), String>
fn assert_valid_dynamic(&self, id: &DynPropertyId) -> Result<(), String>
(internal) Utility method to ensure there is a dynamic property with given ID.
sourcefn assert_no_static(&self, id: &StatPropertyId) -> Result<(), String>
fn assert_no_static(&self, id: &StatPropertyId) -> Result<(), String>
(internal) Utility method to ensure there is no static property with given ID yet.
sourcefn assert_valid_static(&self, id: &StatPropertyId) -> Result<(), String>
fn assert_valid_static(&self, id: &StatPropertyId) -> Result<(), String>
(internal) Utility method to ensure there is a static property with given ID.
source§impl PropertyManager
impl PropertyManager
Observing the PropertyManager
.
sourcepub fn num_dyn_properties(&self) -> usize
pub fn num_dyn_properties(&self) -> usize
The number of dynamic properties in this PropertyManager
.
sourcepub fn num_stat_properties(&self) -> usize
pub fn num_stat_properties(&self) -> usize
The number of static properties in this PropertyManager
.
sourcepub fn is_valid_dyn_property_id(&self, id: &DynPropertyId) -> bool
pub fn is_valid_dyn_property_id(&self, id: &DynPropertyId) -> bool
Check if there is a dynamic property with given Id.
sourcepub fn is_valid_stat_property_id(&self, id: &StatPropertyId) -> bool
pub fn is_valid_stat_property_id(&self, id: &StatPropertyId) -> bool
Check if there is a static property with given Id.
sourcepub fn dyn_props(&self) -> DynPropIterator<'_>
pub fn dyn_props(&self) -> DynPropIterator<'_>
Return an iterator over all dynamic properties of this model.
sourcepub fn stat_props(&self) -> StatPropIterator<'_>
pub fn stat_props(&self) -> StatPropIterator<'_>
Return an iterator over all dynamic properties of this model.
sourcepub fn get_dyn_prop_id(&self, id: &str) -> Result<DynPropertyId, String>
pub fn get_dyn_prop_id(&self, id: &str) -> Result<DynPropertyId, String>
Return a valid dynamic property’s DynPropertyId
corresponding to the given str id
.
Return Err
if such property does not exist (and the ID is invalid).
sourcepub fn get_dyn_prop(&self, id: &DynPropertyId) -> Result<&DynProperty, String>
pub fn get_dyn_prop(&self, id: &DynPropertyId) -> Result<&DynProperty, String>
Return a DynProperty
corresponding to a given DynPropertyId
.
Return Err
if such dynamic property does not exist (the ID is invalid in this context).
sourcepub fn get_stat_prop_id(&self, id: &str) -> Result<StatPropertyId, String>
pub fn get_stat_prop_id(&self, id: &str) -> Result<StatPropertyId, String>
Return a valid static property’s StatPropertyId
corresponding to the given str id
.
Return Err
if such property does not exist (and the ID is invalid).
sourcepub fn get_stat_prop(
&self,
id: &StatPropertyId,
) -> Result<&StatProperty, String>
pub fn get_stat_prop( &self, id: &StatPropertyId, ) -> Result<&StatProperty, String>
Return a StatProperty
corresponding to a given StatPropertyId
.
Return Err
if such static property does not exist (the ID is invalid in this context).
source§impl PropertyManager
impl PropertyManager
Implementation for events related to modifying dynamic
properties.
sourcepub(super) fn event_add_dynamic(
&mut self,
event: &Event,
) -> Result<Consumed, DynError>
pub(super) fn event_add_dynamic( &mut self, event: &Event, ) -> Result<Consumed, DynError>
Perform event of adding a new dynamic property
to this PropertyManager
.
sourcepub(super) fn event_add_default_dynamic(
&mut self,
event: &Event,
) -> Result<Consumed, DynError>
pub(super) fn event_add_default_dynamic( &mut self, event: &Event, ) -> Result<Consumed, DynError>
Perform event of adding a new DEFAULT dynamic property
of given variant
to this PropertyManager
.
sourcepub(super) fn event_modify_dynamic(
&mut self,
event: &Event,
at_path: &[&str],
prop_id: DynPropertyId,
) -> Result<Consumed, DynError>
pub(super) fn event_modify_dynamic( &mut self, event: &Event, at_path: &[&str], prop_id: DynPropertyId, ) -> Result<Consumed, DynError>
Perform event of modifying or removing existing dynamic property
of this
PropertyManager
.
source§impl PropertyManager
impl PropertyManager
Implementation for events related to modifying static
properties.
sourcepub(super) fn event_add_static(
&mut self,
event: &Event,
) -> Result<Consumed, DynError>
pub(super) fn event_add_static( &mut self, event: &Event, ) -> Result<Consumed, DynError>
Perform event of adding a new static property
to this PropertyManager
.
sourcepub(super) fn event_add_default_static(
&mut self,
event: &Event,
) -> Result<Consumed, DynError>
pub(super) fn event_add_default_static( &mut self, event: &Event, ) -> Result<Consumed, DynError>
Perform event of adding a new DEFAULT static property
of given variant
to this PropertyManager
.
sourcepub(super) fn event_modify_static(
&mut self,
event: &Event,
at_path: &[&str],
prop_id: StatPropertyId,
) -> Result<Consumed, DynError>
pub(super) fn event_modify_static( &mut self, event: &Event, at_path: &[&str], prop_id: StatPropertyId, ) -> Result<Consumed, DynError>
Perform event of modifying or removing existing static property
of this
PropertyManager
.
Trait Implementations§
source§impl Clone for PropertyManager
impl Clone for PropertyManager
source§fn clone(&self) -> PropertyManager
fn clone(&self) -> PropertyManager
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for PropertyManager
impl Debug for PropertyManager
source§impl Default for PropertyManager
impl Default for PropertyManager
source§fn default() -> PropertyManager
fn default() -> PropertyManager
Default manager instance with no datasets.
source§impl Manager for PropertyManager
impl Manager for PropertyManager
source§fn generate_id<T>(
&self,
ideal_id: &str,
is_taken: &dyn Fn(&Self, &T) -> bool,
num_indices: usize,
start_index: Option<usize>,
) -> T
fn generate_id<T>( &self, ideal_id: &str, is_taken: &dyn Fn(&Self, &T) -> bool, num_indices: usize, start_index: Option<usize>, ) -> T
T
for a certain component of a manager (e.g., generate a
VariableId
for a Variable
in a ModelState
). Read moresource§fn assert_ids_unique_and_used<T>(
&self,
id_list: &Vec<&str>,
assert_id_is_managed: &dyn Fn(&Self, &T) -> Result<(), String>,
) -> Result<(), String>
fn assert_ids_unique_and_used<T>( &self, id_list: &Vec<&str>, assert_id_is_managed: &dyn Fn(&Self, &T) -> Result<(), String>, ) -> Result<(), String>
source§fn assert_ids_unique_and_new<T>(
&self,
id_list: &Vec<&str>,
assert_id_is_new: &dyn Fn(&Self, &T) -> Result<(), String>,
) -> Result<(), String>
fn assert_ids_unique_and_new<T>( &self, id_list: &Vec<&str>, assert_id_is_new: &dyn Fn(&Self, &T) -> Result<(), String>, ) -> Result<(), String>
source§impl PartialEq for PropertyManager
impl PartialEq for PropertyManager
source§impl SessionHelper for PropertyManager
impl SessionHelper for PropertyManager
source§fn starts_with<'a, 'b>(
prefix: &str,
at_path: &'a [&'b str],
) -> Option<&'a [&'b str]>
fn starts_with<'a, 'b>( prefix: &str, at_path: &'a [&'b str], ) -> Option<&'a [&'b str]>
at_path
starts with a specific first segment.
If yes, returns the remaining part of the path.source§fn matches(expected: &[&str], at_path: &[&str]) -> bool
fn matches(expected: &[&str], at_path: &[&str]) -> bool
at_path
is exactlysource§fn invalid_path_error_generic<T>(at_path: &[&str]) -> Result<T, DynError>
fn invalid_path_error_generic<T>(at_path: &[&str]) -> Result<T, DynError>
source§fn invalid_path_error_specific<T>(
path: &[&str],
component: &str,
) -> Result<T, DynError>
fn invalid_path_error_specific<T>( path: &[&str], component: &str, ) -> Result<T, DynError>
component
.source§fn clone_payload_str(event: &Event, component: &str) -> Result<String, DynError>
fn clone_payload_str(event: &Event, component: &str) -> Result<String, DynError>
source§impl SessionState for PropertyManager
impl SessionState for PropertyManager
impl StructuralPartialEq for PropertyManager
Auto Trait Implementations§
impl Freeze for PropertyManager
impl RefUnwindSafe for PropertyManager
impl Send for PropertyManager
impl Sync for PropertyManager
impl Unpin for PropertyManager
impl UnwindSafe for PropertyManager
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)