RawNullPointerArgumentEvaluator.hpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-05-23
  6. * Changed: 2024-05-31
  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 final : public interface_type::IEvaluator
  19. {
  20. public:
  21. explicit RawNullPointerArgumentEvaluator(const type::RawPointer<T> &_argument) : argument(_argument)
  22. {}
  23. explicit RawNullPointerArgumentEvaluator(const type::RawPointer<T> &_argument, ::std::string _message) : argument(_argument), message(::std::move(_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 IllegalArgumentException{"passed argument is null!"};
  33. }
  34. throw IllegalArgumentException{this->message};
  35. }
  36. }
  37. private:
  38. type::RawPointer<T> argument{};
  39. ::std::string message{};
  40. };
  41. }
  42. #endif