|
casacore
|
#include <Block.h>
Public Member Functions | |
| Block () | |
| Create a zero-length Block. | |
| template<typename Allocator> | |
| Block (AllocSpec< Allocator > const &) | |
| Create a zero-length Block. | |
| Block (size_t n) | |
| Create a Block with the given number of points. | |
| template<typename Allocator> | |
| Block (size_t n, AllocSpec< Allocator > const &) | |
| Create a Block with the given number of points. | |
| Block (size_t n, ArrayInitPolicy initPolicy) | |
| Create a Block with the given number of points. | |
| template<typename Allocator> | |
| Block (size_t n, ArrayInitPolicy initPolicy, AllocSpec< Allocator > const &) | |
| Create a Block with the given number of points. | |
| Block (size_t n, T const &val) | |
| Create a Block of the given length, and initialize (via copy constructor for objects of type T) with the provided value. | |
| template<typename Allocator> | |
| Block (size_t n, T const &val, AllocSpec< Allocator > const &) | |
| Create a Block of the given length, and initialize (via copy constructor for objects of type T) with the provided value. | |
| Block (size_t n, T *&storagePointer, Bool takeOverStorage=True) | |
| Create a Block from a C-array (i.e. | |
| template<typename Allocator> | |
| Block (size_t n, T *&storagePointer, Bool takeOverStorage, AllocSpec< Allocator > const &) | |
| Create a Block from a C-array (i.e. | |
| Block (const Block< T > &other) | |
| Copy the other block into this one. | |
| Block (Block< T > &&other) noexcept | |
| Block< T > & | operator= (const Block< T > &other) |
| Assign other to this. | |
| Block< T > & | operator= (Block< T > &&other) noexcept |
| ~Block () noexcept | |
| Frees up the storage pointed contained in the Block. | |
| void | resize (size_t n, Bool forceSmaller=False, Bool copyElements=True) |
| Resizes the Block. | |
| void | resize (size_t n, Bool forceSmaller, Bool copyElements, ArrayInitPolicy initPolicy) |
| void | remove (size_t whichOne, Bool forceSmaller=True) |
| Remove a single element from the Block. | |
| void | remove (size_t whichOne, Bool forceSmaller, ArrayInitPolicy initPolicy) |
Additional Inherited Members | |
| Static Public Member Functions inherited from casacore::BlockTrace | |
| static void | setTraceSize (size_t sz) |
| Set the trace size. | |
| Static Protected Member Functions inherited from casacore::BlockTrace | |
| static void | doTraceAlloc (const void *addr, size_t nelem, DataType type, size_t sz) |
| Write alloc and free trace messages. | |
| static void | doTraceFree (const void *addr, size_t nelem, DataType type, size_t sz) |
| Static Protected Attributes inherited from casacore::BlockTrace | |
| static size_t | itsTraceSize |
forward declarations:
simple 1-D array
Public interface
This should be viewed as a block of memory without sophisticated manipulation functions. Thus it is called Block.
Block<T> is a simple templated 1-D array class. Indices are always 0-based. For efficiency reasons, no index checking is done unless the preprocessor symbol AIPS_ARRAY_INDEX_CHECK is defined. Block<T>'s may be assigned to and constructed from other Block<T>'s. As no reference counting is done this can be an expensive operation, however.
The net effect of this class is meant to be unsurprising to users who think of arrays as first class objects. The name "Block" is intended to convey the concept of a solid "chunk" of things without any intervening "fancy" memory management, etc. This class was written to be used in the implementations of more functional Vector, Matrix, etc. classes, although it is expected Block<T> will be useful on its own.
The Block class should be efficient. You should normally use Block.
Warning: If you use the assignment operator on an element of this class, you may leave dangling references to pointers released from storage(); Resizing the array will also have this effect if the underlying storage is actually affected;
If index checking is turned on, an out-of-bounds index will generate an indexError<uInt> exception.
|
inline |
Create a zero-length Block.
Note that any index into this Block is an error. DefaultAllocator<T> is used as an allocator.
Definition at line 145 of file Block.h.
References casacore::allocator_p, casacore::array, casacore::capacity_p, casacore::destroyPointer, casacore::get_allocator(), casacore::True, and casacore::used_p.
Referenced by Block(), Block(), operator=(), and operator=().
|
inlineexplicit |
Create a zero-length Block.
Note that any index into this Block is an error.
Definition at line 152 of file Block.h.
References casacore::allocator_p, casacore::array, casacore::capacity_p, casacore::destroyPointer, casacore::get_allocator(), casacore::True, and casacore::used_p.
|
inlineexplicit |
Create a Block with the given number of points.
The values in Block are initialized. Note that indices range between 0 and n-1. DefaultAllocator<T> is used as an allocator.
Definition at line 160 of file Block.h.
References casacore::allocator_p, casacore::destroyPointer, casacore::get_allocator(), casacore::ArrayInitPolicies::INIT, casacore::init(), casacore::init_anyway(), casacore::ArrayInitPolicies::NO_INIT, casacore::True, and casacore::used_p.
|
inline |
Create a Block with the given number of points.
The values in Block are initialized. Note that indices range between 0 and n-1.
Definition at line 169 of file Block.h.
References casacore::allocator_p, casacore::destroyPointer, casacore::get_allocator(), casacore::ArrayInitPolicies::INIT, casacore::init(), casacore::init_anyway(), casacore::ArrayInitPolicies::NO_INIT, casacore::True, and casacore::used_p.
|
inline |
Create a Block with the given number of points.
The values in Block are uninitialized. Note that indices range between 0 and n-1. DefaultAllocator<T> is used as an allocator.
Definition at line 178 of file Block.h.
References casacore::allocator_p, casacore::destroyPointer, casacore::get_allocator(), casacore::init(), casacore::True, and casacore::used_p.
|
inline |
Create a Block with the given number of points.
Note that indices range between 0 and n-1.
Definition at line 187 of file Block.h.
References casacore::allocator_p, casacore::destroyPointer, casacore::get_allocator(), casacore::init(), casacore::True, and casacore::used_p.
|
inline |
Create a Block of the given length, and initialize (via copy constructor for objects of type T) with the provided value.
DefaultAllocator<T> is used as an allocator.
Definition at line 197 of file Block.h.
References casacore::allocator_p, casacore::array, casacore::dealloc(), casacore::destroyPointer, casacore::get_allocator(), casacore::get_size(), casacore::init(), casacore::ArrayInitPolicies::NO_INIT, casacore::True, and casacore::used_p.
|
inline |
Create a Block of the given length, and initialize (via copy constructor for objects of type T) with the provided value.
Definition at line 212 of file Block.h.
References casacore::allocator_p, casacore::array, casacore::dealloc(), casacore::destroyPointer, casacore::get_allocator(), casacore::get_size(), casacore::init(), casacore::ArrayInitPolicies::NO_INIT, casacore::True, and casacore::used_p.
|
inline |
Create a Block from a C-array (i.e.
pointer). If takeOverStorage is True, The Block assumes that it owns the pointer, i.e. that it is safe to release it via allocator when the Block is destructed, otherwise the actual storage is not destroyed. If true, storagePointer is set to 0. It is strongly recommended to supply an appropriate allocator argument explicitly whenever takeOverStorage == True to let Block to know how to release the storagePointer. The default allocator set by this constructor will be changed from NewDelAllocator<T>::value to DefaultAllocator<T>::value in future.
Definition at line 234 of file Block.h.
References casacore::allocator_p, casacore::array, casacore::capacity_p, casacore::destroyPointer, casacore::get_allocator(), casacore::True, and casacore::used_p.
|
inline |
Create a Block from a C-array (i.e.
pointer). If takeOverStorage is True, The Block assumes that it owns the pointer, i.e. that it is safe to release it via allocator when the Block is destructed, otherwise the actual storage is not destroyed. If true, storagePointer is set to 0.
Definition at line 246 of file Block.h.
References casacore::allocator_p, casacore::array, casacore::capacity_p, casacore::destroyPointer, casacore::get_allocator(), and casacore::used_p.
|
inline |
Copy the other block into this one.
Uses copy, not reference, semantics.
Definition at line 255 of file Block.h.
References casacore::allocator_p, casacore::array, Block(), casacore::dealloc(), casacore::destroyPointer, casacore::get_size(), casacore::init(), casacore::ArrayInitPolicies::NO_INIT, casacore::size(), casacore::True, and casacore::used_p.
|
inlinenoexcept |
|
inlinenoexcept |
Frees up the storage pointed contained in the Block.
Definition at line 315 of file Block.h.
References casacore::deinit().
|
inlinenoexcept |
The allocator of other is left as is; the storage is emptied so no need to change it.
Definition at line 295 of file Block.h.
References casacore::allocator_p, casacore::array, Block(), casacore::capacity_p, casacore::deinit(), casacore::destroyPointer, and casacore::used_p.
|
inline |
Assign other to this.
this resizes itself to the size of other, so after the assignment, this->nelements() == other.nelements() always.
Definition at line 281 of file Block.h.
References casacore::allocator_p, casacore::array, Block(), casacore::False, casacore::get_size(), casacore::ArrayInitPolicies::NO_INIT, resize(), and casacore::True.
|
inline |
Definition at line 410 of file Block.h.
References casacore::allocator_p, casacore::array, casacore::destroyPointer, casacore::get_capacity(), casacore::get_size(), casacore::ArrayInitPolicies::INIT, casacore::set_capacity(), casacore::set_size(), casacore::traceAlloc(), casacore::traceFree(), and casacore::True.
|
inline |
Remove a single element from the Block.
If forceSmaller is True this will resize the Block and hence involve new memory allocations. This is relatively expensive so setting forceSmaller to False is preferred. When forceSmaller is False the Block is not resized but the elements with an index above the removed element are shuffled down by one. For backward compatibility forceSmaller is True by default.
initPolicy makes sense to determine whether new storage should be initialized or not before copying when forceSmaller is True.
Definition at line 406 of file Block.h.
References casacore::ArrayInitPolicies::INIT, casacore::init_anyway(), casacore::ArrayInitPolicies::NO_INIT, remove(), and casacore::True.
Referenced by remove().
|
inline |
Definition at line 347 of file Block.h.
References casacore::allocator_p, casacore::array, casacore::deinit(), casacore::destroyPointer, casacore::False, casacore::get_capacity(), casacore::get_size(), casacore::ArrayInitPolicies::INIT, casacore::set_capacity(), casacore::set_size(), casacore::traceAlloc(), casacore::traceFree(), and casacore::True.
|
inline |
Resizes the Block.
If n == nelements() resize just returns. If a larger size is requested (n > nelements()) the Block always resizes. If the requested size is smaller (n < nelements()), by default the Block does not resize smaller, although it can be forced to with forceSmaller. The reasoning behind this is that often the user will just want a buffer of at least a certain size, and won't want to pay the cost of multiple resizings.
Normally the old elements are copied over (although if the Block is lengthened the trailing elements will have undefined values), however this can be turned off by setting copyElements to False.
This is written as three functions because default parameters do not always work properly with templates.
initPolicy makes sense to determine whether extended elements should be initialized or not when you enlarge Block.
Definition at line 343 of file Block.h.
References casacore::False, casacore::ArrayInitPolicies::INIT, casacore::init_anyway(), casacore::ArrayInitPolicies::NO_INIT, resize(), and casacore::True.
Referenced by operator=(), and resize().