NullPointerEvaluator.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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-04
  7. *
  8. * */
  9. #include <ls-std/core/evaluator/NullPointerEvaluator.hpp>
  10. #include <ls-std/core/exception/NullPointerException.hpp>
  11. using ls::std::core::NullPointerEvaluator;
  12. using ls::std::core::NullPointerException;
  13. using std::make_shared;
  14. using std::move;
  15. using std::shared_ptr;
  16. using std::string;
  17. NullPointerEvaluator::NullPointerEvaluator(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. NullPointerEvaluator::NullPointerEvaluator(const void *_rawArgument, string _message) : NullPointerEvaluator(_rawArgument)
  27. {
  28. this->message = ::move(_message);
  29. }
  30. NullPointerEvaluator::NullPointerEvaluator(const shared_ptr<void> &_argument) : argument(_argument)
  31. {}
  32. NullPointerEvaluator::NullPointerEvaluator(const shared_ptr<void> &_argument, string _message) : argument(_argument), message(::move(_message))
  33. {}
  34. NullPointerEvaluator::~NullPointerEvaluator() noexcept = default;
  35. void NullPointerEvaluator::evaluate()
  36. {
  37. if (this->argument == nullptr)
  38. {
  39. if (this->message.empty())
  40. {
  41. throw NullPointerException{"reference in use is null!"};
  42. }
  43. else
  44. {
  45. throw NullPointerException{this->message};
  46. }
  47. }
  48. }