-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStringObserver.cs~
More file actions
72 lines (63 loc) · 1.5 KB
/
StringObserver.cs~
File metadata and controls
72 lines (63 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
using System;
using MathParser.DataTypes;
using System.Collections.Generic;
namespace MathParser
{
/// <summary>
/// The entry point of the data.
/// Stores all the history and send the string for further processing to different.
/// Processing classes.
/// </summary>
public class StringObserver : ISolver
{
string givenString;
bool Processed = true;
public StringObserver() { }
MathParserExpression Solution;
public MathParserExpression getSolution() => Solution;
public bool isProcessed() => Processed;
Dictionary<string, MathParserExpression> History;
Dictionary<string, MathParserExpression> theExpressionListHistory = new Dictionary<string, MathParserExpression>();
public StringObserver(string String_To_Interpret, Dictionary<string, MathParserExpression> History)
{
this.History = History;
givenString = String_To_Interpret.Trim();
Interpret();
if (Processed)
{
theExpressionListHistory.Add(givenString, Solution);
}
}
private void Interpret()
{
if (!givenString.Contains("="))
{
NonEquation solve = new NonEquation(givenString);
solve.History = History;
solve.Solve();
if (solve.isProcessed())
{
Solution = solve.getSolution();
}
else
{
Processed = false;
}
}
else
{
Equation sol = new Equation(givenString);
sol.theHistory = History;
sol.Solve();
if (sol.isProcessed())
{
Solution = sol.getSolution();
}
else
{
Processed = false;
}
}
}
}
}