ContainerExceptions.hpp
Go to the documentation of this file.
1 // @formatter:off
2 //
3 // Balau core C++ library
4 //
5 // Copyright (C) 2008 Bora Software (contact@borasoftware.com)
6 //
7 // Licensed under the Boost Software License - Version 1.0 - August 17th, 2003.
8 // See the LICENSE file for the full license text.
9 //
10 
16 
17 #ifndef COM_BORA_SOFTWARE__BALAU_EXCEPTION__CONTAINER_EXCEPTIONS
18 #define COM_BORA_SOFTWARE__BALAU_EXCEPTION__CONTAINER_EXCEPTIONS
19 
21 
22 namespace Balau::Exception {
23 
28  public: const size_t index;
29 
30  public: IndexOutOfRangeException(const char * file, int line, const std::string & st, size_t index_)
31  : BalauException(file, line, st, "IndexOutOfRange", ::toString(index_))
32  , index(index_) {}
33 
34  public: IndexOutOfRangeException(const char * file, int line, const std::string & st, const std::string & text, size_t index_)
35  : BalauException(file, line, st, "IndexOutOfRange", text + " - " + ::toString(index_))
36  , index(index_) {}
37 };
38 
39 inline bool operator == (const IndexOutOfRangeException & lhs, const IndexOutOfRangeException & rhs) {
40  return lhs.message == rhs.message && lhs.index == rhs.index;
41 }
42 
47  public: EmptyException(const char * file, int line, const std::string & st, const std::string & text)
48  : BalauException(file, line, st, "Empty", text) {}
49 };
50 
54 class SizeException : public BalauException {
55  public: SizeException(const char * file, int line, const std::string & st, const std::string & text)
56  : BalauException(file, line, st, "Size", text) {}
57 };
58 
62 template <typename T> class ItemExistsException : public BalauException {
63  public: const T item;
64 
65  public: ItemExistsException(const char * file, int line, const std::string & st, T item_, const std::string & text)
66  : BalauException(file, line, st, "ItemExists", text)
67  , item(item_) {}
68 };
69 
73 template <typename T> class ItemDoesNotExistException : public BalauException {
74  public: const T item;
75 
76  public: ItemDoesNotExistException(const char * file, int line, const std::string & st, T item_, const std::string & text)
77  : BalauException(file, line, st, "ItemDoesNotExist", text)
78  , item(item_) {}
79 };
80 
84 template <typename T, typename U> class RelationshipDoesNotExistException : public BalauException {
85  public: const T item1;
86  public: const U item2;
87 
88  public: RelationshipDoesNotExistException(const char * file, int line, const std::string & st, T item1_, U item2_, const std::string & text)
89  : BalauException(file, line, st, "RelationshipDoesNotExist", text)
90  , item1(item1_)
91  , item2(item2_) {}
92 };
93 
94 } // namespace Balau::Exception
95 
96 #endif // COM_BORA_SOFTWARE__BALAU_EXCEPTION__CONTAINER_EXCEPTIONS
bool operator==(const BalauException &lhs, const BalauException &rhs)
Base class comparison function for Balau exceptions.
Definition: BalauException.hpp:112
All exception classes.
Definition: BalauException.hpp:50
Thrown when a non-existent relationship between two items is requested.
Definition: ContainerExceptions.hpp:84
Thrown when an attempt is made to add an existing item to a container.
Definition: ContainerExceptions.hpp:62
Balau::U8String< AllocatorT > toString(const BalauException &e)
Base class toString<AllocatorT> function for Balau exceptions.
Definition: BalauException.hpp:122
Thrown when a request is made for an element but no elements are available.
Definition: ContainerExceptions.hpp:46
Thrown when an invalid size is supplied or detected.
Definition: ContainerExceptions.hpp:54
Thrown when an attempt is made to remove a non-existing item in a container.
Definition: ContainerExceptions.hpp:73
const std::string message
The message.
Definition: BalauException.hpp:59
Thrown when a specified index is not in the valid range.
Definition: ContainerExceptions.hpp:27
Base Balau exception classes.
Base class of all Balau exceptions.
Definition: BalauException.hpp:55