RawNullPointerEvaluator.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-24
  6. * Changed: 2024-05-25
  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. * @class(name: 'RawNullPointerEvaluator', package: 'core')
  17. * */
  18. namespace ls::std::core
  19. {
  20. template<typename T>
  21. class RawNullPointerEvaluator : public ls::std::core::interface_type::IEvaluator
  22. {
  23. public:
  24. explicit RawNullPointerEvaluator(const ls::std::core::type::RawPointer<T> &_argument) : argument(_argument)
  25. {}
  26. RawNullPointerEvaluator(const ls::std::core::type::RawPointer<T> &_argument, const ::std::string &_message) : argument(_argument), message(_message)
  27. {}
  28. ~RawNullPointerEvaluator() 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::NullPointerException{"reference in use is null!"};
  36. }
  37. else
  38. {
  39. throw ls::std::core::NullPointerException{this->message};
  40. }
  41. }
  42. }
  43. private:
  44. ls::std::core::type::RawPointer<T> argument{};
  45. ::std::string message{};
  46. };
  47. }
  48. #endif