Workspace 6.21.5
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
ObjectArray Class Reference

Generic array class for holding an array of DataObject's.

#include <Workspace/DataExecution/DataObjects/objectarray.h>

Inheritance diagram for ObjectArray:
[legend]

Classes

class  const_iterator
 
class  iterator
 

Public Types

using size_type = size_t
 

Public Member Functions

 ObjectArray ()
 
 ObjectArray (const DataFactory &factoryRestriction)
 
 ObjectArray (const ObjectArray &)
 
 ObjectArray (const QStringList &stringList)
 
 ~ObjectArray () override
 
template<typename T >
T & addItem ()
 
DataObjectback ()
 
const DataObjectback () const
 
iterator begin ()
 
const_iterator begin () const
 
bool canSerialize () const override
 
size_type capacity () const
 
void clear ()
 
bool empty () const
 
iterator end ()
 
const_iterator end () const
 
void ensureHasData ()
 
void erase (size_type index)
 
DataObjectfront ()
 
const DataObjectfront () const
 
const DataFactorygetFactoryRestriction () const
 
bool hasData () const
 
bool insert (const DataObject &obj, size_type index)
 
bool isAssignable () const
 
bool load (const SerializedItem &item) override
 
ObjectArrayoperator= (const ObjectArray &)
 
DataObjectoperator[] (size_type index)
 
const DataObjectoperator[] (size_type index) const
 
void pop_back ()
 
bool push_back (const DataFactory &factory)
 
bool push_back (const DataObject &obj)
 
template<typename T >
bool push_back_copy (const T &obj)
 
template<typename T >
T & push_back_new ()
 
template<typename T >
bool push_back_ptr (T *ptr, bool takeOwnership)
 
void reserve (size_type numItems)
 
void resize (size_type newSize, const DataFactory &factory)
 
bool save (SerializedItem &item) const override
 
template<typename T >
void setFactoryRestriction ()
 
void setFactoryRestriction (const DataFactory *factory)
 
size_type size () const
 
void swap (ObjectArray &array)
 
- Public Member Functions inherited from Serialize
virtual ~Serialize ()=default
 
virtual bool canSerialize () const =0
 
virtual bool load (const SerializedItem &item)=0
 
virtual bool save (SerializedItem &item) const =0
 

Static Public Member Functions

static bool fromQVariant (const QVariant &v, ObjectArray *&data, bool deepConvert, bool &ownsData)
 
static QVariant toQVariant (const ObjectArray &data)
 

Member Typedef Documentation

◆ size_type

using size_type = size_t

Constructor & Destructor Documentation

◆ ObjectArray() [1/4]

◆ ObjectArray() [2/4]

ObjectArray ( const DataFactory factoryRestriction)

◆ ObjectArray() [3/4]

ObjectArray ( const ObjectArray array)

◆ ObjectArray() [4/4]

ObjectArray ( const QStringList stringList)

◆ ~ObjectArray()

~ObjectArray ( )
overridedefault

Member Function Documentation

◆ addItem()

T & addItem ( )
inline

Convenience template to push a new object and return a reference. Similar to ObjectDictionary.

◆ back() [1/2]

DataObject & back ( )
Returns
The last item in the array.
Precondition
The array must not be empty.

◆ back() [2/2]

const DataObject & back ( ) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ begin() [1/2]

iterator begin ( )
inline

◆ begin() [2/2]

const_iterator begin ( ) const
inline

◆ canSerialize()

bool canSerialize ( ) const
overridevirtual
Returns
Always returns true for an ObjectArray, even if the underlying data type stored in the array does not support serialization. This is because the array itself can be serialized. If the caller needs to know if the array items can be serialized, then they have to check each one for themselves.

Implements Serialize.

◆ capacity()

ObjectArray::size_type capacity ( ) const
Returns
The number of items the object array can hold before it needs to reallocate itself and therefore copy the contents to a new memory location. By definition, this will always be at least the current size of the array as returned by size().
Note
Because the array stores pointers to data objects, the objects themselves are not copied. Instead, only pointers to the objects have to be copied and this is a computationally cheap operation.
See also
reserve()

◆ clear()

void clear ( )

Clears the array. All data owned by the data objects in the array will be deleted as well. If the data object has data it does not own, that data will continue to exist after this function returns.

◆ empty()

bool empty ( ) const
Returns
True if the array is empty.

◆ end() [1/2]

iterator end ( )
inline

◆ end() [2/2]

const_iterator end ( ) const
inline

◆ ensureHasData()

void ensureHasData ( )

Ensures that all items in the array have valid data by calling each item's ensureHasData() function.

◆ erase()

void erase ( size_type  index)
Parameters
indexThe index of the item to remove from the array. It must be less than the result of size().

Erases the item at the specified index. The object at that index will be destroyed.

See also
insert(), pop_back()

◆ fromQVariant()

bool fromQVariant ( const QVariant &  v,
ObjectArray *&  data,
bool  deepConvert,
bool &  ownsData 
)
static

