NullPointerArgumentEvaluator.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-08
  6. * Changed: 2024-05-31
  7. *
  8. * */
  9. #include <ls-std/core/evaluator/NullPointerArgumentEvaluator.hpp>
  10. #include <ls-std/core/exception/IllegalArgumentException.hpp>
  11. using ls::std::core::IllegalArgumentException;
  12. using ls::std::core::NullPointerArgumentEvaluator;
  13. using std::make_shared;
  14. using std::move;
  15. using std::shared_ptr;
  16. using std::string;
  17. NullPointerArgumentEvaluator::NullPointerArgumentEvaluator(const shared_ptr<void> &_argument) : argument(_argument)
  18. {}
  19. NullPointerArgumentEvaluator::NullPointerArgumentEvaluator(const shared_ptr<void> &_argument, string _message) : NullPointerArgumentEvaluator(_argument)
  20. {
  21. this->message = ::move(_message);
  22. }
  23. NullPointerArgumentEvaluator::~NullPointerArgumentEvaluator() noexcept = default;
  24. void NullPointerArgumentEvaluator::evaluate()
  25. {
  26. if (this->argument == nullptr)
  27. {
  28. if (this->message.empty())
  29. {
  30. throw IllegalArgumentException{"passed argument is null!"};
  31. }
  32. throw IllegalArgumentException{this->message};
  33. }
  34. }