Newer
Older
use serde_derive::{Deserialize, Serialize};

Udo Eisenbarth
committed
use std::collections::HashMap;
use crate::{error::OpossumError, lightdata::LightData, optical::OpticGraph, nodes::FilterType};
#[derive(Default, Serialize, Deserialize, Debug, Clone)]
pub props: HashMap<String, Property>,
pub fn set(&mut self, name: &str, value: Property) -> Option<()> {
if self.props.insert(name.into(), value).is_some() {
Some(())
} else {
None
}
pub fn get(&self, name: &str) -> Option<&Property> {
self.props.get(name)
}
pub fn get_bool(&self, name: &str) -> Result<Option<bool>, OpossumError> {
if let Some(property) = self.props.get(name) {
if let Proptype::Bool(value) = property.prop {
Ok(Some(value))
} else {
Err(OpossumError::Other("not a bool property".into()))
}
} else {
Ok(None)
}

Udo Eisenbarth
committed
#[derive(Debug, Serialize, Deserialize, Clone)]

Udo Eisenbarth
committed
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
impl From<bool> for Property {
fn from(value: bool) -> Self {
Property {
prop: Proptype::Bool(value),
}
}
}
impl From<f64> for Property {
fn from(value: f64) -> Self {
Property {
prop: Proptype::F64(value),
}
}
}
impl From<String> for Property {
fn from(value: String) -> Self {
Property {
prop: Proptype::String(value),
}
}
}
impl From<&str> for Property {
fn from(value: &str) -> Self {
Property {
prop: Proptype::String(value.to_string()),
}
}
}
impl From<i32> for Property {
fn from(value: i32) -> Self {
Property {
prop: Proptype::I32(value),
}
}
}
impl From<FilterType> for Property {
fn from(value: FilterType) -> Self {
Property {
prop: Proptype::FilterType(value),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
String(String),
I32(i32),
F64(f64),
Bool(bool),
LightData(Option<LightData>),
OpticGraph(OpticGraph),