40 #include <type_traits>
43 #if defined(AIPS_ARRAY_INDEX_CHECK)
116 static void doTraceAlloc (
const void* addr,
size_t nelem,
117 DataType
type,
size_t sz);
118 static void doTraceFree (
const void* addr,
size_t nelem,
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,
444 void remove(
size_t whichOne,
Bool forceSmaller =
True) {
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));
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) {}
829 void remove(
size_t whichOne,
Bool forceSmaller) {
Block(size_t n)
Create a Block with the given number of points.
static constexpr ArrayInitPolicy NO_INIT
Don't initialize elements in the array.
void prohibitChangingAllocator()
Prohibit changing allocator for this instance.
void set_capacity(size_t new_value)
Set the capacity of the vector.
Block(size_t n, T *&storagePointer, Bool takeOverStorage=True)
Create a Block from a C-array (i.e.
const T * storage() const
const T & operator[](size_t index) const
void construct(size_t pos, size_t n, T const *src)
T value_type
Define the STL-style iterators.
An aligned allocator with the default alignment.
void resize(size_t n, Bool forceSmaller=False, Bool copyElements=True)
Resizes the Block.
ptrdiff_t difference_type
size_t nelements() const
The number of elements contained in this Block<T>.
static bool init_anyway()
const T * storage() const
virtual void construct(pointer ptr, size_type n, const_pointer src)=0
virtual void destroy(pointer ptr, size_type n)=0
virtual casacore::String type() const
Implements RegionShape::type.
static constexpr int value
const value_type & const_reference
static void setTraceSize(size_t sz)
Set the trace size.
Index errors returning the bad index.
Block(size_t n, Allocator_private::AllocSpec< T > allocator)
A global enum used by some Array/Block constructors.
const T & operator[](size_t index) const
Block()
Create a zero-length Block.
void replaceStorage(size_t n, T *&storagePointer, Bool takeOverStorage=True)
Replace the internal storage with a C-array (i.e.
size_t capacity() const
The capacity in this Block<T>.
const value_type * const_pointer
PtrBlock(const PtrBlock< T > &other)
size_t used_p
The number of used elements in the vector.
T & operator[](size_t index)
Index into the block (0-based).
void traceFree(const void *addr, size_t sz) const
Block(size_t n, ArrayInitPolicy initPolicy, AllocSpec< Allocator > const &)
Create a Block with the given number of points.
void replaceStorage(size_t n, T *&storagePointer, Bool takeOverStorage, AllocSpec< Allocator > const &)
Bool keep_allocator_p
Can we change allocator or not?
PtrBlock(size_t n, T val)
Allocator_private::BulkAllocator< T > * allocator_p
The allocator.
const_iterator end() const
static void doTraceAlloc(const void *addr, size_t nelem, DataType type, size_t sz)
Write alloc and free trace messages.
Bool empty() const
Is the block empty (i.e.
Block(size_t n, ArrayInitPolicy initPolicy, Allocator_private::BulkAllocator< T > *allocator)
virtual pointer allocate(size_type elements, const void *ptr=0)=0
Block(size_t n, AllocSpec< Allocator > const &)
Create a Block with the given number of points.
T & operator[](size_t index)
void permitChangingAllocator()
Permit changing allocator for this instance.
void remove(size_t whichOne, Bool forceSmaller=True)
Remove a single element from the Block.
virtual void deallocate(pointer ptr, size_type size)=0
void replaceStorage(size_t n, T *&storagePointer, Bool takeOverStorage=True)
Block(size_t n, T *&storagePointer, Bool takeOverStorage, Allocator_private::BulkAllocator< T > *allocator)
#define AlwaysAssert(expr, exception)
These marcos are provided for use instead of simply using the constructors of assert_ to allow additi...
bool Bool
Define the standard types used by Casacore.
void set_size(size_t new_value)
Set the number of used elements in the vector.
Allocator_private::BulkAllocator< T > * get_allocator()
void resize(size_t n, Bool forceSmaller, Bool copyElements)
PtrBlock< T > & operator=(const PtrBlock< T > &other)
static constexpr int value
size_t get_capacity() const
The capacity of the vector.
static constexpr ArrayInitPolicy INIT
Initialize all elements in the array with the default value.
Bool isCompatibleAllocator()
A drop-in replacement for Block<T*>.
iterator begin()
Get the begin and end iterator object for this block.
template <class T, class U> class vector;
void construct(size_t pos, size_t n, T const &initial_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 ...
static size_t itsTraceSize
PtrBlock(size_t n, T *&storagePointer, Bool takeOverStorage=True)
Block(size_t n, ArrayInitPolicy initPolicy)
Create a Block with the given number of points.
void init(ArrayInitPolicy initPolicy)
end of friend
Base class for all Casacore library errors.
const_iterator begin() const
Block(AllocSpec< Allocator > const &)
Create a zero-length Block.
void resize(size_t n, Bool forceSmaller, Bool copyElements, ArrayInitPolicy initPolicy)
void construct(size_t pos, size_type n)
static Allocator_private::BulkAllocator< typename Allocator::value_type > * get_allocator()
Bool destroyPointer
Can we delete the storage upon destruction?
static BulkAllocator< typename Allocator::value_type > * get_allocator()
An allocator behaves like operator new[]/delete[].
String: the storage and methods of handling collections of characters.
void traceAlloc(const void *addr, size_t sz) const
size_t get_size() const
The number of used elements in the vector.
Block< T > & operator=(const T &val)
Set all values in the block to "val".
T * array
The actual storage.
T * storage()
If you really, really, need a "raw" pointer to the beginning of the storage area this will give it to...
Block(const Block< T > &other)
Copy the other block into this one.
void destroy(size_t pos, size_type n)
void resize(size_t n, Bool forceSmaller)
~Block()
Frees up the storage pointed contained in the Block.
PtrBlock< T > & operator=(const T &val)
Block< T > & operator=(const Block< T > &other)
Assign other to this.
size_t capacity_p
The capacity of the vector.
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
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 ...
static void doTraceFree(const void *addr, size_t nelem, DataType type, size_t sz)
Block(size_t n, T *&storagePointer, Bool takeOverStorage, AllocSpec< Allocator > const &)
Create a Block from a C-array (i.e.
#define casacore
<X11/Intrinsic.h> #defines true, false, casacore::Bool, and String.