31#include <casacore/casa/aips.h>
32#include <casacore/casa/Utilities/Assert.h>
33#include <casacore/casa/Utilities/Copy.h>
34#include <casacore/casa/Utilities/DataType.h>
35#include <casacore/casa/Containers/Allocator.h>
41#if defined(AIPS_ARRAY_INDEX_CHECK)
42#include <casacore/casa/Exceptions/Error.h>
57 static void doTraceFree(
const void *addr,
size_t nelem, DataType
type,
size_t sz);
70 static constexpr int value =
static_cast<int>(std::is_fundamental<T>::value);
77 static constexpr int value =
static_cast<int>(std::is_pointer<T>::value);
152 template <
typename Allocator>
172 template <
typename Allocator>
190 template <
typename Allocator>
214 template <
typename Allocator>
240 array(storagePointer),
249 template <
typename Allocator>
254 array(storagePointer),
280 other.capacity_p = 0;
282 other.array =
nullptr;
283 other.destroyPointer =
false;
289 if (&other !=
this) {
303 if (
this == &other) {
313 other.capacity_p = 0;
315 other.array =
nullptr;
316 other.destroyPointer =
false;
348 resize(n, forceSmaller, copyElements,
368 size_t nmin = std::min(
get_size(), n);
410 remove(whichOne, forceSmaller,
415#if defined(AIPS_ARRAY_INDEX_CHECK)
418 "index out of range"));
424 if (forceSmaller ==
True) {
437 objcopy(tp,
array, whichOne);
444 objcopy(tp + whichOne,
array + whichOne + 1,
get_size() - whichOne - 1);
484 template <
typename Allocator>
496 array = storagePointer;
511#if defined(AIPS_ARRAY_INDEX_CHECK)
516 "Block::operator[] - "
517 "index out of range"));
523#if defined(AIPS_ARRAY_INDEX_CHECK)
525 throw(indexError<uInt>(index,
526 "Block::operator[] const - "
527 "index out of range"));
541 void set(
const T &val) { *
this = val; }
611 inline void traceFree(
const void *addr,
size_t sz)
const {
654 template <
typename Allocator>
655 static typename Allocator_private::BulkAllocator<typename Allocator::value_type> *
660 template <
typename Allocator>
700using PtrBlock [[deprecated(
701 "Use Block<T> or std::vector<T>: the original motivation for this class no longer holds")]] =
705extern template class Block<Bool>;
706extern template class Block<Char>;
707extern template class Block<Short>;
708extern template class Block<uShort>;
709extern template class Block<Int>;
710extern template class Block<uInt>;
711extern template class Block<Int64>;
712extern template class Block<Float>;
713extern template class Block<Double>;
714extern template class Block<Complex>;
715extern template class Block<DComplex>;
716extern template class Block<String>;
717extern template class Block<void *>;
#define AlwaysAssert(expr, exception)
These marcos are provided for use instead of simply using the assert_ function directly.
static BulkAllocator< typename Allocator::value_type > * get_allocator()
static void doTraceAlloc(const void *addr, size_t nelem, DataType type, size_t sz)
Write alloc and free trace messages.
static size_t itsTraceSize
static void setTraceSize(size_t sz)
Set the trace size.
static void doTraceFree(const void *addr, size_t nelem, DataType type, size_t sz)
static constexpr int value
static constexpr int value
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 ...
void remove(size_t whichOne, Bool forceSmaller=True)
Remove a single element from the Block.
Block< T > & operator=(const Block< T > &other)
Assign other to this.
Block(size_t n, T *&storagePointer, Bool takeOverStorage, AllocSpec< Allocator > const &)
Create a Block from a C-array (i.e.
Block< T > & operator=(Block< T > &&other) noexcept
void resize(size_t n, Bool forceSmaller=False, Bool copyElements=True)
Resizes the Block.
void remove(size_t whichOne, Bool forceSmaller, ArrayInitPolicy initPolicy)
Block(AllocSpec< Allocator > const &)
Create a zero-length Block.
void resize(size_t n, Bool forceSmaller, Bool copyElements, ArrayInitPolicy initPolicy)
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 ...
Block(size_t n, ArrayInitPolicy initPolicy)
Create a Block with the given number of points.
Block(Block< T > &&other) noexcept
Block()
Create a zero-length Block.
Block(size_t n, AllocSpec< Allocator > const &)
Create a Block with the given number of points.
Block(size_t n)
Create a Block with the given number of points.
Block(size_t n, T *&storagePointer, Bool takeOverStorage=True)
Create a Block from a C-array (i.e.
~Block() noexcept
Frees up the storage pointed contained in the Block.
Block(const Block< T > &other)
Copy the other block into this one.
Block(size_t n, ArrayInitPolicy initPolicy, AllocSpec< Allocator > const &)
Create a Block with the given number of points.
An aligned allocator with the default alignment.
An allocator behaves like operator new[]/delete[].
Index errors returning the bad index.
For temporary backward namespace compatibility, use casa as alias for casacore.
size_t nelements() const
The number of elements contained in this Block<T>.
static Allocator_private::BulkAllocator< typename Allocator::value_type > * get_allocator()
void traceAlloc(const void *addr, size_t sz) const
Allocator_private::BulkAllocator< T > * allocator_p
The allocator.
T value_type
Define the STL-style iterators.
size_t capacity() const
The capacity in this Block<T>.
size_t capacity_p
The capacity of the vector.
T * array
The actual storage.
const value_type * const_pointer
T * storage()
If you really, really, need a "raw" pointer to the beginning of the storage area this will give it to...
ptrdiff_t difference_type
Bool empty() const
Is the block empty (i.e.
iterator begin()
Get the begin and end iterator object for this block.
Bool isCompatibleAllocator()
static constexpr bool init_anyway()
void set_capacity(size_t new_value)
Set the capacity of the vector.
Bool destroyPointer
Can we delete the storage upon destruction?
size_t used_p
The number of used elements in the vector.
void init()
Other internal helper function(s).
const value_type & const_reference
size_t get_size() const
The number of used elements in the vector.
void traceFree(const void *addr, size_t sz) const
bool Bool
Define the standard types used by Casacore.
void replaceStorage(size_t n, T *&storagePointer, Bool takeOverStorage=True)
Replace the internal storage with a C-array (i.e.
NewDelAllocator< T > NewDelAllocator< T >::value
void set_size(size_t new_value)
Set the number of used elements in the vector.
size_t get_capacity() const
The capacity of the vector.
T & operator[](size_t index)
Index into the block (0-based).
Block< T > & operator=(const T &val)
Set all values in the block to "val".
static constexpr ArrayInitPolicy NO_INIT
Don't initialize elements in the array.
static constexpr ArrayInitPolicy INIT
Initialize all elements in the array with the default value.