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

using namespace std;
using namespace uCalcSoftware;

void ucalc_call OutputAnswerCB(uCalcBase::Callback cb) {
   cb.ReturnStr("Answer: " + cb.ArgStr(1));
}
void ucalc_call OutputSymbolCB(uCalcBase::Callback cb) {
   cb.ReturnStr("==> " + cb.ArgStr(1));
}
void ucalc_call OutputBoolCB(uCalcBase::Callback cb) {
   if (cb.ArgStr(1) == "false") {
      cb.ReturnStr("No");
   } else if (cb.ArgStr(1) == "true") {
      cb.ReturnStr("Yes");
   }
}
int main() {
   uCalc uc;

   // This format inserts "Answer: " in front of every result
   auto OutputAnswer = uc.Format( OutputAnswerCB);
   cout << uc.EvalStr("10+20") << endl;
   cout << uc.EvalStr("'Hello '+'world'") << endl;
   cout << uc.EvalStr("5 > 10") << endl;
   cout << "---" << endl;

   // This one inserts ==> in front of the result
   // The previously defined "Answer: " output is still prepended as well
   auto OutputSymbol = uc.Format( OutputSymbolCB);
   cout << uc.EvalStr("10+20") << endl;
   cout << uc.EvalStr("'Hello '+'world'") << endl;
   cout << uc.EvalStr("5 > 10") << endl;
   cout << "---" << endl;

   // Causes Boolean values to return Yes or No (instead of true or false)
   auto OutputBool = uc.Format( OutputBoolCB, "Bool");
   cout << uc.EvalStr("10+20") << endl;
   cout << uc.EvalStr("'Hello '+'world'") << endl;
   cout << uc.EvalStr("5 > 10") << endl;
   cout << uc.EvalStr("5 < 10") << endl;
   cout << "---" << endl;

   // The previously defined "==>" output is removed
   OutputSymbol.Release();
   cout << uc.EvalStr("10+20") << endl;
   cout << uc.EvalStr("'Hello '+'world'") << endl;
   cout << uc.EvalStr("5 > 10") << endl;
   cout << uc.EvalStr("5 < 10") << endl;
}