use std::collections::{BTreeMap, BTreeSet};
#[derive(Default)]
pub(crate) struct SessionParameterRegistry {
placeholders: BTreeMap<String, String>,
libraries: BTreeSet<&'static str>,
client_settings: BTreeMap<String, String>,
}
impl SessionParameterRegistry {
pub(crate) fn placeholder(&self, name: &str) -> Option<&str> {
self.placeholders
.get(&name.to_ascii_lowercase())
.map(String::as_str)
}
pub(crate) fn add_placeholder(&mut self, name: &str) {
self.placeholders
.entry(name.to_ascii_lowercase())
.or_insert_with(|| name.to_string());
}
pub(crate) fn remove_placeholder(&mut self, name: &str) {
self.placeholders.remove(&name.to_ascii_lowercase());
}
pub(crate) fn placeholders_with_prefix(&self, prefix: &str) -> Vec<String> {
self.placeholders
.values()
.filter(|name| {
name.split_once('.')
.is_some_and(|(component, _)| component == prefix)
})
.cloned()
.collect()
}
pub(crate) fn library_loaded(&self, library: &str) -> bool {
self.libraries.contains(library)
}
pub(crate) fn load_library(&mut self, library: &'static str) -> bool {
self.libraries.insert(library)
}
pub(crate) fn reserved_prefixes(&self) -> impl Iterator<Item = &str> + '_ {
self.libraries.iter().copied()
}
pub(crate) fn client_setting(&self, name: &str) -> Option<&str> {
self.client_settings
.get(&name.to_ascii_lowercase())
.map(String::as_str)
}
pub(crate) fn set_client_setting(&mut self, name: &str, setting: String) {
self.client_settings
.insert(name.to_ascii_lowercase(), setting);
}
}