RawNullPointerEvaluator.hpp 1.6 KB

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