◆ front() [1/2]

DataObject & front ( )
Returns
The first item in the array.
Precondition
The array must not be empty.

◆ front() [2/2]

const DataObject & front ( ) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ getFactoryRestriction()

const DataFactory * getFactoryRestriction ( ) const

◆ hasData()

bool hasData ( ) const
Returns
True if all items in the array have valid data. If any data object in the array returns false for a call to its hasData() function, then this function also returns false.

◆ insert()

bool insert ( const DataObject obj,
size_type  index 
)
Parameters
objThe object to insert into the array. A clone of this object will be stored and the array takes ownership of the clone.
indexThe index of the item to insert before. It must not be greater than the result of size().
Returns
True if obj satisfies the factory restriction (if one is in place) and if obj was able to be cloned.
See also
erase(), push_back(), setFactoryRestriction()

◆ isAssignable()

bool isAssignable ( ) const

◆ load()

bool load ( const SerializedItem item)
overridevirtual
Parameters
itemSupplies the state to be loaded into this object group.

This function will load the state of this object group from item. It will usually be called by an implementation of Serialize::load.

Precondition
The immediate children of item must all have unique tag names. Data saved by the save function is guaranteed to satisfy this.

Implements Serialize.

◆ operator=()

ObjectArray & operator= ( const ObjectArray array)

◆ operator[]() [1/2]

DataObject & operator[] ( size_type  index)
Parameters
indexThe index of the object to retrieve.
Returns
The array item at index. No check is made to ensure that index is valid.

◆ operator[]() [2/2]

const DataObject & operator[] ( size_type  index) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ pop_back()

void pop_back ( )
Precondition
The array must not be empty.

This function removes the last element of the array. The data object that is at the end of the array will be destroyed.

See also
push_back(), erase()

◆ push_back() [1/2]

bool push_back ( const DataFactory factory)
Parameters
factoryThe factory to use to create a new object to be appended to the array. The object's hasData() function will usually return false because it will not normally have any underlying data created by the factory for most data types.

The main purpose of this function is to push a new item onto the end of the array which the caller will subsequently supply data to. If you want to supply an object to copy directly, use the other overload of this function.

Returns
True if factory satisfies the factory restriction if one is in place.
See also
pop_back(), setFactoryRestriction()

◆ push_back() [2/2]

bool push_back ( const DataObject obj)
Parameters
objThe object to append into the array. A clone of this object will be stored and the array takes ownership of the clone.
Returns
True if obj satisfies the factory restriction (if one is in place) and if obj was able to be cloned.
See also
pop_back(), insert(), setFactoryRestriction()

◆ push_back_copy()

bool push_back_copy ( const T &  obj)
inline

Push a new copy of an object (obj)

◆ push_back_new()

T & push_back_new ( )
inline

Convenience template to push a new object and return a reference

◆ push_back_ptr()

bool push_back_ptr ( T *  ptr,
bool  takeOwnership 
)
inline

Push a pointer to existing data (ptr)

◆ reserve()

void reserve ( size_type  numItems)
Parameters
numItemsThe number of items that the array must be able to store before a memory reallocation will be needed.

If numItems is less than the result returned from capacity(), the function has no effect. Otherwise, the memory is reallocated to increase the capacity up to the specified size.

Postcondition
The result of size() always remains unchanged. The result of capacity() will be at least numItems.
See also
capacity()

◆ resize()

void resize ( size_type  newSize,
const DataFactory factory 
)
Parameters
newSizeThe new size of the array.
factoryThe data factory to use to create new items in the array if it needs to be lengthed. If a factory restriction has been set through a call to setFactoryRestriction() or through the constructor taking a factory as a parameter, then factory must match the factory restriction exactly.

Items will be appended or deleted from the end of the array as necessary to make it have the specified size. All existing objects in the first newSize elements of the array will continue to exist unchanged, since the array stores pointers to objects and therefore does not need to copy or clone objects in order to resize the array.

◆ save()

bool save ( SerializedItem item) const
overridevirtual
Parameters
itemWhere to save the state of this array.

This function will serialise the array by saving each object it contains to item. If an item is not serializable, it will be silently skipped. At the very least, an array will always have its size included in the serialization.

Implements Serialize.

◆ setFactoryRestriction() [1/2]

void setFactoryRestriction ( )
inline

◆ setFactoryRestriction() [2/2]

void setFactoryRestriction ( const DataFactory factory)

◆ size()

ObjectArray::size_type size ( ) const
Returns
The number of objects in the array.

◆ swap()

void swap ( ObjectArray array)
Parameters
arrayThe array with which to swap contents.

Swapping the contents of two ObjectArray instances is very efficient. No actual array elements are copied. The swap is achieved by swapping the private implementation objects for both arrays, and this usually amounts to little more than assignment of three pointer values.

◆ toQVariant()

QVariant toQVariant ( const ObjectArray data)
static