NullPointerArgumentEvaluator.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-08
  6. * Changed: 2023-04-07
  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 void *_rawArgument)
  18. {
  19. shared_ptr<void> value{};
  20. if (_rawArgument != nullptr)
  21. {
  22. value = make_shared<int>();
  23. }
  24. this->argument = value;
  25. }
  26. NullPointerArgumentEvaluator::NullPointerArgumentEvaluator(const void *_rawArgument, string _message) : NullPointerArgumentEvaluator(_rawArgument)
  27. {
  28. this->message = ::move(_message);
  29. }
  30. NullPointerArgumentEvaluator::NullPointerArgumentEvaluator(const shared_ptr<void> &_argument) : argument(_argument)
  31. {}
  32. NullPointerArgumentEvaluator::NullPointerArgumentEvaluator(const shared_ptr<void> &_argument, string _message) : NullPointerArgumentEvaluator(_argument)
  33. {
  34. this->message = ::move(_message);
  35. }
  36. NullPointerArgumentEvaluator::~NullPointerArgumentEvaluator() noexcept = default;
  37. void NullPointerArgumentEvaluator::evaluate()
  38. {
  39. if (this->argument == nullptr)
  40. {
  41. if (this->message.empty())
  42. {
  43. throw IllegalArgumentException{"passed argument is null!"};
  44. }
  45. else
  46. {
  47. throw IllegalArgumentException{this->message};
  48. }
  49. }
  50. }