Example #1
0
bool WinFrame::ExecExpr(const std::string& expr)
{
    /* If expression is empty -> show information */
    if (expr.empty())
        ShowIntro();
    else if (expr == "exit")
    {
        /* Clear input to avoid storing "exit" in the config-file */
        SetInput("");
        Close();
    }
    else if (expr == "demo")
        ShowDemo();
    else if (expr == "const")
        ShowConstants();
    else if (expr == "clear")
    {
        constantsSet_.constants.clear();
        constantsSet_.ResetStd();
        ShowConstants();
    }
    else
    {
        /* Setup compute mode */
        Ac::ComputeMode mode;
        mode.degree = GetOptionDegree();

        /* Show status message */
        SetOutput("computing ...");

#ifdef AC_MULTI_THREADED

        /* Wait until previous thread has successfully terminated */
        if (computing_)
            return false;
        JoinThread();

#endif

        /* Compute expression */
#ifdef AC_MULTI_THREADED

        computing_ = true;
        thread_ = std::unique_ptr<std::thread>(new std::thread(&WinFrame::ComputeThreadProc, this, expr, mode));

#else

        ComputeThreadProc(expr.ToStdString(), mode);

#endif
    }

    return true;
}