Storage container that stores a vector of unique pointers of T, but represents most of the public facing accessors (iterators, operator[]) as a vector of T. More...
#include <UniqueStorage.h>
Classes | |
struct | DereferenceIterator |
Iterator that adds an additional dereference to BaseIterator. More... | |
Public Types | |
using | values_type = typename std::vector< std::unique_ptr< T > > |
using | iterator = DereferenceIterator< typename values_type::iterator > |
using | const_iterator = DereferenceIterator< typename values_type::const_iterator > |
Public Member Functions | |
UniqueStorage ()=default | |
UniqueStorage (UniqueStorage &&)=default | |
UniqueStorage (const UniqueStorage &mp)=delete | |
UniqueStorage & | operator= (const UniqueStorage &)=delete |
std::size_t | size () const |
bool | empty () const |
bool | hasValue (const std::size_t i) const |
iterator | begin () |
Begin and end iterators to the underlying data. More... | |
iterator | end () |
const_iterator | begin () const |
const_iterator | end () const |
const T & | operator[] (const std::size_t i) const |
T & | operator[] (const std::size_t i) |
const T * | queryValue (const std::size_t i) const |
T * | queryValue (const std::size_t i) |
Protected Member Functions | |
void | setPointer (const std::size_t i, std::unique_ptr< T > &&ptr) |
Sets the underlying unique_ptr at index i to ptr . More... | |
T & | addPointer (std::unique_ptr< T > &&ptr) |
Adds the given object in ptr to the storage. More... | |
void | resize (const std::size_t size) |
Resizes the underlying vector. More... | |
void | clear () |
Clears the underlying vector. More... | |
Private Member Functions | |
const std::unique_ptr< T > & | pointerValue (const std::size_t i) const |
Returns a read-only reference to the underlying unique pointer at index i . More... | |
std::unique_ptr< T > & | pointerValue (const std::size_t i) |
Returns a reference to the underlying unique pointer at index i . More... | |
Private Attributes | |
values_type | _values |
The underlying data. More... | |
Friends | |
void | storeHelper (std::ostream &stream, UniqueStorage< T > &, void *) |
UniqueStorage helper routine. More... | |
void | loadHelper (std::istream &stream, UniqueStorage< T > &, void *) |
UniqueStorage helper routine. More... | |
Storage container that stores a vector of unique pointers of T, but represents most of the public facing accessors (iterators, operator[]) as a vector of T.
That is, these accessors dereference the underlying storage. More importantly, if data is not properly initialized using setValue(), this dereferencing will either lead to an assertion or a nullptr dereference.
Definition at line 18 of file UniqueStorage.h.
using UniqueStorage< T >::const_iterator = DereferenceIterator<typename values_type::const_iterator> |
Definition at line 72 of file UniqueStorage.h.
using UniqueStorage< T >::iterator = DereferenceIterator<typename values_type::iterator> |
Definition at line 71 of file UniqueStorage.h.
using UniqueStorage< T >::values_type = typename std::vector<std::unique_ptr<T> > |
Definition at line 70 of file UniqueStorage.h.
|
default |
|
default |
|
delete |
|
inlineprotected |
Adds the given object in ptr
to the storage.
Definition at line 153 of file UniqueStorage.h.
Referenced by RestartableDataMap::Data::addPointer().
|
inline |
Begin and end iterators to the underlying data.
Note that dereferencing these iterators may lead to an assertion or the dereference of a nullptr whether or not the underlying data is initialized.
Definition at line 82 of file UniqueStorage.h.
Referenced by RestartableDataMap::begin(), and RestartableDataMap::findData().
|
inline |
Definition at line 84 of file UniqueStorage.h.
|
inlineprotected |
|
inline |
Definition at line 116 of file UniqueStorage.h.
Referenced by RestartableDataMap::empty().
|
inline |
Definition at line 83 of file UniqueStorage.h.
Referenced by RestartableDataMap::end(), and RestartableDataMap::findData().
|
inline |
Definition at line 85 of file UniqueStorage.h.
|
inline |
is
initialized Definition at line 121 of file UniqueStorage.h.
Referenced by MaterialPropertyStorage::shallowSwapData(), MaterialPropertyStorage::shallowSwapDataBack(), and storeHelper().
|
delete |
|
inline |
i
.Note that the underlying data may not necessarily be initialized, in which case this will throw an assertion or dereference a nullptr.
You can check whether or not the underlying data is initialized with hasValue(i).
Definition at line 98 of file UniqueStorage.h.
|
inline |
Definition at line 103 of file UniqueStorage.h.
|
inlineprivate |
Returns a read-only reference to the underlying unique pointer at index i
.
Definition at line 174 of file UniqueStorage.h.
Referenced by UniqueStorage< RestartableDataValue >::hasValue(), loadHelper(), and storeHelper().
|
inlineprivate |
Returns a reference to the underlying unique pointer at index i
.
Definition at line 183 of file UniqueStorage.h.
|
inline |
i
The pointer will be nullptr if !hasValue(i), that is, if the unique_ptr at index i
is not initialized
Definition at line 130 of file UniqueStorage.h.
Referenced by MaterialData::haveGenericProperty().
|
inline |
Definition at line 131 of file UniqueStorage.h.
|
inlineprotected |
Resizes the underlying vector.
Definition at line 162 of file UniqueStorage.h.
Referenced by loadHelper(), and MaterialProperties::resize().
|
inlineprotected |
Sets the underlying unique_ptr at index i
to ptr
.
This can be used to construct objects in the storage, i.e., setPointer(0, std::make_unique<T>(...));
Definition at line 144 of file UniqueStorage.h.
Referenced by MaterialProperties::setPointer().
|
inline |
Note that this is not necessarily the size of constructed objects, as underlying objects could be uninitialized
Definition at line 112 of file UniqueStorage.h.
Referenced by RestartableDataMap::addData(), dataLoad(), dataStore(), RestartableDataMap::findData(), UniqueStorage< RestartableDataValue >::pointerValue(), UniqueStorage< RestartableDataValue >::resize(), UniqueStorage< RestartableDataValue >::setPointer(), MaterialPropertyStorage::shallowSwapData(), MaterialPropertyStorage::shallowSwapDataBack(), RestartableDataMap::size(), and storeHelper().
|
friend |
UniqueStorage helper routine.
UniqueStorage Helper Function.
The unique_ptr<T> loader is called to load the data. That is, you will likely need a specialization of unique_ptr<T> that will appropriately construct and then fill the piece of data.
Definition at line 1063 of file DataIO.h.
|
friend |
UniqueStorage helper routine.
The data within the UniqueStorage object cannot be null. The helper for unique_ptr<T> is called to store the data.
Definition at line 970 of file DataIO.h.
|
private |
The underlying data.
Definition at line 192 of file UniqueStorage.h.
Referenced by UniqueStorage< RestartableDataValue >::addPointer(), UniqueStorage< RestartableDataValue >::begin(), UniqueStorage< RestartableDataValue >::clear(), UniqueStorage< RestartableDataValue >::empty(), UniqueStorage< RestartableDataValue >::end(), UniqueStorage< RestartableDataValue >::pointerValue(), UniqueStorage< RestartableDataValue >::resize(), UniqueStorage< RestartableDataValue >::setPointer(), and UniqueStorage< RestartableDataValue >::size().