Skip to content

Commit

Permalink
Refactor logic functions
Browse files Browse the repository at this point in the history
  • Loading branch information
fintarin committed Aug 7, 2023
1 parent 599ed2e commit 682dc4f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/fintamath/functions/logic/And.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
namespace fintamath {

std::unique_ptr<IMathObject> And::call(const ArgumentsRefVector &argsVect) const {
return std::make_unique<Boolean>(cast<Boolean>(argsVect.front().get()) && cast<Boolean>(argsVect.back().get()));
const auto &lhs = cast<Boolean>(argsVect.front().get());
const auto &rhs = cast<Boolean>(argsVect.back().get());

return std::make_unique<Boolean>(lhs && rhs);
}

}
5 changes: 4 additions & 1 deletion src/fintamath/functions/logic/Equiv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
namespace fintamath {

std::unique_ptr<IMathObject> Equiv::call(const ArgumentsRefVector &argsVect) const {
return std::make_unique<Boolean>(cast<Boolean>(argsVect.front().get()) == cast<Boolean>(argsVect.back().get()));
const auto &lhs = cast<Boolean>(argsVect.front().get());
const auto &rhs = cast<Boolean>(argsVect.back().get());

return std::make_unique<Boolean>(lhs == rhs);
}

}
5 changes: 4 additions & 1 deletion src/fintamath/functions/logic/Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
namespace fintamath {

std::unique_ptr<IMathObject> Impl::call(const ArgumentsRefVector &argsVect) const {
return std::make_unique<Boolean>(!cast<Boolean>(argsVect.front().get()) || cast<Boolean>(argsVect.back().get()));
const auto &lhs = cast<Boolean>(argsVect.front().get());
const auto &rhs = cast<Boolean>(argsVect.back().get());

return std::make_unique<Boolean>(!lhs || rhs);
}

}
5 changes: 4 additions & 1 deletion src/fintamath/functions/logic/Nequiv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
namespace fintamath {

std::unique_ptr<IMathObject> Nequiv::call(const ArgumentsRefVector &argsVect) const {
return std::make_unique<Boolean>(cast<Boolean>(argsVect.front().get()) != cast<Boolean>(argsVect.back().get()));
const auto &lhs = cast<Boolean>(argsVect.front().get());
const auto &rhs = cast<Boolean>(argsVect.back().get());

return std::make_unique<Boolean>(lhs != rhs);
}

}
4 changes: 3 additions & 1 deletion src/fintamath/functions/logic/Not.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace fintamath {

std::unique_ptr<IMathObject> Not::call(const ArgumentsRefVector &argsVect) const {
return std::make_unique<Boolean>(!cast<Boolean>(argsVect.front().get()));
const auto &rhs = cast<Boolean>(argsVect.front().get());

return std::make_unique<Boolean>(!rhs);
}

}
5 changes: 4 additions & 1 deletion src/fintamath/functions/logic/Or.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
namespace fintamath {

std::unique_ptr<IMathObject> Or::call(const ArgumentsRefVector &argsVect) const {
return std::make_unique<Boolean>(cast<Boolean>(argsVect.front().get()) || cast<Boolean>(argsVect.back().get()));
const auto &lhs = cast<Boolean>(argsVect.front().get());
const auto &rhs = cast<Boolean>(argsVect.back().get());

return std::make_unique<Boolean>(lhs || rhs);
}

}

0 comments on commit 682dc4f

Please sign in to comment.