RawNullPointerArgumentEvaluator.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-05-23
  6. * Changed: 2023-05-24
  7. *
  8. * */
  9. #ifndef LS_STD_RAW_NULL_POINTER_ARGUMENT_EVALUATOR_HPP
  10. #define LS_STD_RAW_NULL_POINTER_ARGUMENT_EVALUATOR_HPP
  11. #include <ls-std/core/exception/IllegalArgumentException.hpp>
  12. #include <ls-std/core/interface/IEvaluator.hpp>
  13. #include <ls-std/core/type/RawPointer.hpp>
  14. #include <string>
  15. namespace ls::std::core
  16. {
  17. template<typename T>
  18. class RawNullPointerArgumentEvaluator : public ls::std::core::interface_type::IEvaluator
  19. {
  20. public:
  21. explicit RawNullPointerArgumentEvaluator(const ls::std::core::type::RawPointer<T> &_argument) : argument(_argument)
  22. {}
  23. explicit RawNullPointerArgumentEvaluator(const ls::std::core::type::RawPointer<T> &_argument, const ::std::string &_message) : argument(_argument), message(_message)
  24. {}
  25. ~RawNullPointerArgumentEvaluator() noexcept override = default;
  26. void evaluate() override
  27. {
  28. if (this->argument.get() == nullptr)
  29. {
  30. if (this->message.empty())
  31. {
  32. throw ls::std::core::IllegalArgumentException{"passed argument is null!"};
  33. }
  34. else
  35. {
  36. throw ls::std::core::IllegalArgumentException{this->message};
  37. }
  38. }
  39. }
  40. private:
  41. ls::std::core::type::RawPointer<T> argument{};
  42. ::std::string message{};
  43. };
  44. }
  45. #endif