mpaymetov / oop-labs

Задания по объектно-ориентированному программированию
0 stars 0 forks source link

Замечания по программе Calculator #20

Open alexey-malov opened 5 years ago

alexey-malov commented 5 years ago
alexey-malov commented 5 years ago
alexey-malov commented 5 years ago
alexey-malov commented 5 years ago

Преобразование из/в строковое представление лучше оставить в CalcControl

alexey-malov commented 5 years ago
alexey-malov commented 5 years ago
alexey-malov commented 5 years ago
alexey-malov commented 5 years ago
class CCalculator
{
public:
    CCalculator() = default;
    ~CCalculator() = default; 
alexey-malov commented 5 years ago
alexey-malov commented 5 years ago
alexey-malov commented 5 years ago
alexey-malov commented 5 years ago
alexey-malov commented 5 years ago
bool CCalculator::SetVar(const std::string& identifier, std::string& errorMsg)
{
    if (!CanBeIdentifier(identifier))
    {
        errorMsg = "identifier name incorrect";
        return false;
    }

    auto it = m_names.find(identifier);
    if (it == m_names.end())
    {
        auto val = std::make_shared<CVariable>();
        auto var = std::make_pair(identifier, val);
        m_names.insert(var); // (1)
        m_vars.insert(var); // (2)
        return true;
    }

    errorMsg = "identifier already exist";
    return false;
}
alexey-malov commented 5 years ago
bool CCalculator::SetValue(const std::string& identifier, const double value, std::string& errorMsg)
{
    if (!CanBeIdentifier(identifier))
    {
        errorMsg = "identifier name incorrect";
        return false;
    }

    std::pair<std::string, std::shared_ptr<CVariable>> var;

    auto it = m_vars.find(identifier);
    if (it != m_vars.end())
    {
        var = *it;
    }
    else
    {
        var = std::make_pair(identifier, std::make_shared<CVariable>());
        m_names.insert(var);
        m_vars.insert(var);
    }

    var.second->SetValue(value);
    UpdateFns();
    return true;
}
alexey-malov commented 5 years ago
alexey-malov commented 5 years ago
    auto it_var = m_names.find(firstOperand);
alexey-malov commented 5 years ago
alexey-malov commented 5 years ago