mod compositequote;
mod deltavolquote;
mod derivedquote;
mod multicompositequote;
mod simplequote;
pub use compositequote::CompositeQuote;
pub use deltavolquote::{AtmType, DeltaType, DeltaVolQuote};
pub use derivedquote::DerivedQuote;
pub use multicompositequote::MultiCompositeQuote;
pub use simplequote::{SimpleQuote, make_quote_handle};
use std::cell::Cell;
use crate::errors::QlResult;
use crate::patterns::observable::{AsObservable, Observable, Observer};
use crate::shared::{Shared, SharedMut, shared, shared_mut};
use crate::types::Real;
pub trait Quote: AsObservable {
fn value(&self) -> QlResult<Real>;
fn is_valid(&self) -> bool;
}
struct Invalidator {
cache: Shared<Cell<Option<Real>>>,
observable: Shared<Observable>,
}
impl Invalidator {
fn new() -> (
Shared<Cell<Option<Real>>>,
Shared<Observable>,
SharedMut<Invalidator>,
) {
let cache = shared(Cell::new(None));
let observable = shared(Observable::new());
let listener = shared_mut(Invalidator {
cache: Shared::clone(&cache),
observable: Shared::clone(&observable),
});
(cache, observable, listener)
}
}
impl Observer for Invalidator {
fn update(&mut self) {
self.cache.set(None);
self.observable.notify_observers();
}
}