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

using namespace std;
using namespace uCalcSoftware;

#define tf(IsTrue) ((IsTrue) ? "True" : "False")

int main() {
   uCalc uc;

   // In C# and VB you should use "using".
   // In C++ you can flag a uCalc object for
   // auto-release with Owned(), or by setting
   // the last parameter of the constructor to true.

   uCalc::Transformer t(uc);
   auto MemIndex = t.MemoryIndex();
   t.Release(); // MemIndex will be recycled and assigned to the next def


   {
      uCalc::Transformer TempTransform(uc);
      TempTransform.Owned(); // Causes TempTransform to be released when it goes out of scope // Owned() causes TempTransform to be released when it goes out of scope
      cout << tf(TempTransform.MemoryIndex() == MemIndex) << endl; // MemoryIndex() will be the recycled value of the released t object
   }
   // TempTransform goes out of scope here

   uCalc::Transformer t3(uc);
   cout << tf(t3.MemoryIndex() == MemIndex) << endl; // MemoryIndex() will be the recycled value of the released TempTransform object
   t3.Release();

   {
      uCalc::Transformer StickyTransformer(uc); // StickyTransformer here does NOT get released when it goes out of scope
      cout << tf(StickyTransformer.MemoryIndex() == MemIndex) << endl;
   } // StickyTransformer remains in memery

   uCalc::Transformer t4(uc);
   cout << tf(t4.MemoryIndex() == MemIndex) << endl; // False since StickyTransformer was not released; MemoryIndex() has a new value
}