A collection of generic opaque pointers that can receive the buffer from outside (loan).
More...
#include <LoanableCollection.hpp>
A collection of generic opaque pointers that can receive the buffer from outside (loan).
This is an abstract class. See LoanableSequence for details.
◆ element_type
◆ size_type
◆ LoanableCollection()
◆ buffer()
Get the pointer to the elements buffer.
The returned value may be nullptr if maximum() is 0. Otherwise it is guaranteed that up to maximum() elements can be accessed.
- Returns
- the pointer to the elements buffer.
◆ has_ownership()
bool has_ownership |
( |
| ) |
const |
|
inline |
Get the ownership flag.
- Returns
- whether the collection has ownership of the buffer.
◆ length() [1/2]
Get the number of elements currently accessible.
- Returns
- the number of elements currently accessible.
◆ length() [2/2]
Set the number of elements currently accessible.
This method tells the collection that a certain number of elements should be accessible. If the new length is greater than the current maximum() the collection should allocate space for the new elements. If this is the case and the collection does not own the buffer (i.e. has_ownership() is false) then no allocation will be performed, the length will remain unchanged, and false will be returned.
- Precondition
- new_length >= 0
- Parameters
-
[in] | new_length | New number of elements to be accessible. |
- Returns
- true if the new length was correctly set.
- Postcondition
- length() == new_length
-
maximum() >= new_length
◆ loan()
Loan a buffer to the collection.
- Parameters
-
[in] | buffer | pointer to the buffer to be loaned. |
[in] | new_maximum | number of allocated elements in buffer. |
[in] | new_length | number of accessible elements in buffer. |
- Precondition
- (has_ownership() == false) || (maximum() == 0)
-
new_maximum > 0
-
new_maximum >= new_length
-
buffer != nullptr
- Returns
- false if preconditions are not met.
-
true if operation succeeds.
- Postcondition
- buffer() == buffer
-
has_ownership() == false
-
maximum() == new_maximum
-
length() == new_length
◆ maximum()
Get the maximum number of elements currently allocated.
- Returns
- the maximum number of elements currently allocated.
◆ resize()
◆ unloan() [1/2]
◆ unloan() [2/2]
Remove the loan from the collection.
- Parameters
-
[out] | maximum | number of allocated elements on the returned buffer. |
[out] | length | number of accessible elements on the returned buffer. |
- Precondition
- has_ownership() == false
- Returns
- nullptr if preconditions are not met.
-
pointer to the previously loaned buffer of elements.
- Postcondition
- buffer() == nullptr
-
has_ownership() == true
-
length() == 0
-
maximum() == 0
◆ elements_
◆ has_ownership_
bool has_ownership_ = true |
|
protected |
◆ length_
◆ maximum_
The documentation for this class was generated from the following file: