IndexOutOfBoundsEvaluator.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-10
  6. * Changed: 2023-02-23
  7. *
  8. * */
  9. #include <ls-std/core/evaluator/IndexOutOfBoundsEvaluator.hpp>
  10. #include <ls-std/core/exception/IndexOutOfBoundsException.hpp>
  11. using ls::std::core::IndexOutOfBoundsEvaluator;
  12. using ls::std::core::IndexOutOfBoundsException;
  13. using std::move;
  14. using std::string;
  15. IndexOutOfBoundsEvaluator::IndexOutOfBoundsEvaluator(size_t _index, size_t _size) : index(_index), size(_size)
  16. {}
  17. IndexOutOfBoundsEvaluator::IndexOutOfBoundsEvaluator(size_t _index, size_t _size, string _message) : index(_index), size(_size), message(::move(_message))
  18. {}
  19. IndexOutOfBoundsEvaluator::~IndexOutOfBoundsEvaluator() noexcept = default;
  20. void IndexOutOfBoundsEvaluator::evaluate()
  21. {
  22. if (this->index >= this->size)
  23. {
  24. if (this->message.empty())
  25. {
  26. throw IndexOutOfBoundsException{};
  27. }
  28. else
  29. {
  30. throw IndexOutOfBoundsException{this->message};
  31. }
  32. }
  33. }