Zero  0.1.0
multi_clock_exceptions.hpp
Go to the documentation of this file.
1 #ifndef __MULTI_CLOCK_EXCEPTIONS_HPP
2 #define __MULTI_CLOCK_EXCEPTIONS_HPP
3 
4 #include <exception>
5 
6 namespace zero::multi_clock {
7 
8  typedef uint32_t ClockIndex;
9 
10  template<class key_type,
11  class value_type, uint32_t clock_count, key_type invalid_index, key_type invalid_clock_index>
12  class MultiHandedClock;
13 
28  template<class key_type,
29  class value_type, uint32_t clock_count, key_type invalid_index, key_type invalid_clock_index = clock_count>
30  class MultiHandedClockException : public std::exception {
31  public:
39  MultiHandedClockException(const MultiHandedClock<key_type, value_type, clock_count, invalid_index,
40  invalid_clock_index>* multiHandedClock) :
41  _multiHandedClock(multiHandedClock) {};
42 
49  const char* what() const noexcept override {
50  int whatStringLength = snprintf(nullptr, 0,
51  "An unknown exception happened in the MultiHandedClock instance %p",
53  char* whatSentence = new char[whatStringLength + 1];
54  snprintf(whatSentence, whatStringLength,
55  "An unknown exception happened in the MultiHandedClock instance %p",
57  return whatSentence;
58  };
59 
60  protected:
65  const MultiHandedClock<key_type, value_type, clock_count, invalid_index,
66  invalid_clock_index>* _multiHandedClock;
67  };
68 
82  template<class key_type,
83  class value_type, uint32_t clock_count, key_type invalid_index, key_type invalid_clock_index = clock_count>
84  class MultiHandedClockEmptyException : public MultiHandedClockException<key_type, value_type, clock_count,
85  invalid_index, invalid_clock_index> {
86  public:
95  MultiHandedClockEmptyException(const MultiHandedClock<key_type, value_type, clock_count, invalid_index,
96  invalid_clock_index>* multiHandedClock,
97  const ClockIndex& emptyClock) :
98  MultiHandedClockException<key_type, value_type, clock_count, invalid_index, invalid_clock_index>(
99  multiHandedClock),
100  _emptyClock(emptyClock) {};
101 
102  const char* what() const noexcept override {
103  int whatStringLength = snprintf(nullptr, 0,
104  "The clock %u of MultiHandedClock instance %p was unexpectedly empty.",
105  _emptyClock, this->_multiHandedClock);
106  char* whatSentence = new char[whatStringLength + 1];
107  snprintf(whatSentence, whatStringLength,
108  "The clock %u of MultiHandedClock instance %p was unexpectedly empty.",
109  _emptyClock, this->_multiHandedClock);
110  return whatSentence;
111  };
112 
113  protected:
119  const ClockIndex _emptyClock;
120  };
121 
136  template<class key_type,
137  class value_type, uint32_t clock_count, key_type invalid_index, key_type invalid_clock_index = clock_count>
138  class MultiHandedClockInvalidIndexException : public MultiHandedClockException<key_type, value_type, clock_count,
139  invalid_index, invalid_clock_index> {
140  public:
150  MultiHandedClockInvalidIndexException(const MultiHandedClock<key_type, value_type, clock_count, invalid_index,
151  invalid_clock_index>* multiHandedClock,
152  const key_type& invalidIndex) :
153  MultiHandedClockException<key_type, value_type, clock_count, invalid_index, invalid_clock_index>(
154  multiHandedClock),
155  _invalidIndex(invalidIndex) {};
156 
157  const char* what() const noexcept override {
158  int whatStringLength = snprintf(nullptr, 0,
159  "The index %u is invalid for the MultiHandedClock instance %p.",
160  _invalidIndex, this->_multiHandedClock);
161  char* whatSentence = new char[whatStringLength + 1];
162  snprintf(whatSentence, whatStringLength,
163  "The index %u is invalid for the MultiHandedClock instance %p.",
164  _invalidIndex, this->_multiHandedClock);
165  return whatSentence;
166  };
167 
168  protected:
173  const key_type _invalidIndex;
174  };
175 
189  template<class key_type,
190  class value_type, uint32_t clock_count, key_type invalid_index, key_type invalid_clock_index = clock_count>
192  clock_count, invalid_index,
193  invalid_clock_index> {
194  public:
205  const MultiHandedClock<key_type, value_type, clock_count, invalid_index,
206  invalid_clock_index>* multiHandedClock,
207  const key_type& alreadyContainedIndex) :
208  MultiHandedClockException<key_type, value_type, clock_count, invalid_index, invalid_clock_index>(
209  multiHandedClock),
210  _alreadyContainedIndex(alreadyContainedIndex) {};
211 
212  const char* what() const noexcept override {
213  int whatStringLength = snprintf(nullptr, 0,
214  "The index %u is unexpectedly already contained in the MultiHandedClock instance %p.",
215  _alreadyContainedIndex, this->_multiHandedClock);
216  char* whatSentence = new char[whatStringLength + 1];
217  snprintf(whatSentence, whatStringLength,
218  "The index %u is unexpectedly already contained in the MultiHandedClock instance %p.",
219  _alreadyContainedIndex, this->_multiHandedClock);
220  return whatSentence;
221  };
222 
223  protected:
228  const key_type _alreadyContainedIndex;
229  };
230 
244  template<class key_type,
245  class value_type, uint32_t clock_count, key_type invalid_index, key_type invalid_clock_index = clock_count>
246  class MultiHandedClockNotContainedException : public MultiHandedClockException<key_type, value_type, clock_count,
247  invalid_index, invalid_clock_index> {
248  public:
258  MultiHandedClockNotContainedException(const MultiHandedClock<key_type, value_type, clock_count, invalid_index,
259  invalid_clock_index>* multiHandedClock,
260  const key_type& notContainedIndex) :
261  MultiHandedClockException<key_type, value_type, clock_count, invalid_index, invalid_clock_index>(
262  multiHandedClock),
263  _notContainedIndex(notContainedIndex) {};
264 
265  const char* what() const noexcept override {
266  int whatStringLength = snprintf(nullptr, 0,
267  "The index %u is unexpectedly not contained in the MultiHandedClock instance %p.",
268  _notContainedIndex, this->_multiHandedClock);
269  char* whatSentence = new char[whatStringLength + 1];
270  snprintf(whatSentence, whatStringLength,
271  "The index %u is unexpectedly not contained in the MultiHandedClock instance %p.",
272  _notContainedIndex, this->_multiHandedClock);
273  return whatSentence;
274  };
275 
276  protected:
281  const key_type _notContainedIndex;
282  };
283 }
284 
285 #endif // __MULTI_CLOCK_EXCEPTIONS_HPP
MultiHandedClockInvalidIndexException(const MultiHandedClock< key_type, value_type, clock_count, invalid_index, invalid_clock_index > *multiHandedClock, const key_type &invalidIndex)
Constructor of an exception thrown when an access to a MultiHandedClock with an invalid index happens...
Definition: multi_clock_exceptions.hpp:150
Exception Thrown When an Access to a MultiHandedClock with an Invalid Index Happens.
Definition: multi_clock_exceptions.hpp:138
Exception thrown when a MultiHandedClock is empty.
Definition: multi_clock_exceptions.hpp:84
const ClockIndex _emptyClock
Index of the Empty Clock.
Definition: multi_clock_exceptions.hpp:119
Exception thrown in a MultiHandedClock.
Definition: multi_clock_exceptions.hpp:30
const MultiHandedClock< key_type, value_type, clock_count, invalid_index, invalid_clock_index > * _multiHandedClock
The MultiHandedClock.
Definition: multi_clock_exceptions.hpp:66
const key_type _notContainedIndex
The Expected Key.
Definition: multi_clock_exceptions.hpp:281
const char * what() const noexcept override
Definition: multi_clock_exceptions.hpp:265
uint32_t ClockIndex
Data type of clock indexes.
Definition: multi_clock.hpp:17
const char * what() const noexcept override
Definition: multi_clock_exceptions.hpp:157
Definition: multi_clock.hpp:11
const key_type _invalidIndex
Invalid Index That was Used.
Definition: multi_clock_exceptions.hpp:173
Exception thrown when a key is already contained in a MultiHandedClock.
Definition: multi_clock_exceptions.hpp:191
MultiHandedClockException(const MultiHandedClock< key_type, value_type, clock_count, invalid_index, invalid_clock_index > *multiHandedClock)
Constructor of an exception thrown in MultiHandedClock.
Definition: multi_clock_exceptions.hpp:39
MultiHandedClockNotContainedException(const MultiHandedClock< key_type, value_type, clock_count, invalid_index, invalid_clock_index > *multiHandedClock, const key_type &notContainedIndex)
Constructor of an exception thrown when a key was unexpectedly not already contained in any clock of ...
Definition: multi_clock_exceptions.hpp:258
MultiHandedClockAlreadyContainedException(const MultiHandedClock< key_type, value_type, clock_count, invalid_index, invalid_clock_index > *multiHandedClock, const key_type &alreadyContainedIndex)
Constructor of an exception thrown when a key was unexpectedly already contained in any clock of the ...
Definition: multi_clock_exceptions.hpp:204
Multiple Clocks with a Common Set of Entries.
Definition: multi_clock.hpp:54
MultiHandedClockEmptyException(const MultiHandedClock< key_type, value_type, clock_count, invalid_index, invalid_clock_index > *multiHandedClock, const ClockIndex &emptyClock)
Constructor of an exception thrown when an MultiHandedClock is empty.
Definition: multi_clock_exceptions.hpp:95
const key_type _alreadyContainedIndex
The unexpected key.
Definition: multi_clock_exceptions.hpp:228
const char * what() const noexcept override
Definition: multi_clock_exceptions.hpp:212
Exception thrown when a key is not already contained in a MultiHandedClock.
Definition: multi_clock_exceptions.hpp:246
const char * what() const noexcept override
Definition: multi_clock_exceptions.hpp:102
const char * what() const noexcept override
What caused the exception happened?
Definition: multi_clock_exceptions.hpp:49