Zero  0.1.0
hashtable_deque_exceptions.hpp
Go to the documentation of this file.
1 #ifndef __HASHTABLE_DEQUE_EXCEPTIONS_HPP
2 #define __HASHTABLE_DEQUE_EXCEPTIONS_HPP
3 
4 namespace zero::hashtable_deque {
5 
16  template<class key_type, key_type invalid_key>
17  class HashtableDequeException : public std::exception {
18  public:
27  HashtableDequeException(const uint64_t& size, const key_type& back, const key_type& front) :
28  _size(size),
29  _back(back),
30  _front(front) {};
31 
38  const char* what() const noexcept override {
39  return "An unknown exception happened in an instance of HashtableDeque.";
40  };
41 
48  virtual const char* details() const noexcept {
49  int whatStringLength = snprintf(nullptr, 0,
50  "HashtableDeque.size() = %zd, HashtableDeque._back = %zd, HashtableDeque._front = %zd",
51  _size, _back, _front);
52  char* whatSentence = new char[whatStringLength + 1];
53  snprintf(whatSentence, whatStringLength,
54  "HashtableDeque.size() = %zd, HashtableDeque._back = %zd, HashtableDeque._front = %zd",
55  _size, _back, _front);
56  return whatSentence;
57  };
58 
59  protected:
65  const uint64_t _size;
66 
72  const key_type _back;
73 
79  const key_type _front;
80  };
81 
92  template<class key_type, key_type invalid_key>
93  class HashtableDequeAlreadyContainsException : public HashtableDequeException<key_type, invalid_key> {
94  public:
106  HashtableDequeAlreadyContainsException(const uint64_t& size, const key_type& back, const key_type& front,
107  const key_type& containedKey) :
108  HashtableDequeException<key_type, invalid_key>(size, back, front),
109  _containedKey(containedKey) {};
110 
111  const char* what() const noexcept override {
112  int whatStringLength = snprintf(nullptr, 0,
113  "%zd was tried to be inserted into an HashtableDeque, but it was already contained in there.",
114  _containedKey);
115  char* whatSentence = new char[whatStringLength + 1];
116  snprintf(whatSentence, whatStringLength,
117  "%zd was tried to be inserted into an HashtableDeque, but it was already contained in there.",
118  _containedKey);
119  return whatSentence;
120  };
121 
122  protected:
127  const key_type _containedKey;
128  };
129 
140  template<class key_type, key_type invalid_key>
141  class HashtableDequeEmptyException : public HashtableDequeException<key_type, invalid_key> {
142  public:
144 
145  const char* what() const noexcept override {
146  return "An HashtableDeque was already empty.";
147  };
148  };
149 
160  template<class key_type, key_type invalid_key>
161  class HashtableDequeNotContainedException : public HashtableDequeException<key_type, invalid_key> {
162  public:
173  HashtableDequeNotContainedException(const uint64_t& size, const key_type& back, const key_type& front,
174  const key_type& requestedKey) :
175  HashtableDequeException<key_type, invalid_key>(size, back, front),
176  _requestedKey(requestedKey) {};
177 
178  const char* what() const noexcept override {
179  int whatStringLength = snprintf(nullptr, 0, "An HashtableDeque does not contain key %zd", _requestedKey);
180  char* whatSentence = new char[whatStringLength + 1];
181  snprintf(whatSentence, whatStringLength, "An HashtableDeque does not contain key %zd", _requestedKey);
182  return whatSentence;
183  };
184 
185  private:
190  const key_type _requestedKey;
191  };
192 
203  template<class key_type, key_type invalid_key>
205  public:
216  HashtableDequeAlreadyAtTheFrontException(const uint64_t& size, const key_type& back, const key_type& front,
217  const key_type& frontKey) :
218  HashtableDequeException<key_type, invalid_key>(size, back, front),
219  _frontKey(frontKey) {};
220 
221  const char* what() const noexcept override {
222  int whatStringLength = snprintf(nullptr, 0, "An HashtableDeque has key %zd at the front", _frontKey);
223  char* whatSentence = new char[whatStringLength + 1];
224  snprintf(whatSentence, whatStringLength, "An HashtableDeque has key %zd at the front", _frontKey);
225  return whatSentence;
226  };
227 
228  private:
233  const key_type _frontKey;
234  };
235 
246  template<class key_type, key_type invalid_key>
247  class HashtableDequeAlreadyAtTheBackException : public HashtableDequeException<key_type, invalid_key> {
248  public:
259  HashtableDequeAlreadyAtTheBackException(const uint64_t& size, const key_type& back, const key_type& front,
260  const key_type& backKey) :
261  HashtableDequeException<key_type, invalid_key>(size, back, front),
262  _backKey(backKey) {};
263 
264  const char* what() const noexcept override {
265  int whatStringLength = snprintf(nullptr, 0, "An HashtableDeque has key %zd at the back", _backKey);
266  char* whatSentence = new char[whatStringLength + 1];
267  snprintf(whatSentence, whatStringLength, "An HashtableDeque has key %zd at the back", _backKey);
268  return whatSentence;
269  };
270 
271  private:
276  const key_type _backKey;
277  };
278 
279 }
280 
281 #endif //__HASHTABLE_DEQUE_EXCEPTIONS_HPP
HashtableDequeNotContainedException(const uint64_t &size, const key_type &back, const key_type &front, const key_type &requestedKey)
Constructor of an exception thrown when an entry was not already contained in an HashtableDeque.
Definition: hashtable_deque_exceptions.hpp:173
const char * what() const noexcept override
What caused the exception happened?
Definition: hashtable_deque_exceptions.hpp:38
const key_type _containedKey
The Unexpected Entry.
Definition: hashtable_deque_exceptions.hpp:127
const key_type _frontKey
The Entry at the Front.
Definition: hashtable_deque_exceptions.hpp:233
virtual const char * details() const noexcept
Details about the exceptional state.
Definition: hashtable_deque_exceptions.hpp:48
Exception thrown when an entry was not already contained in an HashtableDeque.
Definition: hashtable_deque_exceptions.hpp:161
Definition: hashtable_deque.hpp:10
Exception thrown when an entry was already at the front of an HashtableDeque.
Definition: hashtable_deque_exceptions.hpp:204
Exception thrown in HashtableDeque.
Definition: hashtable_deque_exceptions.hpp:17
Exception thrown when an entry was already at the back of an HashtableDeque.
Definition: hashtable_deque_exceptions.hpp:247
const char * what() const noexcept override
Definition: hashtable_deque_exceptions.hpp:145
const char * what() const noexcept override
Definition: hashtable_deque_exceptions.hpp:264
const char * what() const noexcept override
Definition: hashtable_deque_exceptions.hpp:111
const key_type _back
The back of the HashtableDeque.
Definition: hashtable_deque_exceptions.hpp:72
const key_type _backKey
The Entry at the Back.
Definition: hashtable_deque_exceptions.hpp:276
Exception thrown when an entry was already contained in an HashtableDeque.
Definition: hashtable_deque_exceptions.hpp:93
HashtableDequeAlreadyContainsException(const uint64_t &size, const key_type &back, const key_type &front, const key_type &containedKey)
Constructor of an exception thrown when an entry was already contained in an HashtableDeque.
Definition: hashtable_deque_exceptions.hpp:106
HashtableDequeAlreadyAtTheFrontException(const uint64_t &size, const key_type &back, const key_type &front, const key_type &frontKey)
Definition: hashtable_deque_exceptions.hpp:216
const key_type _requestedKey
The Expected Entry.
Definition: hashtable_deque_exceptions.hpp:190
Exception thrown when an HashtableDeque is empty.
Definition: hashtable_deque_exceptions.hpp:141
const key_type _front
The front of the HashtableDeque.
Definition: hashtable_deque_exceptions.hpp:79
HashtableDequeAlreadyAtTheBackException(const uint64_t &size, const key_type &back, const key_type &front, const key_type &backKey)
Definition: hashtable_deque_exceptions.hpp:259
const char * what() const noexcept override
Definition: hashtable_deque_exceptions.hpp:221
const char * what() const noexcept override
Definition: hashtable_deque_exceptions.hpp:178
const uint64_t _size
The size of the HashtableDeque.
Definition: hashtable_deque_exceptions.hpp:65
HashtableDequeException(const uint64_t &size, const key_type &back, const key_type &front)
Constructor of an exception thrown in HashtableDeque.
Definition: hashtable_deque_exceptions.hpp:27