33 #include <casacore/casa/aips.h>
34 #include <casacore/casa/Utilities/Assert.h>
35 #include <casacore/casa/Utilities/Copy.h>
36 #include <casacore/casa/Utilities/DataType.h>
37 #include <casacore/casa/Containers/Allocator.h>
40 #include <type_traits>
43 #if defined(AIPS_ARRAY_INDEX_CHECK)
44 #include <casacore/casa/Exceptions/Error.h>
117 DataType type,
size_t sz);
119 DataType type,
size_t sz);
124 template<
typename T>
class Block;
129 template<
typename U>
friend class Block;
135 template<
typename U>
friend class Block;
211 template<
typename Allocator>
228 template<
typename Allocator>
246 template<
typename Allocator>
271 template<
typename Allocator>
306 template<
typename Allocator>
307 Block(
size_t n, T *&storagePointer,
Bool takeOverStorage,
335 if (&other !=
this) {
378 resize(n, forceSmaller, copyElements,
445 remove(whichOne, forceSmaller,
450 #if defined(AIPS_ARRAY_INDEX_CHECK)
452 "index out of range"));
458 if (forceSmaller ==
True) {
471 objcopy(tp,
array, whichOne);
478 objcopy(tp + whichOne,
array + whichOne + 1,
get_size() - whichOne - 1);
532 template<
typename Allocator>
535 throw AipsError(
"Block::replaceStorage - Attemption to change allocator of Block");
546 allocator_p = get_allocator<typename Allocator::type>();
547 array = storagePointer;
562 #if defined(AIPS_ARRAY_INDEX_CHECK)
567 "index out of range"));
573 #if defined(AIPS_ARRAY_INDEX_CHECK)
576 "index out of range"));
587 void set(
const T &val) { *
this = val; }
659 doTraceAlloc (addr, sz, whatType(
static_cast<T*
>(0)),
sizeof(T));
662 inline void traceFree (
const void* addr,
size_t sz)
const
665 doTraceFree (addr, sz, whatType(
static_cast<T*
>(0)),
sizeof(T));
670 friend class Array<T>;
683 Block(
size_t n, T *&storagePointer,
Bool takeOverStorage,
695 T
const &initial_value) {
747 template<
typename Allocator>
754 template<
typename Allocator>
757 typename Allocator::type::value_type> *other_allocator =
758 Allocator_private::get_allocator<typename Allocator::type>();
820 :
block_p(n, (void **&)storagePointer, takeOverStorage) {}
#define AlwaysAssert(expr, exception)
These marcos are provided for use instead of simply using the constructors of assert_ to allow additi...
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 ...
size_t capacity_p
The capacity of the vector.
Block< T > & operator=(const Block< T > &other)
Assign other to this.
Bool empty() const
Is the block empty (i.e.
T * array
The actual storage.
void remove(size_t whichOne, Bool forceSmaller=True)
Remove a single element from the Block.
size_t used_p
The number of used elements in the vector.
void replaceStorage(size_t n, T *&storagePointer, Bool takeOverStorage, AllocSpec< Allocator > const &)
Allocator_private::BulkAllocator< T > * allocator_p
The allocator.
static bool init_anyway()
const_iterator begin() const
static Allocator_private::BulkAllocator< typename Allocator::value_type > * get_allocator()
Allocator_private::BulkAllocator< T > * get_allocator()
Block(size_t n, T *&storagePointer, Bool takeOverStorage, AllocSpec< Allocator > const &)
Create a Block from a C-array (i.e.
void construct(size_t pos, size_type n)
void traceFree(const void *addr, size_t sz) const
Bool destroyPointer
Can we delete the storage upon destruction?
Bool isCompatibleAllocator()
void resize(size_t n, Bool forceSmaller=False, Bool copyElements=True)
Resizes the Block.
iterator begin()
Get the begin and end iterator object for this block.
void prohibitChangingAllocator()
Prohibit changing allocator for this instance.
void permitChangingAllocator()
Permit changing allocator for this instance.
void remove(size_t whichOne, Bool forceSmaller, ArrayInitPolicy initPolicy)
void init(ArrayInitPolicy initPolicy)
end of friend
Block(size_t n, T *&storagePointer, Bool takeOverStorage, Allocator_private::BulkAllocator< T > *allocator)
Block(AllocSpec< Allocator > const &)
Create a zero-length Block.
const value_type * const_pointer
const value_type & const_reference
const T & operator[](size_t index) const
T & operator[](size_t index)
Index into the block (0-based).
T value_type
Define the STL-style iterators.
void replaceStorage(size_t n, T *&storagePointer, Bool takeOverStorage=True)
Replace the internal storage with a C-array (i.e.
void resize(size_t n, Bool forceSmaller, Bool copyElements, ArrayInitPolicy initPolicy)
Block(size_t n, ArrayInitPolicy initPolicy, Allocator_private::BulkAllocator< T > *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 ...
Block(size_t n, ArrayInitPolicy initPolicy)
Create a Block with the given number of points.
size_t nelements() const
The number of elements contained in this Block<T>.
Block(size_t n, Allocator_private::AllocSpec< T > allocator)
~Block()
Frees up the storage pointed contained in the Block.
void traceAlloc(const void *addr, size_t sz) const
size_t capacity() const
The capacity in this Block<T>.
Block()
Create a zero-length Block.
size_t get_size() const
The number of used elements in the vector.
const_iterator end() const
void set_size(size_t new_value)
Set the number of used elements in the vector.
void destroy(size_t pos, size_type n)
Block(size_t n, AllocSpec< Allocator > const &)
Create a Block with the given number of points.
void construct(size_t pos, size_t n, T const &initial_value)
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.
T * storage()
If you really, really, need a "raw" pointer to the beginning of the storage area this will give it to...
void set_capacity(size_t new_value)
Set the capacity of the vector.
Block< T > & operator=(const T &val)
Set all values in the block to "val".
ptrdiff_t difference_type
Bool keep_allocator_p
Can we change allocator or not?
void construct(size_t pos, size_t n, T const *src)
size_t get_capacity() const
The capacity of the vector.
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.
const T * storage() const
An aligned allocator with the default alignment.
An allocator behaves like operator new[]/delete[].
A drop-in replacement for Block<T*>.
PtrBlock< T > & operator=(const T &val)
const T * storage() const
PtrBlock(const PtrBlock< T > &other)
PtrBlock(size_t n, T val)
T & operator[](size_t index)
const T & operator[](size_t index) const
PtrBlock< T > & operator=(const PtrBlock< T > &other)
void remove(size_t whichOne, Bool forceSmaller)
void resize(size_t n, Bool forceSmaller)
void replaceStorage(size_t n, T *&storagePointer, Bool takeOverStorage=True)
void remove(size_t whichOne)
void resize(size_t n, Bool forceSmaller, Bool copyElements)
PtrBlock(size_t n, T *&storagePointer, Bool takeOverStorage=True)
Index errors returning the bad index.
this file contains all the compiler specific defines
LatticeExprNode min(const LatticeExprNode &left, const LatticeExprNode &right)
bool Bool
Define the standard types used by Casacore.
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
virtual pointer allocate(size_type elements, const void *ptr=0)=0
virtual void deallocate(pointer ptr, size_type size)=0
virtual void construct(pointer ptr, size_type n, const_pointer src)=0
virtual void destroy(pointer ptr, size_type n)=0
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.