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

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   // Original default instance
   uCalc::DefaultInstance().DefineVariable("id = 'Original'");
   cout << "Current Default ID: " << uCalc::DefaultInstance().EvalStr("id") << endl;

   // Push a new default instance onto the stack
   uCalc ucA;
   ucA.DefineVariable("id = 'Instance A'");
   ucA.IsDefault(true);
   cout << "Current Default ID: " << uCalc::DefaultInstance().EvalStr("id") << endl;

   // The 'NewUsing' block creates a temporary, scoped default instance

   // The following instance will be auto-released at the end of the block
   {
      uCalc ucB;
      ucB.Owned(); // Causes ucB to be released when it goes out of scope
      ucB.DefineVariable("id = 'Instance B (temp)'");
      ucB.IsDefault(true); // Pushes 'ucB' onto the stack
      cout << "Current Default ID: " << uCalc::DefaultInstance().EvalStr("id") << endl;
   }

   // 'ucB' has gone out of scope, so the default reverts to the previous one ('ucA')
   cout << "Current Default ID (after scope exit): " << uCalc::DefaultInstance().EvalStr("id") << endl;

   // Manually unset 'ucA'
   ucA.IsDefault(false);
   cout << "Current Default ID (after unset): " << uCalc::DefaultInstance().EvalStr("id") << endl;
}