Loading...
Searching...
No Matches
casacore::Block< T > Class Template Reference
casa package (libcasa_casa) » Containers_module

More...

`#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

## Detailed Description

template<class T>
class casacore::Block< T >

forward declarations:

simple 1-D array

### Intended use:

Public interface

### Review Status

Reviewed By:
  UNKNOWN
Date Reviewed:
  before2004/08/25

### Etymology

This should be viewed as a block of memory without sophisticated manipulation functions. Thus it is called Block.

### Synopsis

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.

### Example

Block<Int> a(100,0); // 100 ints initialized to 0
Block<Int> b; // 0-length Block
//..\.
b = a; // resize b and copy a into it
for (size_t i=0; i < a.nelements(); i++) {
a[i] = i; // Generate a sequence
// with Vectors, could simply say "indgen(myVector);"
}
b.set(-1); // All positions in b have the value -1
b.resize(b.nelements()*2); // Make b twice as long, by default the old
// elements are copied over, although this can
// be defeated.
some_c_function(b.storage()); // Use a fn that takes an
// <tt>Int *</tt> pointer
casacore::Block::resize
void resize(size_t n, Bool forceSmaller=False, Bool copyElements=True)
Resizes the Block.
Definition Block.h:343
casacore::Block::Block
Block()
Create a zero-length Block.
Definition Block.h:145

Definition at line 139 of file Block.h.

## Constructor & Destructor Documentation

## Block() [1/12]

template<class T>

casacore::Block< T >::Block | ( |  | ) |

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=().

## Block() [2/12]

template<class T>
template<typename Allocator>

casacore::Block< T >::Block | ( | AllocSpec< Allocator > const & |  | ) |

inline explicit

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.

## Block() [3/12]

template<class T>

casacore::Block< T >::Block | ( | size_t | n | ) |

inline explicit

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.

## Block() [4/12]

template<class T>
template<typename Allocator>

casacore::Block< T >::Block | ( | size_t | n,
|  | AllocSpec< Allocator > const & | )

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.

## Block() [5/12]

template<class T>

casacore::Block< T >::Block | ( | size_t | n,
|  | ArrayInitPolicy | initPolicy )

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.

## Block() [6/12]

template<class T>
template<typename Allocator>

casacore::Block< T >::Block | ( | size_t | n,
|  | ArrayInitPolicy | initPolicy,
|  | AllocSpec< Allocator > const & | )

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.

## Block() [7/12]

template<class T>

casacore::Block< T >::Block | ( | size_t | n,
|  | T const & | val )

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.

## Block() [8/12]

template<class T>
template<typename Allocator>

casacore::Block< T >::Block | ( | size_t | n,
|  | T const & | val,
|  | AllocSpec< Allocator > const & | )

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.

## Block() [9/12]

template<class T>

casacore::Block< T >::Block | ( | size_t | n,
|  | T *& | storagePointer,
|  | Bool | takeOverStorage = True )

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.

## Block() [10/12]

template<class T>
template<typename Allocator>

casacore::Block< T >::Block | ( | size_t | n,
|  | T *& | storagePointer,
|  | Bool | takeOverStorage,
|  | AllocSpec< Allocator > const & | )

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.

## Block() [11/12]

template<class T>

casacore::Block< T >::Block | ( | const Block< T > & | other | ) |

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.

## Block() [12/12]

template<class T>

casacore::Block< T >::Block | ( | Block< T > && | other | ) |

inline noexcept

The allocator of other is left as is; the storage is emptied so no need to change it.

Definition at line 269 of file Block.h.

References Block().

## ~Block()

template<class T>

casacore::Block< T >::~Block | ( |  | ) |

inline noexcept

Frees up the storage pointed contained in the Block.

Definition at line 315 of file Block.h.

References casacore::deinit().

## Member Function Documentation

## operator=() [1/2]

template<class T>

Block< T > & casacore::Block< T >::operator= | ( | Block< T > && | other | ) |

inline noexcept

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.

## operator=() [2/2]

template<class T>

Block< T > & casacore::Block< T >::operator= | ( | const Block< T > & | other | ) |

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.

## remove() [1/2]

template<class T>

void casacore::Block< T >::remove | ( | size_t | whichOne,
|  | Bool | forceSmaller,
|  | ArrayInitPolicy | initPolicy )

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.

## remove() [2/2]

template<class T>

void casacore::Block< T >::remove | ( | size_t | whichOne,
|  | Bool | forceSmaller = 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().

## resize() [1/2]

template<class T>

void casacore::Block< T >::resize | ( | size_t | n,
|  | Bool | forceSmaller,
|  | Bool | copyElements,
|  | ArrayInitPolicy | initPolicy )

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.

## resize() [2/2]

template<class T>

void casacore::Block< T >::resize | ( | size_t | n,
|  | Bool | forceSmaller = False,
|  | Bool | copyElements = 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.

Block<float> bf(100, 0.0);
bf.resize(10); // bf.nelements() == 100
bf.resize(10, True) // bf.nelements() == 10
bf.resize(200) // bf.nelements() == 200
casacore::True
const Bool True
Definition aipstype.h:41

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().

The documentation for this class was generated from the following files:

- casa/Containers/Allocator.h
- casa/Containers/Block.h