aboutsummaryrefslogtreecommitdiff
path: root/src/context.rs
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2024-01-18 18:29:10 +0100
committerNathan Reiner <nathan@nathanreiner.xyz>2024-01-18 18:29:10 +0100
commit1713618d4cc0194674f91fd2d24ef2de88f21784 (patch)
tree1cb39a43019c071ca127cb9f609c045327798de3 /src/context.rs
parent670c1881af4680ce7c248498528d14b98210af3f (diff)
create small iced demo
Diffstat (limited to 'src/context.rs')
-rw-r--r--src/context.rs66
1 files changed, 0 insertions, 66 deletions
diff --git a/src/context.rs b/src/context.rs
deleted file mode 100644
index 409600f..0000000
--- a/src/context.rs
+++ /dev/null
@@ -1,66 +0,0 @@
-use crate::complex::Complex;
-use crate::function::Function;
-use crate::operation::Operation;
-use std::sync::Arc;
-use std::collections::HashMap;
-
-#[derive(Default, Clone)]
-pub struct Context {
- ops: Vec<Operation>,
- vars: HashMap<String, Complex>,
- funcs: HashMap<String, Arc<dyn Function>>,
-}
-
-impl Context {
- pub fn new() -> Self {
- Self::default()
- }
-
- pub fn with_operations(mut self, ops: Vec<Operation>) -> Self {
- self.ops = ops;
- self
- }
-
- pub fn with_variables(mut self, vars: HashMap<String, Complex>) -> Self {
- self.vars = vars;
- self
- }
-
- pub fn with_functions(mut self, funcs: HashMap<String, Arc<dyn Function>>) -> Self {
- self.funcs = funcs;
- self
- }
-
- pub fn operations(&self) -> &Vec<Operation> {
- &self.ops
- }
-
- pub fn set_variable(&mut self, name: &str, value: Complex) {
- self.vars.insert(name.to_string(), value);
- }
-
- pub fn set_function(&mut self, name: &str, func: Arc<dyn Function>) {
- self.funcs.insert(name.to_string(), func);
- }
-
- pub fn variable(&self, name: &str) -> Option<&Complex> {
- self.vars.get(name)
- }
-
- pub fn function(&self, name: &str) -> Option<&Arc<dyn Function>> {
- self.funcs.get(name)
- }
-}
-
-#[macro_export]
-macro_rules! variables {
- {$($x:expr => $y:expr), *} => {
- {
- let mut h : HashMap<String, Complex> = HashMap::new();
- $(
- h.insert($x.to_string(), $y);
- )*
- h
- }
- };
-}