Skip to content

Commit b05ba0c

Browse files
adopted reviewer suggestion on bool arg for grow and resize
1 parent 3ff116d commit b05ba0c

File tree

5 files changed

+15
-14
lines changed

5 files changed

+15
-14
lines changed

Diff for: src/buildblock/ProjDataInMemory.cxx

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ ProjDataInMemory::ProjDataInMemory(shared_ptr<const ExamInfo> const& exam_info_s
7373
void
7474
ProjDataInMemory::create_buffer(const bool initialise_with_0)
7575
{
76-
this->buffer.set_initialise_with_zeros(initialise_with_0);
77-
this->buffer.grow(0, this->size_all() - 1);
76+
// this->buffer.set_initialise_with_zeros(initialise_with_0);
77+
this->buffer.grow(0, this->size_all() - 1, initialise_with_0);
7878
}
7979

8080
///////////////// /set functions

Diff for: src/include/stir/Array.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -451,13 +451,13 @@ class Array<1, elemT> : public NumericVectorWithOffset<elemT, elemT>
451451
inline virtual void grow(const IndexRange<1>& range);
452452

453453
// Array::grow initialises new elements to 0
454-
inline void grow(const int min_index, const int max_index) override;
454+
inline virtual void grow(const int min_index, const int max_index, bool initialise_with_0 = true);
455455

456456
//! Array::resize initialises new elements to 0
457457
inline virtual void resize(const IndexRange<1>& range);
458458

459459
// Array::resize initialises new elements to 0
460-
inline void resize(const int min_index, const int max_index) override;
460+
inline virtual void resize(const int min_index, const int max_index, bool initialise_with_0 = true);
461461

462462
//! \name access to the data via a pointer
463463
//@{

Diff for: src/include/stir/Array.inl

+6-5
Original file line numberDiff line numberDiff line change
@@ -576,15 +576,16 @@ Array<1, elemT>::init(const IndexRange<1>& range, elemT* const data_ptr, bool co
576576

577577
template <class elemT>
578578
void
579-
Array<1, elemT>::resize(const int min_index, const int max_index)
579+
Array<1, elemT>::resize(const int min_index, const int max_index, bool initialise_with_0)
580580
{
581581
this->check_state();
582582
const int oldstart = this->get_min_index();
583583
const size_type oldlength = this->size();
584584

585-
base_type::resize(min_index, max_index);
585+
base_type::resize(min_index, max_index, initialise_with_0);
586586

587-
if (!get_initialise_with_zeros())
587+
// if (!get_initialise_with_zeros())
588+
if (!initialise_with_0)
588589
{
589590
this->check_state();
590591
return;
@@ -614,9 +615,9 @@ Array<1, elemT>::resize(const IndexRange<1>& range)
614615

615616
template <class elemT>
616617
void
617-
Array<1, elemT>::grow(const int min_index, const int max_index)
618+
Array<1, elemT>::grow(const int min_index, const int max_index, bool initialise_with_0)
618619
{
619-
resize(min_index, max_index);
620+
resize(min_index, max_index, initialise_with_0);
620621
}
621622

622623
template <class elemT>

Diff for: src/include/stir/VectorWithOffset.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class VectorWithOffset
194194
resize() in a derived class, it is probably safest to overload
195195
grow() as well.
196196
*/
197-
inline virtual void grow(const int min_index, const int max_index);
197+
inline virtual void grow(const int min_index, const int max_index, bool initialise_with_0 = true);
198198

199199
//! grow the range of the vector from 0 to new_size-1, new elements are set to \c T()
200200
inline void grow(const unsigned int new_size);
@@ -207,7 +207,7 @@ class VectorWithOffset
207207
\todo in principle reallocation could be avoided when the new range would fit in the
208208
old one by shifting.
209209
*/
210-
inline virtual void resize(const int min_index, const int max_index);
210+
inline virtual void resize(const int min_index, const int max_index, bool initialise_with_0 = true);
211211

212212
//! change the range of the vector from 0 to new_size-1, new elements are set to \c T()
213213
inline void resize(const unsigned int new_size);

Diff for: src/include/stir/VectorWithOffset.inl

+3-3
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ VectorWithOffset<T>::reserve(const unsigned int new_size)
416416
// the new members will be initialised with the default constructor for T
417417
template <class T>
418418
void
419-
VectorWithOffset<T>::resize(const int min_index, const int max_index)
419+
VectorWithOffset<T>::resize(const int min_index, const int max_index, bool initialise_with_0)
420420
{
421421
this->check_state();
422422
if (min_index > max_index)
@@ -482,11 +482,11 @@ VectorWithOffset<T>::resize(const unsigned new_size)
482482
// the new members will be initialised with the default constructor for T
483483
template <class T>
484484
void
485-
VectorWithOffset<T>::grow(const int min_index, const int max_index)
485+
VectorWithOffset<T>::grow(const int min_index, const int max_index, bool initialise_with_0)
486486
{
487487
// allow grow arbitrary when it's zero length
488488
assert(length == 0 || (min_index <= this->get_min_index() && max_index >= this->get_max_index()));
489-
this->resize(min_index, max_index);
489+
this->resize(min_index, max_index, initialise_with_0);
490490
}
491491

492492
template <class T>

0 commit comments

Comments
 (0)