RawNullPointerEvaluator.hpp 1.7 KB

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