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 DataType
type,
size_t sz);
59 DataType
type,
size_t sz);
64template<
typename T>
class Block;
69 template<
typename U>
friend class Block;
70 static constexpr int value =
static_cast<int>(std::is_fundamental<T>::value);
75 template<
typename U>
friend class Block;
76 static constexpr int value =
static_cast<int>(std::is_pointer<T>::value);
151 template<
typename Allocator>
168 template<
typename Allocator>
186 template<
typename Allocator>
211 template<
typename Allocator>
245 template<
typename Allocator>
246 Block(
size_t n, T *&storagePointer,
Bool takeOverStorage,
273 other.capacity_p = 0;
275 other.array =
nullptr;
276 other.destroyPointer =
false;
282 if (&other !=
this) {
297 if (
this == &other) {
307 other.capacity_p = 0;
309 other.array =
nullptr;
310 other.destroyPointer =
false;
344 resize(n, forceSmaller, copyElements,
365 size_t nmin = std::min(
get_size(), n);
407 remove(whichOne, forceSmaller,
412#if defined(AIPS_ARRAY_INDEX_CHECK)
414 "index out of range"));
420 if (forceSmaller ==
True) {
433 objcopy(tp,
array, whichOne);
440 objcopy(tp + whichOne,
array + whichOne + 1,
get_size() - whichOne - 1);
481 template<
typename Allocator>
492 array = storagePointer;
507#if defined(AIPS_ARRAY_INDEX_CHECK)
512 "index out of range"));
518#if defined(AIPS_ARRAY_INDEX_CHECK)
520 throw(indexError<uInt>(index,
"Block::operator[] const - "
521 "index out of range"));
532 void set(
const T &val) { *
this = val; }
607 inline void traceFree (
const void* addr,
size_t sz)
const
652 template<
typename Allocator>
653 static typename Allocator_private::BulkAllocator<
659 template<
typename Allocator>
662 typename Allocator::type::value_type> *other_allocator =
700using PtrBlock [[deprecated(
"Use Block<T> or std::vector<T>: the original motivation for this class no longer holds")]]
704extern template class Block<Bool>;
705extern template class Block<Char>;
706extern template class Block<Short>;
707extern template class Block<uShort>;
708extern template class Block<Int>;
709extern template class Block<uInt>;
710extern template class Block<Int64>;
711extern template class Block<Float>;
712extern template class Block<Double>;
713extern template class Block<Complex>;
714extern template class Block<DComplex>;
715extern template class Block<String>;
716extern 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.
this file contains all the compiler specific defines
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.