| 1 |
/// The MIT License (MIT) |
| 2 |
/// Copyright (c) 2016 Peter Goldsborough |
| 3 |
/// |
| 4 |
/// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 |
/// of this software and associated documentation files (the "Software"), to |
| 6 |
/// deal in the Software without restriction, including without limitation the |
| 7 |
/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 8 |
/// sell copies of the Software, and to permit persons to whom the Software is |
| 9 |
/// furnished to do so, subject to the following conditions: |
| 10 |
/// |
| 11 |
/// The above copyright notice and this permission notice shall be included in |
| 12 |
/// all copies or substantial portions of the Software. |
| 13 |
/// |
| 14 |
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 |
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 |
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 |
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 19 |
/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 20 |
/// IN THE SOFTWARE. |
| 21 |
|
| 22 |
#ifndef LRU_INTERNAL_ERRORS_HPP |
| 23 |
#define LRU_INTERNAL_ERRORS_HPP |
| 24 |
|
| 25 |
#include <stdexcept> |
| 26 |
#include <string> |
| 27 |
|
| 28 |
namespace LRU { |
| 29 |
namespace Error { |
| 30 |
|
| 31 |
/// Exception thrown when the value of an invalid key was requested. |
| 32 |
struct KeyNotFound : public std::runtime_error { |
| 33 |
using super = std::runtime_error; |
| 34 |
|
| 35 |
KeyNotFound() : super("Failed to find key") { |
| 36 |
} |
| 37 |
|
| 38 |
explicit KeyNotFound(const std::string& key) |
| 39 |
: super("Failed to find key: " + key) { |
| 40 |
} |
| 41 |
}; |
| 42 |
|
| 43 |
/// Exception thrown when the value of an expired key was requested. |
| 44 |
struct KeyExpired : public std::runtime_error { |
| 45 |
using super = std::runtime_error; |
| 46 |
|
| 47 |
explicit KeyExpired(const std::string& key) |
| 48 |
: super("Key found, but expired: " + key) { |
| 49 |
} |
| 50 |
|
| 51 |
KeyExpired() : super("Key found, but expired") { |
| 52 |
} |
| 53 |
}; |
| 54 |
|
| 55 |
/// Exception thrown when requesting the front or end key of an empty cache. |
| 56 |
struct EmptyCache : public std::runtime_error { |
| 57 |
using super = std::runtime_error; |
| 58 |
explicit EmptyCache(const std::string& what_was_expected) |
| 59 |
: super("Requested " + what_was_expected + " of empty cache") { |
| 60 |
} |
| 61 |
}; |
| 62 |
|
| 63 |
/// Exception thrown when attempting to convert an invalid unordered iterator to |
| 64 |
/// an ordered iterator. |
| 65 |
struct InvalidIteratorConversion : public std::runtime_error { |
| 66 |
using super = std::runtime_error; |
| 67 |
InvalidIteratorConversion() |
| 68 |
: super("Cannot convert past-the-end unordered to ordered iterator") { |
| 69 |
} |
| 70 |
}; |
| 71 |
|
| 72 |
/// Exception thrown when attempting to erase the past-the-end iterator. |
| 73 |
struct InvalidIterator : public std::runtime_error { |
| 74 |
using super = std::runtime_error; |
| 75 |
InvalidIterator() : super("Past-the-end iterator is invalid here") { |
| 76 |
} |
| 77 |
}; |
| 78 |
|
| 79 |
/// Exception thrown when requesting statistics about an unmonitored key. |
| 80 |
struct UnmonitoredKey : public std::runtime_error { |
| 81 |
using super = std::runtime_error; |
| 82 |
UnmonitoredKey() : super("Requested statistics for unmonitored key") { |
| 83 |
} |
| 84 |
}; |
| 85 |
|
| 86 |
/// Exception thrown when requesting the statistics object of a cache when none |
| 87 |
/// was registered. |
| 88 |
struct NotMonitoring : public std::runtime_error { |
| 89 |
using super = std::runtime_error; |
| 90 |
NotMonitoring() : super("Statistics monitoring not enabled for this cache") { |
| 91 |
} |
| 92 |
}; |
| 93 |
|
| 94 |
namespace Lowercase { |
| 95 |
using key_not_found = KeyNotFound; |
| 96 |
using key_expired = KeyExpired; |
| 97 |
using empty_cache = EmptyCache; |
| 98 |
using invalid_iterator_conversion = InvalidIteratorConversion; |
| 99 |
using invalid_iterator = InvalidIterator; |
| 100 |
using unmonitored_key = UnmonitoredKey; |
| 101 |
using not_monitoring = NotMonitoring; |
| 102 |
} // namespace Lowercase |
| 103 |
|
| 104 |
} // namespace Error |
| 105 |
} // namespace LRU |
| 106 |
|
| 107 |
#endif // LRU_INTERNAL_ERRORS_HPP |