#include #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // Set up two different uCalc contexts with the same variable name 'x'. uCalc::DefaultInstance().DefineVariable("x = 1.2"); uc.DefineVariable("x = 10"); cout << "--- Testing Expression Contexts ---" << endl; // 1. Expression created in the *default* context uses x = 1.2 { uCalc::Expression exprDefault("x + 5"); exprDefault.Owned(); // Causes exprDefault to be released when it goes out of scope cout << "Default context (x=1.2): " << exprDefault.Evaluate() << endl; // 2. Expression created in a *specific* context ('uc') uses x = 10 { uCalc::Expression exprSpecific(uc, "x + 5"); exprSpecific.Owned(); // Causes exprSpecific to be released when it goes out of scope cout << "Specific context (x=10): " << exprSpecific.Evaluate() << endl; // 3. Create empty, then parse later (uses default context for the Parse call) { uCalc::Expression exprEmpty; exprEmpty.Owned(); // Causes exprEmpty to be released when it goes out of scope exprEmpty.Parse("x * 10"); cout << "Empty then parsed (x=1.2):" << exprEmpty.Evaluate() << endl; } } } }