#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   // --- Main Application Context ---
   // The implicit 'uc' object is the initial default.
   uCalc::DefaultInstance().DefineConstant("PI = 3.14159");
   cout << "Initial Count: " << uCalc::DefaultCount() << endl;

   // --- A Plugin needs a temporary, isolated context ---
   {
      uCalc moduleCalc;
      moduleCalc.Owned(); // Causes moduleCalc to be released when it goes out of scope
      moduleCalc.IsDefault(true); // Push the new instance onto the stack.
      cout << "Count after module pushes new default: " << uCalc::DefaultCount() << endl;

      // The module's context is now active.
      // uCalc::DefaultInstance() would now return 'moduleCalc'.
   }

   // When 'moduleCalc' goes out of scope, it's destroyed and automatically
   // removed from the stack, restoring the previous default.

   cout << "Count after module instance is disposed: " << uCalc::DefaultCount() << endl;

   // Verify the original default instance is active again.
   auto result = uCalc::DefaultInstance().EvalStr("PI");
   cout << "Original context restored. PI = " << result << endl;
}