RawNullPointerArgumentEvaluator.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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-25
  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. /*
  16. * @class(name: 'RawNullPointerArgumentEvaluator', package: 'core')
  17. * */
  18. namespace ls::std::core
  19. {
  20. template<typename T>
  21. class RawNullPointerArgumentEvaluator : public ls::std::core::interface_type::IEvaluator
  22. {
  23. public:
  24. explicit RawNullPointerArgumentEvaluator(const ls::std::core::type::RawPointer<T> &_argument) : argument(_argument)
  25. {}
  26. explicit RawNullPointerArgumentEvaluator(const ls::std::core::type::RawPointer<T> &_argument, const ::std::string &_message) : argument(_argument), message(_message)
  27. {}
  28. ~RawNullPointerArgumentEvaluator() noexcept override = default;
  29. void evaluate() override
  30. {
  31. if (this->argument.get() == nullptr)
  32. {
  33. if (this->message.empty())
  34. {
  35. throw ls::std::core::IllegalArgumentException{"passed argument is null!"};
  36. }
  37. else
  38. {
  39. throw ls::std::core::IllegalArgumentException{this->message};
  40. }
  41. }
  42. }
  43. private:
  44. ls::std::core::type::RawPointer<T> argument{};
  45. ::std::string message{};
  46. };
  47. }
  48. #endif