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>
115 DataType type,
size_t sz);
117 DataType type,
size_t sz);
122template<
typename T>
class Block;
127 template<
typename U>
friend class Block;
128 static constexpr int value =
static_cast<int>(std::is_fundamental<T>::value);
133 template<
typename U>
friend class Block;
134 static constexpr int value =
static_cast<int>(std::is_pointer<T>::value);
209 template<
typename Allocator>
226 template<
typename Allocator>
244 template<
typename Allocator>
269 template<
typename Allocator>
304 template<
typename Allocator>
305 Block(
size_t n, T *&storagePointer,
Bool takeOverStorage,
333 if (&other !=
this) {
376 resize(n, forceSmaller, copyElements,
401 size_t nmin = std::min(
get_size(), n);
443 remove(whichOne, forceSmaller,
448#if defined(AIPS_ARRAY_INDEX_CHECK)
450 "index out of range"));
456 if (forceSmaller ==
True) {
469 objcopy(tp,
array, whichOne);
476 objcopy(tp + whichOne,
array + whichOne + 1,
get_size() - whichOne - 1);
530 template<
typename Allocator>
533 throw AipsError(
"Block::replaceStorage - Attemption to change allocator of Block");
544 allocator_p = get_allocator<typename Allocator::type>();
545 array = storagePointer;
560#if defined(AIPS_ARRAY_INDEX_CHECK)
565 "index out of range"));
571#if defined(AIPS_ARRAY_INDEX_CHECK)
574 "index out of range"));
585 void set(
const T &val) { *
this = val; }
660 inline void traceFree (
const void* addr,
size_t sz)
const
668 friend class Array<T>;
681 Block(
size_t n, T *&storagePointer,
Bool takeOverStorage,
693 T
const &initial_value) {
745 template<
typename Allocator>
752 template<
typename Allocator>
755 typename Allocator::type::value_type> *other_allocator =
756 Allocator_private::get_allocator<typename Allocator::type>();
818 :
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
Allocator_private::BulkAllocator< T > * get_allocator()
const T & operator[](size_t index) const
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.
const T * storage() const
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
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.
void construct(size_t pos, size_type n)
void traceFree(const void *addr, size_t sz) const
T * storage()
If you really, really, need a "raw" pointer to the beginning of the storage area this will give it to...
static Allocator_private::BulkAllocator< typename Allocator::value_type > * get_allocator()
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
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.
Block< T > & operator=(const T &val)
Set all values in the block to "val".
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.
void set_capacity(size_t new_value)
Set the capacity of the vector.
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.
T & operator[](size_t index)
Index into the block (0-based).
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[].
A drop-in replacement for Block<T*>.
PtrBlock(const PtrBlock< T > &other)
PtrBlock(size_t n, T val)
PtrBlock< T > & operator=(const T &val)
void remove(size_t whichOne, Bool forceSmaller)
const T * storage() const
void resize(size_t n, Bool forceSmaller)
void replaceStorage(size_t n, T *&storagePointer, Bool takeOverStorage=True)
const T & operator[](size_t index) const
void remove(size_t whichOne)
void resize(size_t n, Bool forceSmaller, Bool copyElements)
T & operator[](size_t index)
PtrBlock< T > & operator=(const PtrBlock< T > &other)
PtrBlock(size_t n, T *&storagePointer, Bool takeOverStorage=True)
Index errors returning the bad index.
this file contains all the compiler specific defines
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.