use std::collections::BTreeMap;
use sim_kernel::{Error, Result, Symbol};
use crate::LanguageProfile;
#[derive(Clone, Debug, Default)]
pub struct ProfileRegistry {
profiles: BTreeMap<Symbol, LanguageProfile>,
}
impl ProfileRegistry {
pub fn new() -> Self {
Self::default()
}
pub fn register_profile(&mut self, profile: LanguageProfile) -> Result<()> {
let symbol = profile.symbol.clone();
if self.profiles.contains_key(&symbol) {
return Err(Error::DuplicateExport {
kind: "standard-profile",
symbol,
});
}
self.profiles.insert(symbol, profile);
Ok(())
}
pub fn profile(&self, symbol: &Symbol) -> Option<&LanguageProfile> {
self.profiles.get(symbol)
}
pub fn profiles(&self) -> impl Iterator<Item = &LanguageProfile> {
self.profiles.values()
}
pub fn len(&self) -> usize {
self.profiles.len()
}
pub fn is_empty(&self) -> bool {
self.profiles.is_empty()
}
}