casacore
Loading...
Searching...
No Matches
Block.h
Go to the documentation of this file.
1// # Block.h: Simple templated array classes
2// # Copyright (C) 1993-1997,2000,2002,2005,2015
3// # Associated Universities, Inc. Washington DC, USA.
4// # National Astronomical Observatory of Japan
5// # 2-21-1, Osawa, Mitaka, Tokyo, 181-8588, Japan.
6// #
7// # This library is free software; you can redistribute it and/or modify it
8// # under the terms of the GNU Library General Public License as published by
9// # the Free Software Foundation; either version 2 of the License, or (at your
10// # option) any later version.
11// #
12// # This library is distributed in the hope that it will be useful, but WITHOUT
13// # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14// # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
15// # License for more details.
16// #
17// # You should have received a copy of the GNU Library General Public License
18// # along with this library; if not, write to the Free Software Foundation,
19// # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
20// #
21// # Correspondence concerning AIPS++ should be addressed as follows:
22// # Internet email: casa-feedback@nrao.edu.
23// # Postal address: AIPS++ Project Office
24// # National Radio Astronomy Observatory
25// # 520 Edgemont Road
26// # Charlottesville, VA 22903-2475 USA
27
28#ifndef CASA_BLOCK_H
29#define CASA_BLOCK_H
30
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>
36#include <cstddef> // for ptrdiff_t
37#include <algorithm> // for std:min/max
38#include <type_traits>
39
40// # For index checking
41#if defined(AIPS_ARRAY_INDEX_CHECK)
42#include <casacore/casa/Exceptions/Error.h>
43#endif
44
45namespace casacore { // # NAMESPACE CASACORE - BEGIN
46
48 public:
49 // Set the trace size. The (de)allocation of Blocks with >= sz elements
50 // will be traced using the MemoryTrace class.
51 // A value 0 means no tracing.
52 static void setTraceSize(size_t sz);
53
54 protected:
55 // Write alloc and free trace messages.
56 static void doTraceAlloc(const void *addr, size_t nelem, DataType type, size_t sz);
57 static void doTraceFree(const void *addr, size_t nelem, DataType type, size_t sz);
58
59 protected:
60 static size_t itsTraceSize;
61};
62
63template <typename T>
64class Block;
65
66template <typename T>
68 template <typename U>
69 friend class Block;
70 static constexpr int value = static_cast<int>(std::is_fundamental<T>::value);
71};
72
73template <typename T>
75 template <typename U>
76 friend class Block;
77 static constexpr int value = static_cast<int>(std::is_pointer<T>::value);
78};
79
80// <summary>simple 1-D array</summary>
81// <use visibility=export>
82//
83// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
84// </reviewed>
85//
86// <etymology>
87// This should be viewed as a <em>block</em> of memory without sophisticated
88// manipulation functions. Thus it is called <src>Block</src>.
89// </etymology>
90//
91// <synopsis>
92// <src>Block<T></src> is a simple templated 1-D array class. Indices are always
93// 0-based. For efficiency reasons, no index checking is done unless the
94// preprocessor symbol <src>AIPS_ARRAY_INDEX_CHECK</src> is defined.
95// <src>Block<T></src>'s may be assigned to and constructed from other
96// <src>Block<T></src>'s.
97// As no reference counting is done this can be an expensive operation, however.
98//
99// The net effect of this class is meant to be unsurprising to users who think
100// of arrays as first class objects. The name "Block" is intended to convey
101// the concept of a solid "chunk" of things without any intervening "fancy"
102// memory management, etc. This class was written to be
103// used in the implementations of more functional Vector, Matrix, etc. classes,
104// although it is expected <src>Block<T></src> will be useful on its own.
105//
106// The Block class should be efficient. You should normally use <src>Block</src>.
107//
108// <note role=warning> If you use the assignment operator on an element of this
109// class, you may leave dangling references to pointers released from
110// <src>storage()</src>.
111// Resizing the array will also have this effect if the underlying storage
112// is actually affected.
113// </note>
114//
115// If index checking is turned on, an out-of-bounds index will
116// generate an <src>indexError<uInt></src> exception.
117// </synopsis>
118//
119// <example>
120// <srcblock>
121// Block<Int> a(100,0); // 100 ints initialized to 0
122// Block<Int> b; // 0-length Block
123// // ...
124// b = a; // resize b and copy a into it
125// for (size_t i=0; i < a.nelements(); i++) {
126// a[i] = i; // Generate a sequence
127// // with Vectors, could simply say "indgen(myVector);"
128// }
129// b.set(-1); // All positions in b have the value -1
130// b.resize(b.nelements()*2); // Make b twice as long, by default the old
131// // elements are copied over, although this can
132// // be defeated.
133// some_c_function(b.storage()); // Use a fn that takes an
134// // <src>Int *</src> pointer
135// </srcblock>
136// </example>
137//
138template <class T>
139class Block : public BlockTrace {
140 public:
141 // Create a zero-length Block. Note that any index into this Block
142 // is an error.
143 // DefaultAllocator<T> is used as an allocator.
146 capacity_p(0),
147 used_p(0),
148 array(0),
150 // Create a zero-length Block. Note that any index into this Block
151 // is an error.
152 template <typename Allocator>
153 explicit Block(AllocSpec<Allocator> const &)
154 : allocator_p(get_allocator<typename Allocator::type>()),
155 capacity_p(0),
156 used_p(0),
157 array(0),
159
160 // Create a Block with the given number of points. The values in Block
161 // are initialized. Note that indices range between 0 and n-1.
162 // DefaultAllocator<T> is used as an allocator.
169
170 // Create a Block with the given number of points. The values in Block
171 // are initialized. Note that indices range between 0 and n-1.
172 template <typename Allocator>
177
178 // Create a Block with the given number of points. The values in Block
179 // are uninitialized. Note that indices range between 0 and n-1.
180 // DefaultAllocator<T> is used as an allocator.
181 Block(size_t n, ArrayInitPolicy initPolicy)
183 used_p(n),
185 init(initPolicy);
186 }
187
188 // Create a Block with the given number of points.
189 // Note that indices range between 0 and n-1.
190 template <typename Allocator>
191 Block(size_t n, ArrayInitPolicy initPolicy, AllocSpec<Allocator> const &)
192 : allocator_p(get_allocator<typename Allocator::type>()), used_p(n), destroyPointer(True) {
193 init(initPolicy);
194 }
195
196 // Create a Block of the given length, and initialize (via copy constructor for
197 // objects of type T) with the provided value.
198 // DefaultAllocator<T> is used as an allocator.
199 Block(size_t n, T const &val)
201 used_p(n),
204 try {
205 allocator_p->construct(array, get_size(), val);
206 } catch (...) {
207 dealloc();
208 throw;
209 }
210 }
211
212 // Create a Block of the given length, and initialize (via copy constructor for
213 // objects of type T) with the provided value.
214 template <typename Allocator>
215 Block(size_t n, T const &val, AllocSpec<Allocator> const &)
216 : allocator_p(get_allocator<typename Allocator::type>()), used_p(n), destroyPointer(True) {
218 try {
219 allocator_p->construct(array, get_size(), val);
220 } catch (...) {
221 dealloc();
222 throw;
223 }
224 }
225
226 // Create a <src>Block</src> from a C-array (i.e. pointer). If
227 // <src>takeOverStorage</src> is <src>True</src>, The Block assumes that
228 // it owns the pointer, i.e. that it is safe to release it via <src>allocator</src> when
229 // the Block is destructed, otherwise the actual storage is not destroyed.
230 // If true, <src>storagePointer</src> is set to <src>0</src>.
231 // It is strongly recommended to supply an appropriate <src>allocator</src> argument explicitly
232 // whenever <src>takeOverStorage</src> == True
233 // to let <src>Block</src> to know how to release the <src>storagePointer</src>.
234 // The default allocator set by this constructor will be changed from
235 // <src>NewDelAllocator<T>::value</src> to <src>DefaultAllocator<T>::value</src> in future.
236 Block(size_t n, T *&storagePointer, Bool takeOverStorage = True)
238 capacity_p(n),
239 used_p(n),
240 array(storagePointer),
241 destroyPointer(takeOverStorage) {
242 if (destroyPointer) storagePointer = 0;
243 }
244 // Create a <src>Block</src> from a C-array (i.e. pointer). If
245 // <src>takeOverStorage</src> is <src>True</src>, The Block assumes that
246 // it owns the pointer, i.e. that it is safe to release it via <src>allocator</src> when
247 // the Block is destructed, otherwise the actual storage is not destroyed.
248 // If true, <src>storagePointer</src> is set to <src>0</src>.
249 template <typename Allocator>
250 Block(size_t n, T *&storagePointer, Bool takeOverStorage, AllocSpec<Allocator> const &)
251 : allocator_p(get_allocator<typename Allocator::type>()),
252 capacity_p(n),
253 used_p(n),
254 array(storagePointer),
255 destroyPointer(takeOverStorage) {
256 if (destroyPointer) storagePointer = 0;
257 }
258
259 // Copy the other block into this one. Uses copy, not reference, semantics.
260 Block(const Block<T> &other)
263
264 try {
265 objthrowcp1(array, other.array, get_size());
266 allocator_p->construct(array, get_size(), other.array);
267 } catch (...) {
268 dealloc();
269 throw;
270 }
271 }
272
273 Block(Block<T> &&other) noexcept
274 : allocator_p(other.allocator_p),
275 capacity_p(other.capacity_p),
276 used_p(other.used_p),
277 array(other.array),
278 destroyPointer(other.destroyPointer) {
279 // The allocator of other is left as is; the storage is emptied so no need to change it.
280 other.capacity_p = 0;
281 other.used_p = 0;
282 other.array = nullptr;
283 other.destroyPointer = false;
284 }
285
286 // Assign other to this. this resizes itself to the size of other, so after
287 // the assignment, this->nelements() == other.nelements() always.
288 Block<T> &operator=(const Block<T> &other) {
289 if (&other != this) {
290 T *old = array;
291 this->resize(other.size(), True, False, ArrayInitPolicies::NO_INIT);
292 if (array == old) {
293 objcopy(array, other.array, get_size());
294 } else {
295 objthrowcp1(array, other.array, get_size());
296 allocator_p->construct(array, get_size(), other.array);
297 }
298 }
299 return *this;
300 }
301
302 Block<T> &operator=(Block<T> &&other) noexcept {
303 if (this == &other) {
304 return *this;
305 }
306 deinit();
307 allocator_p = other.allocator_p;
308 capacity_p = other.capacity_p;
309 used_p = other.used_p;
310 destroyPointer = other.destroyPointer;
311 array = other.array;
312 // The allocator of other is left as is; the storage is emptied so no need to change it.
313 other.capacity_p = 0;
314 other.used_p = 0;
315 other.array = nullptr;
316 other.destroyPointer = false;
317 return *this;
318 }
319
320 // Frees up the storage pointed contained in the Block.
321 ~Block() noexcept { deinit(); }
322
323 // Resizes the Block. If <src>n == nelements()</src> resize just returns. If
324 // a larger size is requested (<src>n > nelements()</src>) the Block always
325 // resizes. If the requested size is smaller (<src>n < nelements()</src>),
326 // by default the Block does not resize smaller, although it can be
327 // forced to with <src>forceSmaller</src>. The reasoning behind this is that
328 // often the user will just want a buffer of at least a certain size,
329 // and won't want to pay the cost of multiple resizings.
330 // <srcblock>
331 // Block<float> bf(100, 0.0);
332 // bf.resize(10); // bf.nelements() == 100
333 // bf.resize(10, True) // bf.nelements() == 10
334 // bf.resize(200) // bf.nelements() == 200
335 // </srcblock>
336 // Normally the old elements are copied over (although if the
337 // Block is lengthened the trailing elements will have undefined
338 // values), however this can be turned off by setting copyElements to
339 // False.
340 //
341 // This is written as three functions because default parameters do
342 // not always work properly with templates.
343 //
344 // <src>initPolicy</src> makes sense to determine whether extended elements
345 // should be initialized or not when you enlarge Block.
346 // <group>
347 void resize(size_t n, Bool forceSmaller = False, Bool copyElements = True) {
348 resize(n, forceSmaller, copyElements,
350 }
351 void resize(size_t n, Bool forceSmaller, Bool copyElements, ArrayInitPolicy initPolicy) {
352 if (n == get_size()) {
353 return;
354 }
355 if (n < get_size() && forceSmaller == False) {
356 return;
357 }
358 if (get_size() < n && n <= get_capacity()) {
359 allocator_p->construct(&array[get_size()], n - get_size());
360 set_size(n);
361 return;
362 }
363 T *tp = n > 0 ? allocator_p->allocate(n) : 0;
364 traceAlloc(tp, n);
365 if (n > 0) {
366 size_t start = 0;
367 if (copyElements) {
368 size_t nmin = std::min(get_size(), n); // Don't copy too much!
369 if (nmin > 0) {
370 try {
371 allocator_p->construct(tp, nmin, array);
372 } catch (...) {
373 traceFree(tp, n);
374 allocator_p->deallocate(tp, n);
375 throw;
376 }
377 }
378 start = nmin;
379 }
380 if (initPolicy == ArrayInitPolicies::INIT) {
381 try {
382 allocator_p->construct(&tp[start], n - start);
383 } catch (...) {
384 allocator_p->destroy(tp, start);
385 traceFree(tp, n);
386 allocator_p->deallocate(tp, n);
387 throw;
388 }
389 }
390 }
391 deinit();
393 array = tp; // ... and update pointer
394 set_capacity(n);
395 set_size(n);
396 }
397 // </group>
398
399 // Remove a single element from the Block. If forceSmaller is True this
400 // will resize the Block and hence involve new memory allocations. This is
401 // relatively expensive so setting forceSmaller to False is preferred. When
402 // forceSmaller is False the Block is not resized but the elements with an
403 // index above the removed element are shuffled down by one. For backward
404 // compatibility forceSmaller is True by default.
405 //
406 // <src>initPolicy</src> makes sense to determine whether new storage
407 // should be initialized or not before copying when <src>forceSmaller</src> is True.
408 // <group>
409 void remove(size_t whichOne, Bool forceSmaller = True) {
410 remove(whichOne, forceSmaller,
412 }
413 void remove(size_t whichOne, Bool forceSmaller, ArrayInitPolicy initPolicy) {
414 if (whichOne >= get_size()) {
415#if defined(AIPS_ARRAY_INDEX_CHECK)
416 throw(indexError<uInt>(whichOne,
417 "Block::remove() - "
418 "index out of range"));
419#else
420 return;
421#endif
422 }
423 size_t n = get_size() - 1;
424 if (forceSmaller == True) {
425 T *tp = n > 0 ? allocator_p->allocate(n) : 0;
426 traceAlloc(array, n);
427 if (initPolicy == ArrayInitPolicies::INIT && n > 0) {
428 try {
429 allocator_p->construct(tp, n);
430 } catch (...) {
431 traceFree(tp, n);
432 allocator_p->deallocate(tp, n);
433 throw;
434 }
435 }
436 try {
437 objcopy(tp, array, whichOne);
438 } catch (...) {
439 traceFree(tp, n);
440 allocator_p->deallocate(tp, n);
441 throw;
442 }
443 try {
444 objcopy(tp + whichOne, array + whichOne + 1, get_size() - whichOne - 1);
445 } catch (...) {
446 allocator_p->destroy(tp, whichOne);
447 traceFree(tp, n);
448 allocator_p->deallocate(tp, n);
449 throw;
450 }
451 if (array && destroyPointer) {
453 allocator_p->destroy(array, get_size());
454 allocator_p->deallocate(array, get_capacity());
455 array = 0;
456 };
457 set_capacity(n);
458 set_size(n);
459 array = tp;
461 } else {
462 objmove(&array[whichOne], &array[whichOne + 1], get_size() - whichOne - 1);
463 }
464 }
465 // </group>
466
467 // </group>
468
469 // Replace the internal storage with a C-array (i.e. pointer).
470 // If <src>takeOverStorage</src> is True, The Block assumes that it
471 // owns the pointer, i.e. that it is safe to release it via <src>allocator</src> when the
472 // <src>Block</src>is destructed, otherwise the actual storage is not destroyed.
473 // If true, storagePointer is set to <src>NULL</src>.
474 // It is strongly recommended to supply an appropriate <src>allocator</src> argument explicitly
475 // whenever <src>takeOverStorage</src> == True
476 // to let <src>Block</src> to know how to release the <src>storagePointer</src>.
477 // The default parameter of allocator will be changed from <src>AllocSpec<NewDelAllocator<T>
478 // >::value</src> to <src>AllocSpec<DefaultAllocator<T> >::value</src> in future. AipsError is
479 // thrown if allocator is incompatible with the current allocator of the instance and changing
480 // allocator is prohibited, even if takeOverStorage == False. <group>
481 void replaceStorage(size_t n, T *&storagePointer, Bool takeOverStorage = True) {
482 replaceStorage(n, storagePointer, takeOverStorage, AllocSpec<NewDelAllocator<T>>::value);
483 }
484 template <typename Allocator>
485 void replaceStorage(size_t n, T *&storagePointer, Bool takeOverStorage,
486 AllocSpec<Allocator> const &) {
487 if (array && destroyPointer) {
489 allocator_p->destroy(array, get_size());
490 allocator_p->deallocate(array, get_capacity());
491 array = 0;
492 };
493 set_capacity(n);
494 set_size(n);
496 array = storagePointer;
497 destroyPointer = takeOverStorage;
498 if (destroyPointer) storagePointer = 0;
499 }
500 // </group>
501
502 // Index into the block (0-based). If the preprocessor symbol
503 // <src>AIPS_ARRAY_INDEX_CHECK</src> is defined, index checking will be done
504 // and an out-of-bounds index will cause an <src>indexError<uInt></src> to be
505 // thrown. Note that valid indices range between 0 and <src>nelements()-1</src>.
506 // <thrown>
507 // <li> indexError
508 // </thrown>
509 // <group>
510 T &operator[](size_t index) {
511#if defined(AIPS_ARRAY_INDEX_CHECK)
512 // Write it this way to avoid casts; remember index and get_size() are
513 // unsigned.
514 if ((get_size() == 0) || (index > get_size() - 1)) {
515 throw(indexError<uInt>(index,
516 "Block::operator[] - "
517 "index out of range"));
518 };
519#endif
520 return array[index];
521 }
522 const T &operator[](size_t index) const {
523#if defined(AIPS_ARRAY_INDEX_CHECK)
524 if ((get_size() == 0) || (index > get_size() - 1)) {
525 throw(indexError<uInt>(index,
526 "Block::operator[] const - "
527 "index out of range"));
528 };
529#endif
530 return array[index];
531 }
532 // </group>
533
534 // Set all values in the block to "val".
535 // <group>
536 Block<T> &operator=(const T &val) {
537 T tmp = val;
538 objset(array, tmp, get_size());
539 return *this;
540 }
541 void set(const T &val) { *this = val; }
542 // </group>
543
544 // If you really, really, need a "raw" pointer to the beginning of the
545 // storage area this will give it to you. This may leave dangling pointers
546 // if the block is destructed or if the assignment operator or resize
547 // is used. Returns a null pointer if <src>nelements() == 0</src>.
548 // It is best to only use this if you completely control the extent and
549 // lifetime of the <src>Block</src>.
550 // <h3> Examples of misuse </h3> <srcblock>
551 // Block<Int> *bp = new Block<Int>(100);
552 // Int *ip = bp->storage();
553 // DefaultAllocator<Int>::value.deallocate(bp, bp->capacity()); // Oops, ip is now dangling
554 // Block<Int> a(100),b(100);
555 // Int *ip = a.storage();
556 // a = b; // Likewise
557 // </srcblock>
558 // <group>
559 T *storage() { return array; }
560 const T *storage() const { return array; }
561 // </group>
562
563 // The number of elements contained in this <src>Block<T></src>.
564 // <group>
565 size_t nelements() const { return size(); }
566 size_t size() const { return get_capacity(); }
567 // </group>
568
569 // The capacity in this <src>Block<T></src>.
570 // <src>size() <= capacity()</src> is always true.
571 size_t capacity() const { return get_capacity(); }
572
573 // Is the block empty (i.e. no elements)?
574 Bool empty() const { return size() == 0; }
575
576 // Define the STL-style iterators.
577 // It makes it possible to iterate through all data elements.
578 // <srcblock>
579 // Block<Int> bl(100,0);
580 // for (Block<Int>::iterator iter=bl.begin(); iter!=bl.end(); iter++) {
581 // *iter += 1;
582 // }
583 // </srcblock>
584 // <group name=STL-iterator>
585 // STL-style typedefs.
586 // <group>
587 typedef T value_type;
588 typedef T *iterator;
589 typedef const T *const_iterator;
591 typedef const value_type *const_pointer;
594 typedef size_t size_type;
595 typedef ptrdiff_t difference_type;
596 // </group>
597 // Get the begin and end iterator object for this block.
598 // <group>
599 iterator begin() { return array; }
600 const_iterator begin() const { return array; }
601 iterator end() { return array + size(); }
602 const_iterator end() const { return array + size(); }
603 // </group>
604 // </group>
605
606 inline void traceAlloc(const void *addr, size_t sz) const {
607 if (itsTraceSize > 0 && sz >= itsTraceSize) {
608 doTraceAlloc(addr, sz, whatType<T>(), sizeof(T));
609 }
610 }
611 inline void traceFree(const void *addr, size_t sz) const {
612 if (itsTraceSize > 0 && sz >= itsTraceSize) {
613 doTraceFree(addr, sz, whatType<T>(), sizeof(T));
614 }
615 }
616
617 private:
621
622 void init(ArrayInitPolicy initPolicy) {
624 if (get_capacity() > 0) {
625 array = allocator_p->allocate(get_capacity());
627 if (initPolicy == ArrayInitPolicies::INIT) {
628 try {
629 allocator_p->construct(array, get_size());
630 } catch (...) {
631 dealloc();
632 throw;
633 }
634 }
635 } else {
636 array = 0;
637 }
638 }
639
640 void deinit() {
641 if (array && destroyPointer) {
642 allocator_p->destroy(array, get_size());
643 dealloc();
644 }
645 }
646 void dealloc() {
647 if (array && destroyPointer) {
649 allocator_p->deallocate(array, get_capacity());
650 array = 0;
651 }
652 }
653
654 template <typename Allocator>
655 static typename Allocator_private::BulkAllocator<typename Allocator::value_type> *
659
660 template <typename Allocator>
666
667 // The number of used elements in the vector
668 size_t get_size() const { return used_p; }
669 // Set the number of used elements in the vector
670 void set_size(size_t new_value) {
671 AlwaysAssert(new_value <= get_capacity(), AipsError);
672 used_p = new_value;
673 }
674 // The capacity of the vector
675 size_t get_capacity() const { return capacity_p; }
676 // Set the capacity of the vector
677 void set_capacity(size_t new_value) {
678 capacity_p = new_value;
679 set_size(std::min(get_size(), capacity_p));
680 }
681
682 // The allocator
684 // The capacity of the vector
686 // The number of used elements in the vector
687 size_t used_p;
688 // The actual storage
690 // Can we delete the storage upon destruction?
692};
693
699template <typename T>
700using PtrBlock [[deprecated(
701 "Use Block<T> or std::vector<T>: the original motivation for this class no longer holds")]] =
702 Block<T>;
703
704// # Instantiate extern templates for often used types.
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 *>;
718
719} // namespace casacore
720
721#endif
#define AlwaysAssert(expr, exception)
These marcos are provided for use instead of simply using the assert_ function directly.
Definition Assert.h:133
static BulkAllocator< typename Allocator::value_type > * get_allocator()
Definition Allocator.h:283
static void doTraceAlloc(const void *addr, size_t nelem, DataType type, size_t sz)
Write alloc and free trace messages.
static size_t itsTraceSize
Definition Block.h:60
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
Definition Block.h:70
static constexpr int value
Definition Block.h:77
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 ...
Definition Block.h:199
void remove(size_t whichOne, Bool forceSmaller=True)
Remove a single element from the Block.
Definition Block.h:409
Block< T > & operator=(const Block< T > &other)
Assign other to this.
Definition Block.h:288
Block(size_t n, T *&storagePointer, Bool takeOverStorage, AllocSpec< Allocator > const &)
Create a Block from a C-array (i.e.
Definition Block.h:250
Block< T > & operator=(Block< T > &&other) noexcept
Definition Block.h:302
void resize(size_t n, Bool forceSmaller=False, Bool copyElements=True)
Resizes the Block.
Definition Block.h:347
void remove(size_t whichOne, Bool forceSmaller, ArrayInitPolicy initPolicy)
Definition Block.h:413
Block(AllocSpec< Allocator > const &)
Create a zero-length Block.
Definition Block.h:153
void resize(size_t n, Bool forceSmaller, Bool copyElements, ArrayInitPolicy initPolicy)
Definition Block.h:351
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 ...
Definition Block.h:215
Block(size_t n, ArrayInitPolicy initPolicy)
Create a Block with the given number of points.
Definition Block.h:181
Block(Block< T > &&other) noexcept
Definition Block.h:273
Block()
Create a zero-length Block.
Definition Block.h:144
Block(size_t n, AllocSpec< Allocator > const &)
Create a Block with the given number of points.
Definition Block.h:173
Block(size_t n)
Create a Block with the given number of points.
Definition Block.h:163
Block(size_t n, T *&storagePointer, Bool takeOverStorage=True)
Create a Block from a C-array (i.e.
Definition Block.h:236
~Block() noexcept
Frees up the storage pointed contained in the Block.
Definition Block.h:321
Block(const Block< T > &other)
Copy the other block into this one.
Definition Block.h:260
Block(size_t n, ArrayInitPolicy initPolicy, AllocSpec< Allocator > const &)
Create a Block with the given number of points.
Definition Block.h:191
An aligned allocator with the default alignment.
Definition Allocator.h:378
An allocator behaves like operator new[]/delete[].
Definition Allocator.h:350
Index errors returning the bad index.
Definition Error.h:336
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
const T * const_iterator
Definition Block.h:589
size_t nelements() const
The number of elements contained in this Block<T>.
Definition Block.h:565
const Bool False
Definition aipstype.h:42
static Allocator_private::BulkAllocator< typename Allocator::value_type > * get_allocator()
Definition Block.h:656
void traceAlloc(const void *addr, size_t sz) const
Definition Block.h:606
Allocator_private::BulkAllocator< T > * allocator_p
The allocator.
Definition Block.h:683
T value_type
Define the STL-style iterators.
Definition Block.h:587
size_t capacity() const
The capacity in this Block<T>.
Definition Block.h:571
void deinit()
Definition Block.h:640
size_t capacity_p
The capacity of the vector.
Definition Block.h:685
void set(const T &val)
Definition Block.h:541
T * array
The actual storage.
Definition Block.h:689
const value_type * const_pointer
Definition Block.h:591
T * storage()
If you really, really, need a "raw" pointer to the beginning of the storage area this will give it to...
Definition Block.h:559
ptrdiff_t difference_type
Definition Block.h:595
size_t size_type
Definition Block.h:594
Bool empty() const
Is the block empty (i.e.
Definition Block.h:574
void dealloc()
Definition Block.h:646
iterator begin()
Get the begin and end iterator object for this block.
Definition Block.h:599
Bool isCompatibleAllocator()
Definition Block.h:661
static constexpr bool init_anyway()
Definition Block.h:618
T * iterator
Definition Block.h:588
void set_capacity(size_t new_value)
Set the capacity of the vector.
Definition Block.h:677
Bool destroyPointer
Can we delete the storage upon destruction?
Definition Block.h:691
size_t used_p
The number of used elements in the vector.
Definition Block.h:687
void init()
Other internal helper function(s).
const value_type & const_reference
Definition Block.h:593
size_t get_size() const
The number of used elements in the vector.
Definition Block.h:668
value_type * pointer
Definition Block.h:590
void traceFree(const void *addr, size_t sz) const
Definition Block.h:611
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
size_t size() const
Definition Block.h:566
value_type & reference
Definition Block.h:592
void replaceStorage(size_t n, T *&storagePointer, Bool takeOverStorage=True)
Replace the internal storage with a C-array (i.e.
Definition Block.h:481
const Bool True
Definition aipstype.h:41
NewDelAllocator< T > NewDelAllocator< T >::value
Definition Allocator.h:360
void set_size(size_t new_value)
Set the number of used elements in the vector.
Definition Block.h:670
size_t get_capacity() const
The capacity of the vector.
Definition Block.h:675
iterator end()
Definition Block.h:601
T & operator[](size_t index)
Index into the block (0-based).
Definition Block.h:510
Block< T > & operator=(const T &val)
Set all values in the block to "val".
Definition Block.h:536
Allocator specifier.
Definition Allocator.h:395
static constexpr ArrayInitPolicy NO_INIT
Don't initialize elements in the array.
Definition Allocator.h:68
static constexpr ArrayInitPolicy INIT
Initialize all elements in the array with the default value.
Definition Allocator.h:70