#include <ObjectResource.h>

Public Member Functions | |
| ArrayResource (const typename Resource< T, ObjectArray< T > >::Args &args) | |
| ArrayResource (int size, bool noThrow=false) | |
| ArrayResource (T *pObject, const typename Resource< T, ObjectArray< T > >::Args &args) | |
| ArrayResource (T *pObject, int size, bool noThrow=false) | |
| ArrayResource (const Resource< T, ObjectArray< T > > &source) | |
| int | size () const |
| T & | at (int index) const |
This is a Resource class that wraps an array of objects on the local heap. It is in effect a Resource<T,MemoryObject> except that the ObjectArray SourceTrait uses the [] versions of new and delete. It also supports a range checking indexing method called 'at' that functions similarly to the method of the same name on std::vector and std::deque. Since it uses new[], it will use the default constructor to make the objects of type T. The primary reasons for using an ArrayResource in place of a std::vector is for the different ownership semantics, and that a copy is not made when ownership is transfered. An ArrayResource can be returned from a method without making a copy of the contained data.
{
ArrayResource<double> pArray(12); // allocate an array of 12 doubles
for (int i=0; i<12; ++i)
pArray = cos(3.141592654/12.0 * i);
} // delete [] called on pArray here
Definition at line 487 of file ObjectResource.h.
| ArrayResource< T >::ArrayResource | ( | const typename Resource< T, ObjectArray< T > >::Args & | args | ) | [explicit] |
Constructs the Resource object based on a newly allocated heap array.
Essentially, this allocates and wraps an array in the Resource and assigns the Resource object the responsibility for freeing the array.
| args | The arguments that would have been provided to the obtainResource method of the ObjectArray class. |
Definition at line 499 of file ObjectResource.h.
| ArrayResource< T >::ArrayResource | ( | int | size, | |
| bool | noThrow = false | |||
| ) | [explicit] |
Constructs the Resource object based on a newly allocated heap array.
Essentially, this allocates and wraps an array in the Resource and assigns the Resource object the responsibility for freeing the array.
| size | The number of objects in the array. | |
| noThrow | The behavior for a failed allocation. True to return NULL from get(), false to throw std::bad_alloc from this constructor. |
Definition at line 516 of file ObjectResource.h.
| ArrayResource< T >::ArrayResource | ( | T * | pObject, | |
| const typename Resource< T, ObjectArray< T > >::Args & | args | |||
| ) |
Constructs the Resource object based on an existing heap array.
Essentially, this wraps the array in the Resource and assigns the Resource object the responsibility for freeing the array.
| pObject | The array to wrap in the Resource. | |
| args | The arguments that would have been provided to the obtainResource method of the ObjectArray class. |
Definition at line 532 of file ObjectResource.h.
| ArrayResource< T >::ArrayResource | ( | T * | pObject, | |
| int | size, | |||
| bool | noThrow = false | |||
| ) |
Constructs the Resource object based on an existing heap array.
Essentially, this wraps the array in the Resource and assigns the Resource object the responsibility for freeing the array.
| pObject | The array to wrap in the Resource. | |
| size | The number of objects in the array. | |
| noThrow | The behavior for a failed allocation. True to return NULL from get(), false to throw std::bad_alloc from this constructor. |
Definition at line 551 of file ObjectResource.h.
| ArrayResource< T >::ArrayResource | ( | const Resource< T, ObjectArray< T > > & | source | ) |
Definition at line 556 of file ObjectResource.h.
| int ArrayResource< T >::size | ( | ) | const |
Returns the number of objects contained in the underlying array.
Definition at line 566 of file ObjectResource.h.
| T& ArrayResource< T >::at | ( | int | index | ) | const |
Returns a reference to the indexed object.
Indexes into the underlying array and returns a reference to the indexed object. If the index is out of bounds, based on the Args object, it will throw an exception.
| index | The index of the object in the underlying array. |
Definition at line 584 of file ObjectResource.h.