Garfield++ v1r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
DynLinArr< T > Class Template Reference

#include <AbsArr.h>

+ Inheritance diagram for DynLinArr< T >:

Public Member Functions

 DynLinArr (void)
 
 DynLinArr (long fqel)
 
 DynLinArr (long fqel, const T &val)
 
 DynLinArr (long fqel, const T *ar, ArgInterp_Arr)
 
DynLinArr< T > & operator= (const DynLinArr< T > &f)
 
template<class D >
DynLinArr< T > & operator= (const DynLinArr< D > &f)
 
void pass (long fqel, T *fel)
 
 DynLinArr (const DynLinArr< T > &f)
 
 DynLinArr (PILF_CONST DynLinArr< T > &f, Pilfer)
 
 DynLinArr (const DynArr< T > &f)
 
 DynLinArr (const DynArr< T > &f, int n_of_dim, long roc_number)
 
DynLinArrassignAll (const T &f)
 
template<class X >
DynLinArr< T > & assignAll1 (const X &f)
 
T & operator[] (long n)
 
const T & operator[] (long n) const
 
T & acu (long n)
 
const T & acu (long n) const
 
T & last_el (void)
 
const T & last_el (void) const
 
long get_qel (void) const
 
void put_qel (long fqel)
 
void put_qel (long fqel, const T *val, ArgInterp_SingleAdr t)
 
void put_qel (long fqel, const T &val)
 
void increment (const T *val=NULL)
 
void increment (const T &val)
 
void clear (void)
 
void pilfer (PILF_CONST DynLinArr< T > &f)
 
void check (void) const
 
DynArr< T > top (void)
 
void sort (long q_to_sort=0)
 
void sort (DynLinArr< long > &sort_ind, long q_to_sort=0) const
 
void sort_select_increasing (DynLinArr< long > &sort_ind, long q_to_sort=0) const
 
void sort_select_decreasing (DynLinArr< long > &sort_ind, long q_to_sort=0) const
 
 macro_copy_header (DynLinArr)
 
virtual ~DynLinArr ()
 

Friends

template<class P >
void apply1 (DynLinArr< P > &ar, void(*fun)(P &f))
 
template<class P , class X >
void apply2 (DynLinArr< P > &ar, void(*fun1)(P &f, void(*fun21)(X &f)), void(*fun2)(X &f))
 

Detailed Description

template<class T>
class DynLinArr< T >

Definition at line 151 of file AbsArr.h.

Constructor & Destructor Documentation

◆ DynLinArr() [1/8]

template<class T >
DynLinArr< T >::DynLinArr ( void  )
inline

Definition at line 159 of file AbsArr.h.

159: qel(0), el(NULL) { ; }

◆ DynLinArr() [2/8]

template<class T >
DynLinArr< T >::DynLinArr ( long  fqel)
inlineexplicit

Definition at line 160 of file AbsArr.h.

160 : qel(fqel), el(NULL) {
161 if (qel > max_qel_DynLinArr) {
162 mcerr << "ERROR in DynLinArr(long fqel):\n";
163 mcerr << "qel > max_qel_DynLinArr:\n";
165 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
166 << '\n';
167 spexit(mcerr);
168 }
169 if (qel < 0) {
170 mcerr << "ERROR in DynLinArr(long fqel):\n";
171 mcerr << "qel < 0:\n";
172 Iprintn(mcout, qel);
173 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
174 << '\n';
175 spexit(mcerr);
176 }
177#ifdef USE_REPLACE_ALLOC
178 if (fqel > 0) {
179 el = (T*)malloc(sizeof(T) * fqel);
180 long n;
181 for (n = 0; n < fqel; n++)
182 new (&(el[n])) T;
183 }
184#else
185 el = (fqel > 0) ? (new T[fqel]) : (T*)NULL;
186#endif
187 }
long max_qel_DynLinArr
Definition: AbsArr.cpp:17
#define spexit(stream)
Definition: FunNameStack.h:536
#define mcout
Definition: prstream.h:133
#define mcerr
Definition: prstream.h:135
#define Iprintn(file, name)
Definition: prstream.h:216
#define Iprint2n(file, name1, name2)
Definition: prstream.h:236

◆ DynLinArr() [3/8]

template<class T >
DynLinArr< T >::DynLinArr ( long  fqel,
const T &  val 
)
inline

Definition at line 189 of file AbsArr.h.

189 : qel(fqel), el(NULL) {
190 if (qel > max_qel_DynLinArr) {
191 mcerr << "ERROR in DynLinArr(long fqel, const T& val):\n";
192 mcerr << "qel > max_qel_DynLinArr:\n";
194 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
195 << '\n';
196 spexit(mcerr);
197 }
198 if (qel < 0) {
199 mcerr << "ERROR in DynLinArr(long fqel, const T& val):\n";
200 mcerr << "qel < 0:\n";
201 Iprintn(mcout, qel);
202 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
203 << '\n';
204 spexit(mcerr);
205 }
206#ifdef USE_REPLACE_ALLOC
207 if (fqel > 0) {
208 el = (T*)malloc(sizeof(T) * fqel);
209 long n;
210 for (n = 0; n < fqel; n++)
211 new (&(el[n])) T;
212 }
213#else
214 el = (fqel > 0) ? (new T[fqel]) : (T*)NULL;
215#endif
216 assignAll(val);
217 }
DynLinArr & assignAll(const T &f)
Definition: AbsArr.h:289

◆ DynLinArr() [4/8]

template<class T >
DynLinArr< T >::DynLinArr ( long  fqel,
const T *  ar,
ArgInterp_Arr   
)
inline

Definition at line 218 of file AbsArr.h.

218 : qel(fqel), el(NULL) {
219 if (qel > max_qel_DynLinArr) {
220 mcerr << "ERROR in DynLinArr(long fqel, const T* ar, ArgInterp_Arr):\n";
221 mcerr << "qel > max_qel_DynLinArr:\n";
223 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
224 << '\n';
225 spexit(mcerr);
226 }
227 if (qel < 0) {
228 mcerr << "ERROR in DynLinArr(long fqel, const T* ar, ArgInterp_Arr):\n";
229 mcerr << "qel < 0:\n";
230 Iprintn(mcout, qel);
231 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
232 << '\n';
233 spexit(mcerr);
234 }
235#ifdef USE_REPLACE_ALLOC
236 if (fqel > 0) {
237 el = (T*)malloc(sizeof(T) * fqel);
238 long n;
239 for (n = 0; n < fqel; n++)
240 new (&(el[n])) T;
241 }
242#else
243 el = (fqel > 0) ? (new T[fqel]) : (T*)NULL;
244#endif
245 long n;
246 for (n = 0; n < qel; n++)
247 el[n] = ar[n];
248 }

◆ DynLinArr() [5/8]

template<class T >
DynLinArr< T >::DynLinArr ( const DynLinArr< T > &  f)
inline

Definition at line 761 of file AbsArr.h.

762 :
763#ifndef DONT_USE_ABSPTR
764 RegPassivePtr(),
765#endif
766 qel(0),
767 el(NULL) {
768#ifdef DEBUG_DYNLINARR
769 mcout << "DynLinArr(const DynLinArr<T>& f) is working\n";
770#endif
771 *this = f;
772}

◆ DynLinArr() [6/8]

template<class T >
DynLinArr< T >::DynLinArr ( PILF_CONST DynLinArr< T > &  f,
Pilfer   
)
inline

Definition at line 274 of file AbsArr.h.

274 : qel(f.qel), el(f.el) {
275#ifdef DEBUG_DYNLINARR
276 mcout << "DynLinArr( DynLinArr<T>& f, Pilfer) is working\n";
277#endif
278 f.qel = 0;
279 f.el = 0;
280 }

◆ DynLinArr() [7/8]

template<class T >
DynLinArr< T >::DynLinArr ( const DynArr< T > &  f)

Definition at line 2948 of file AbsArr.h.

2948 {
2949 //mcout<<"template<class T> DynLinArr<T>::DynLinArr(const DynArr<T>& f):\n";
2950 f.check();
2951 long qdim = f.get_qdim();
2952 if (qdim != 1) {
2953 mcerr << "ERROR in DynLinArr<T>::DynLinArr(const DynArr<T>& f):\n"
2954 << "f.get_qdim() != 1, f.get_qdim()=" << f.get_qdim() << '\n';
2955 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
2956 << '\n';
2957 spexit(mcerr);
2958 }
2959 const DynLinArr<long>& qelem = f.get_qel();
2960 qel = qelem[0];
2961 //mcout<<"qel="<<qel<<'\n';
2962 if (qel > 0) {
2963#ifdef USE_REPLACE_ALLOC
2964 el = (T*)malloc(sizeof(T) * qel);
2965 long n;
2966 for (n = 0; n < qel; n++)
2967 new (&(el[n])) T;
2968#else
2969 el = new T[qel];
2970#endif
2971 long n;
2972 for (n = 0; n < qel; n++)
2973 el[n] = f.ac(n);
2974 } else
2975 el = NULL;
2976}
long get_qdim(void) const
Definition: AbsArr.h:2547
void check(void) const
Definition: AbsArr.h:2587
T & ac(long i)
Definition: AbsArr.h:2057
const DynLinArr< long > & get_qel(void) const
Definition: AbsArr.h:2548

◆ DynLinArr() [8/8]

template<class T >
DynLinArr< T >::DynLinArr ( const DynArr< T > &  f,
int  n_of_dim,
long  roc_number 
)

Definition at line 2979 of file AbsArr.h.

2983 {
2984 f.check();
2985 long qdim = f.get_qdim();
2986 if (qdim != 2) {
2987 mcerr << "ERROR in DynLinArr<T>::DynLinArr(const DynArr<T>& f, int "
2988 "n_of_dim,long roc_number):\n"
2989 << "f.get_qdim() != 2, f.get_qdim()=" << f.get_qdim() << '\n';
2990 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
2991 << '\n';
2992 spexit(mcerr);
2993 }
2994 const DynLinArr<long>& qelem = f.get_qel();
2995 if (n_of_dim == 0) {
2996 qel = qelem[1];
2997 } else {
2998 qel = qelem[0];
2999 }
3000 //mcout<<"qel="<<qel<<'\n';
3001 if (qel > 0) {
3002#ifdef USE_REPLACE_ALLOC
3003 el = (T*)malloc(sizeof(T) * qel);
3004 long n;
3005 for (n = 0; n < qel; n++)
3006 new (&(el[n])) T;
3007#else
3008 el = new T[qel];
3009#endif
3010 long n;
3011 if (n_of_dim == 0) {
3012 for (n = 0; n < qel; n++)
3013 el[n] = f.ac(roc_number, n);
3014 } else {
3015 for (n = 0; n < qel; n++)
3016 el[n] = f.ac(n, roc_number);
3017 }
3018 }
3019}

◆ ~DynLinArr()

template<class T >
virtual DynLinArr< T >::~DynLinArr ( )
inlinevirtual

Definition at line 562 of file AbsArr.h.

562 {
563 check();
564 if (el != NULL)
565#ifdef USE_REPLACE_ALLOC
566 {
567 long n;
568 for (n = 0; n < qel; n++) {
569 (&(el[n]))->~T();
570 }
571 free(el);
572 }
573#else
574 delete[] el;
575#endif
576 }
void check(void) const
Definition: AbsArr.h:615

Member Function Documentation

◆ acu() [1/2]

◆ acu() [2/2]

template<class T >
const T & DynLinArr< T >::acu ( long  n) const
inline

Definition at line 376 of file AbsArr.h.

377 {
378 return el[n];
379 }

◆ assignAll()

template<class T >
DynLinArr & DynLinArr< T >::assignAll ( const T &  f)
inline

Definition at line 289 of file AbsArr.h.

289 {
290 check();
291 long n;
292 for (n = 0; n < qel; n++)
293 el[n] = f;
294 return *this;
295 }

Referenced by DynLinArr< T >::assignAll1(), and DynLinArr< T >::DynLinArr().

◆ assignAll1()

template<class T >
template<class X >
DynLinArr< T > & DynLinArr< T >::assignAll1 ( const X &  f)
inline

Definition at line 297 of file AbsArr.h.

300 {
301 check();
302 long n;
303 for (n = 0; n < qel; n++)
304 el[n].assignAll(f);
305 return *this;
306 }

◆ check()

template<class T >
void DynLinArr< T >::check ( void  ) const

Definition at line 615 of file AbsArr.h.

615 {
616 if (qel < 0) {
617 mcerr << "ERROR in template<class T> void DynLinArr<T>::check(void):\n";
618 mcerr << "qel < 0, qel=" << qel << '\n';
619 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
620 << '\n';
621 spexit(mcerr);
622 }
623 if (qel == 0 && el != NULL) {
624 mcerr << "ERROR in template<class T> void DynLinArr<T>::check(void):\n";
625 //mcerr<<"qel == 0 && el != NULL: long(el)="<<long(el)<<'\n';
626 mcerr << "qel == 0 && el != NULL: el=" << el << '\n';
627 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
628 << '\n';
629 spexit(mcerr);
630 }
631 if (qel > 0) {
632 if (el == NULL) {
633 mcerr << "ERROR in template<class T> void DynLinArr<T>::check(void):\n";
634 mcerr << "qel > 0 && el == NULL: qel=" << qel << '\n';
635 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
636 << '\n';
637 spexit(mcerr);
638 }
639 if (qel > max_qel_DynLinArr) {
640 mcerr << "ERROR in template<class T> void DynLinArr<T>::check(void):\n";
641 mcerr << "qel > max_qel_DynLinArr: \n";
643 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
644 << '\n';
645 spexit(mcerr);
646 }
647 }
648}

Referenced by DynLinArr< T >::assignAll(), DynLinArr< T >::assignAll1(), DynArr< T >::check(), DynLinArr< T >::increment(), operator<<(), DynLinArr< T >::operator=(), print_adr_DynLinArr(), print_DynArr_double(), print_DynArr_float(), print_DynArr_int_w(), print_DynLinArr(), print_DynLinArr_double(), print_DynLinArr_double2(), print_DynLinArr_float(), print_DynLinArr_int(), print_DynLinArr_int_double(), print_DynLinArr_int_double3(), print_DynLinArr_long(), and DynLinArr< T >::~DynLinArr().

◆ clear()

template<class T >
void DynLinArr< T >::clear ( void  )
inline

◆ get_qel()

template<class T >
long DynLinArr< T >::get_qel ( void  ) const
inline

Definition at line 420 of file AbsArr.h.

420{ return qel; }

Referenced by absref_transmit_absvol::absref_transmit_absvol(), absref_transmit_fixsyscoor::absref_transmit_fixsyscoor(), absref_transmit_manip::absref_transmit_manip(), DynArr< T >::ac(), DynArr< T >::acp(), DynArr< T >::acu(), Heed::AtomicSecondaryProducts::add_channel(), apeq_mant(), append(), assignAll_1(), Heed::AtomMixDef::AtomMixDef(), change_sign(), chispre(), chisran(), IterDynArr< T >::current(), determinant_DynArr(), DynArr< T >::DynArr(), DynLinArr_char_we_to_String(), Heed::ExAtomPhotoAbsCS::ExAtomPhotoAbsCS(), Heed::ElElasticScat::fill_hist_low_scat(), absvol::find_embed_vol(), find_next_comb(), find_next_comb_not_less(), find_prev_comb(), gconfirm_ind(), gconfirm_ind_ext(), Heed::MolecPhotoAbsCS::get_ACS(), Heed::AtomicSecondaryProducts::get_channel(), Heed::SimpleTablePhotoAbsCS::get_CS(), Heed::AtomPhotoAbsCS::get_escape_particles(), Heed::MolecPhotoAbsCS::get_ICS(), Heed::MolecPhotoAbsCS::get_integral_ACS(), Heed::SimpleTablePhotoAbsCS::get_integral_CS(), Heed::MolecPhotoAbsCS::get_integral_ICS(), DynArr< T >::get_qdim(), DynArr< T >::get_s_non_emplty(), Heed::MolecPhotoAbsCS::get_total_Z(), ifequal(), inverse_DynArr(), inverse_DynArr_prot(), IterDynArr< T >::IterDynArr(), merge(), norm_DynLinArr(), norm_DynLinArr_part(), normsq_DynLinArr(), normsq_DynLinArr_part(), DynArr< T >::IndexingProvider< D >::operator D&(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-=(), operator/(), operator/=(), operator<<(), DynArr< T >::IndexingProvider< D >::operator=(), DynLinArr< T >::operator=(), operator==(), operator>>(), DynArr< T >::IndexingProvider< D >::operator[](), DynArr< T >::operator[](), Heed::HeedPhoton::physics_after_new_speed(), DynArr< T >::pilfer(), PointsRan::PointsRan(), PointsRan::print(), Heed::SimpleTablePhotoAbsCS::print(), Heed::AtomicSecondaryProducts::print(), Heed::AtomPhotoAbsCS::print(), Heed::MolecPhotoAbsCS::print(), absvol::print(), print_adr_DynLinArr(), print_BlkArr(), print_DynLinArr(), print_DynLinArr_double(), print_DynLinArr_double2(), print_DynLinArr_float(), print_DynLinArr_int(), print_DynLinArr_int_double(), print_DynLinArr_int_double3(), print_DynLinArr_long(), put_qel_1(), absvol::range(), remove_end_comments(), Heed::SimpleTablePhotoAbsCS::remove_leading_tiny(), Heed::SimpleTablePhotoAbsCS::remove_leading_zeros(), Heed::SimpleTablePhotoAbsCS::scale(), and Heed::SimpleTablePhotoAbsCS::SimpleTablePhotoAbsCS().

◆ increment() [1/2]

template<class T >
void DynLinArr< T >::increment ( const T &  val)
inline

Definition at line 445 of file AbsArr.h.

445 {
446 check();
447 long q = qel + 1;
448 put_qel(q, val);
449 }

◆ increment() [2/2]

template<class T >
void DynLinArr< T >::increment ( const T *  val = NULL)
inline

Definition at line 440 of file AbsArr.h.

440 {
441 check();
442 long q = qel + 1;
443 put_qel(q, *val);
444 }

Referenced by Heed::ExAtomPhotoAbsCS::ExAtomPhotoAbsCS().

◆ last_el() [1/2]

template<class T >
T & DynLinArr< T >::last_el ( void  )
inline

Definition at line 380 of file AbsArr.h.

380 {
381#ifdef ALR_CHECK_BOUND
382 if (qel > 0) {
383 return el[qel - 1];
384 } else {
385 mcerr << "ERROR in const T& DynLinArr::last_el(void) const: qel <=0:"
386 << " qel" << qel << '\n';
387 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
388 << '\n';
389 spexit(mcerr);
390#ifdef INS_CRETURN // Insert calming return
391 return el[0]; // to quiet Microsoft Visial Studio compiler against
392 // "not all control paths return a value"
393#endif
394 }
395#else
396 return el[qel];
397#endif
398 }

◆ last_el() [2/2]

template<class T >
const T & DynLinArr< T >::last_el ( void  ) const
inline

Definition at line 400 of file AbsArr.h.

400 {
401#ifdef ALR_CHECK_BOUND
402 if (qel > 0) {
403 return el[qel - 1];
404 } else {
405 mcerr << "ERROR in const T& DynLinArr::last_el(void) const: qel <=0:"
406 << " qel" << qel << '\n';
407 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
408 << '\n';
409 spexit(mcerr);
410#ifdef INS_CRETURN // Insert calming return
411 return el[0]; // to quiet Microsoft Visial Studio compiler against
412 // "not all control paths return a value"
413#endif
414 }
415#else
416 return el[qel];
417#endif
418 }

◆ macro_copy_header()

template<class T >
DynLinArr< T >::macro_copy_header ( DynLinArr< T >  )

◆ operator=() [1/2]

template<class T >
template<class D >
DynLinArr< T > & DynLinArr< T >::operator= ( const DynLinArr< D > &  f)

Definition at line 710 of file AbsArr.h.

710 {
711#ifdef DEBUG_DYNLINARR
712 mcout << "DynLinArr<T>& DynLinArr<T>::operator=(const DynLinArr<D>& f) is "
713 "working\n";
714#endif
715 //if(this != &f)
716 //{
717 //mcout<<"DynLinArr<T>& operator=(const DynLinArr<T>& f): long(el)="
718 //<<long(el)<<'\n';
719 check();
720 f.check();
721 // First of all we allocate memory and copy to there
722 // all elements from f, because f can be part of this array,
723 // for example, one of its elements.
724 long q = f.get_qel();
725#ifdef USE_REPLACE_ALLOC
726 T* temp_el;
727 if (q > 0) {
728 temp_el = (T*)malloc(sizeof(T) * q);
729 //long n; for(n=0; n<q; n++) T* t = new(&(temp_el[n])) T;
730 // What is this (above)? Perhaps I did not debug this.
731
732 long n;
733 for (n = 0; n < q; n++)
734 new (&(temp_el[n])) T(f.el[n]); // here
735 // we call copy constructor instead of creating default as for above
736 // and then to copy to it.
737 } else
738 temp_el = NULL;
739#else
740 //T* temp_el = (q > 0) ? (new T[q]) : (T*)NULL;
741 T* temp_el = (T*)NULL;
742 if (q > 0) {
743 //mcout<<"operator=: sizeof(T)="<<std::setw(10)<<sizeof(T)<<" q="<<q<<'\n';
744 temp_el = new T[q];
745 //long n; for( n=0; n<q; n++) temp_el[n]=f.el[n];
746 long n;
747 for (n = 0; n < q; n++)
748 temp_el[n] = f[n];
749 }
750
751#endif
752 //long n; for( n=0; n<q; n++) temp_el[n] = f.acu(n);
753 pass(q, temp_el);
754 //el = (qel > 0) ? (new T[qel]) : (T*)NULL;
755 //long n; for( n=0; n<qel; n++) el[n]=f.el[n];
756 //}
757 return *this;
758}
long get_qel(void) const
Definition: AbsArr.h:420
void pass(long fqel, T *fel)
Definition: AbsArr.h:265

◆ operator=() [2/2]

template<class T >
DynLinArr< T > & DynLinArr< T >::operator= ( const DynLinArr< T > &  f)

Definition at line 651 of file AbsArr.h.

651 {
652#ifdef DEBUG_DYNLINARR
653 mcout << "DynLinArr<T>& DynLinArr<T>::operator=(const DynLinArr<T>& f) is "
654 "working\n";
655#endif
656 if (this != &f) {
657 //mcout<<"DynLinArr<T>& operator=(const DynLinArr<T>& f): long(el)="
658 //<<long(el)<<'\n';
659 check();
660 f.check();
661 // First of all we allocate memory and copy to there
662 // all elements from f, because f can be part of this array,
663 // for example, one of its elements.
664 long q = f.get_qel();
665#ifdef USE_REPLACE_ALLOC
666 T* temp_el;
667 if (q > 0) {
668 temp_el = (T*)malloc(sizeof(T) * q);
669 //long n; for(n=0; n<q; n++) new(&(temp_el[n])) T;
670 long n;
671 for (n = 0; n < q; n++)
672 new (&(temp_el[n])) T(f.el[n]); // here
673 // we call copy constructor instead of creating default as for above
674 // and then to copy to it.
675 } else
676 temp_el = NULL;
677#else
678 //mcout<<"operator=: sizeof(T)="<<std::setw(10)<<sizeof(T)<<" q="<<q<<'\n';
679 //T* temp_el = (q > 0) ? (new T[q]) : (T*)NULL;
680 T* temp_el = (T*)NULL;
681 if (q > 0) {
682 //mcout<<"operator=: sizeof(T)="<<std::setw(10)<<sizeof(T)<<"
683 //q="<<q<<'\n';
684 temp_el = new T[q];
685 long n;
686 for (n = 0; n < q; n++)
687 temp_el[n] = f.el[n];
688 }
689#endif
690 //long n; for( n=0; n<q; n++) temp_el[n]=f.el[n];
691 /*
692#ifdef USE_REPLACE_ALLOC
693 for(n=0; n<q; n++) el[n].~T();
694 free(el);
695#else
696 delete[] el;
697#endif
698 qel = q;
699 el = temp_el;
700 */
701 pass(q, temp_el);
702 //el = (qel > 0) ? (new T[qel]) : (T*)NULL;
703 //long n; for( n=0; n<qel; n++) el[n]=f.el[n];
704 }
705 return *this;
706}

◆ operator[]() [1/2]

template<class T >
T & DynLinArr< T >::operator[] ( long  n)
inline

Definition at line 308 of file AbsArr.h.

308 {
309#ifdef ALR_CHECK_BOUND
310 if (n >= 0 && n < qel) {
311 return el[n];
312 } else {
313 mcerr << "ERROR in const T& DynLinArr::operator[](long n) const: "
314 << "n is out of bounds, n=" << n << " qel=" << qel << '\n';
315 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
316 << '\n';
317 spexit(mcerr);
318#ifdef INS_CRETURN
319 return el[0]; // to quiet Microsoft Visial Studio compiler against
320 // "not all control paths return a value"
321#endif
322 }
323#else
324 return el[n];
325#endif
326 /*
327#ifdef ALR_CHECK_BOUND
328 if(n<0 || n>=qel)
329 {
330 mcerr<<"ERROR in T& DynLinArr::operator[](long n): "
331 <<"n is out of bounds, n="<<n
332 <<" qel="<<qel<<'\n';
333 mcerr<<"Type of T is (in internal notations) "<<typeid(T).name()<<'\n';
334 spexit(mcerr);
335 }
336#endif
337 return el[n];
338 */
339 }

◆ operator[]() [2/2]

template<class T >
const T & DynLinArr< T >::operator[] ( long  n) const
inline

Definition at line 340 of file AbsArr.h.

340 {
341#ifdef ALR_CHECK_BOUND
342 if (n >= 0 && n < qel) {
343 return el[n];
344 } else {
345 mcerr << "ERROR in const T& DynLinArr::operator[](long n) const: "
346 << "n is out of bounds, n=" << n << " qel=" << qel << '\n';
347 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
348 << '\n';
349 spexit(mcerr);
350#ifdef INS_CRETURN // Insert calming return
351 return el[0]; // to quiet Microsoft Visial Studio compiler against
352 // "not all control paths return a value"
353#endif
354 }
355#else
356 return el[n];
357#endif
358 /* // it is more simple to read but might be slower to execute
359#ifdef ALR_CHECK_BOUND
360 if(n<0 || n>=qel)
361 {
362 mcerr<<"ERROR in const T& DynLinArr::operator[](long n) const: "
363 <<"n is out of bounds, n="<<n
364 <<" qel="<<qel<<'\n';
365 mcerr<<"Type of T is (in internal notations) "<<typeid(T).name()<<'\n';
366 spexit(mcerr);
367 }
368#endif
369 return el[n];
370 */
371 }

◆ pass()

template<class T >
void DynLinArr< T >::pass ( long  fqel,
T *  fel 
)
inline

Definition at line 265 of file AbsArr.h.

265 {
266 // Do not call directly! Is to be used only
267 // from assignment operator above
268 clear();
269 qel = fqel;
270 el = fel;
271 }
void clear(void)
Definition: AbsArr.h:450

Referenced by Heed::ExAtomPhotoAbsCS::ExAtomPhotoAbsCS(), Heed::ExAtomPhotoAbsCS::replace_shells_by_overage(), and Heed::SimpleAtomPhotoAbsCS::SimpleAtomPhotoAbsCS().

◆ pilfer()

template<class T >
void DynLinArr< T >::pilfer ( PILF_CONST DynLinArr< T > &  f)
inline

Definition at line 454 of file AbsArr.h.

454 {
455#ifdef DEBUG_DYNLINARR
456 mcout << "DynLinArr::pilfer is called\n";
457#endif
458 if (this != &f) {
459 if (qel != 0) {
460 if (f.qel != 0) {
461 mcerr << "ERROR in DynLinArr::pilfer(...):\n";
462 mcerr << "Both the destination and source arrays are not empty\n";
463 // For explanations why it is dengerous, see similar function
464 // of ActivePtr.
465 spexit(mcerr);
466 } else {
467#ifdef USE_REPLACE_ALLOC
468 {
469 long n;
470 for (n = 0; n < qel; n++)
471 el[n].~T();
472 free(el);
473 }
474#else
475 delete[] el;
476#endif
477 qel = 0;
478 }
479 }
480 el = f.el;
481 qel = f.qel;
482 f.el = NULL;
483 f.qel = 0;
484 }
485 }

Referenced by DynArr< T >::pilfer(), DynLinArr< T >::sort(), DynLinArr< T >::sort_select_decreasing(), and DynLinArr< T >::sort_select_increasing().

◆ put_qel() [1/3]

template<class T >
void DynLinArr< T >::put_qel ( long  fqel)

Definition at line 774 of file AbsArr.h.

774 {
775 //
776 // creates array with size fqel
777 // If old array existed, then
778 // If it was less than fqel, it all is copied to new array
779 // and the other elements either assigned *val or
780 // remains not inited.
781 // else its fqel part is copyed to new array.
782 //mcout<<"put_qel: *this="<<(*this);
783 if (fqel < 0) {
784 mcerr << "ERROR in template<class T> void DynLinArr<T>::put_qel(long "
785 "fqel):\n";
786 mcerr << "fqel < 0, fqel=" << fqel << '\n';
787 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
788 << '\n';
789 spexit(mcerr);
790 }
791 check();
792 if (el == NULL) {
793 qel = fqel;
794 if (qel > 0) {
795#ifdef USE_REPLACE_ALLOC
796 el = (T*)malloc(sizeof(T) * fqel);
797 for (long n = 0; n < fqel; ++n)
798 new (&(el[n])) T;
799#else
800 el = new T[fqel];
801#endif
802 }
803 } else {
804 if (qel != fqel) {
805 if (fqel <= 0) {
806 qel = 0;
807#ifdef USE_REPLACE_ALLOC
808 for (long n = 0; n < qel; ++n)
809 el[n].~T();
810 free(el);
811#else
812 delete[] el;
813#endif
814 el = NULL;
815 } else {
816 T* elh;
817#ifdef USE_REPLACE_ALLOC
818 elh = (T*)malloc(sizeof(T) * fqel);
819 for (n = 0; n < fqel; ++n)
820 new (&(elh[n])) T;
821#else
822 elh = new T[fqel]; // long q = find_min(qel,fqel);
823#endif
824 for (long n = 0; n < fqel; ++n) {
825 if (n < qel) elh[n] = el[n];
826 }
827#ifdef USE_REPLACE_ALLOC
828 for (long n = 0; n < qel; ++n)
829 el[n].~T();
830 free(el);
831#else
832 delete[] el;
833#endif
834 el = elh;
835 qel = fqel;
836 }
837 }
838 }
839}

Referenced by Heed::AtomicSecondaryProducts::add_channel(), append(), DynLinArr< T >::clear(), DynArr< T >::DynArr(), Heed::EnTransfCS::EnTransfCS(), Heed::ExAtomPhotoAbsCS::ExAtomPhotoAbsCS(), Heed::generate_Argon_PACS_mod_esc(), Heed::AtomPhotoAbsCS::get_escape_particles(), DynLinArr< T >::increment(), Heed::MolecPhotoAbsCS::MolecPhotoAbsCS(), operator>>(), DynLinArr< T >::put_qel(), remove_end_comments(), Heed::SimpleAtomPhotoAbsCS::SimpleAtomPhotoAbsCS(), Heed::SimpleTablePhotoAbsCS::SimpleTablePhotoAbsCS(), DynLinArr< T >::sort_select_decreasing(), and DynLinArr< T >::sort_select_increasing().

◆ put_qel() [2/3]

template<class T >
void DynLinArr< T >::put_qel ( long  fqel,
const T &  val 
)
inline

Definition at line 437 of file AbsArr.h.

437 {
438 put_qel(fqel, &val, ArgInterp_SingleAdr());
439 }

◆ put_qel() [3/3]

template<class T >
void DynLinArr< T >::put_qel ( long  fqel,
const T *  val,
ArgInterp_SingleAdr  t 
)

Definition at line 842 of file AbsArr.h.

842 {
843 // By default val == NULL
844 // creates array with size fqel
845 // If old array existed, then
846 // If it was less than fqel, it all is copied to new array
847 // and the other elements either assigned *val or
848 // remains not inited.
849 // else its fqel part is copyed to new array.
850 //mcout<<"put_qel: *this="<<(*this);
851 if (fqel < 0) {
852 mcerr << "ERROR in template<class T> void DynLinArr<T>::put_qel(long fqel, "
853 "const T* val, ArgInterp_SingleAdr):\n";
854 mcerr << "fqel < 0, fqel=" << fqel << '\n';
855 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
856 << '\n';
857 spexit(mcerr);
858 // Avoid compiler warning because of unused variable t (HS).
859 mcerr << sizeof(t) << "\n";
860 }
861 check();
862 if (el == NULL) {
863 qel = fqel;
864 if (qel > 0) {
865#ifdef USE_REPLACE_ALLOC
866 el = (T*)malloc(sizeof(T) * fqel);
867 for (long n = 0; n < fqel; ++n)
868 new (&(el[n])) T;
869#else
870 el = new T[fqel];
871#endif
872 }
873 if (val != NULL) for (long n = 0; n < qel; ++n)
874 el[n] = *val;
875 } else {
876 if (qel != fqel) {
877 if (fqel <= 0) {
878 qel = 0;
879#ifdef USE_REPLACE_ALLOC
880 for (long n = 0; n < qel; ++n)
881 el[n].~T();
882 free(el);
883#else
884 delete[] el;
885#endif
886 el = NULL;
887 } else {
888 T* elh;
889#ifdef USE_REPLACE_ALLOC
890 elh = (T*)malloc(sizeof(T) * fqel);
891 for (long n = 0; n < fqel; ++n)
892 new (&(elh[n])) T;
893#else
894 elh = new T[fqel]; // long q = find_min(qel,fqel);
895#endif
896 for (long n = 0; n < fqel; ++n) {
897 if (n < qel)
898 elh[n] = el[n];
899 else if (val != NULL)
900 elh[n] = *val;
901 }
902#ifdef USE_REPLACE_ALLOC
903 for (long n = 0; n < qel; ++n)
904 el[n].~T();
905 free(el);
906#else
907 delete[] el;
908#endif
909 el = elh;
910 qel = fqel;
911 }
912 }
913 }
914}

◆ sort() [1/2]

template<class T >
void DynLinArr< T >::sort ( DynLinArr< long > &  sort_ind,
long  q_to_sort = 0 
) const

Definition at line 985 of file AbsArr.h.

985 {
986 mfunnamep("void DynLinArr<T>::sort(DynLinArr< long >& sort_ind, long "
987 "q_to_sort = 0) const");
988
989 check_econd12(q_to_sort, >, qel, mcerr);
990 if (q_to_sort <= 0) q_to_sort = qel;
991 //if(q_to_sort <= 1) return;
992
993 sort_ind.clear();
994 sort_ind.pilfer(DynLinArr<long>(q_to_sort));
995 long n, m;
996 for (n = 0; n < q_to_sort; n++) {
997 sort_ind.acu(n) = n;
998 }
999 if (q_to_sort <= 1) return;
1000
1001 long n_possible_next = 1;
1002
1003 for (n = 0; n < q_to_sort - 1; n++) {
1004 // first it finds the minimum along the rest and replaces if it is less
1005 long nmin = n_possible_next;
1006 long ind_nmin = sort_ind.acu(nmin);
1007 int s_change_possible_next = 0;
1008
1009 //for(m=n+2; m<q_to_sort; m++)
1010 for (m = n_possible_next + 1; m < q_to_sort; m++) {
1011 if (el[ind_nmin] > el[sort_ind.acu(m)])
1012 //if(el[sort_ind.acu(nmin)] > el[sort_ind.acu(m)])
1013 {
1014 n_possible_next = nmin;
1015 s_change_possible_next = 1;
1016 nmin = m;
1017 ind_nmin = sort_ind.acu(nmin);
1018 }
1019 }
1020 if (s_change_possible_next == 0 || n_possible_next < n + 2) {
1021 n_possible_next = n + 2;
1022 }
1023 if (el[sort_ind.acu(n)] > el[ind_nmin])
1024 //if(el[sort_ind.acu(n)] > el[sort_ind.acu(nmin)])
1025 {
1026 if (s_change_possible_next == 1) {
1027 if (n_possible_next < q_to_sort &&
1028 el[sort_ind.acu(n)] < el[sort_ind.acu(n_possible_next)]) {
1029 n_possible_next = nmin;
1030 }
1031 }
1032 //long t = sort_ind.acu(nmin);
1033 sort_ind.acu(nmin) = sort_ind.acu(n);
1034 sort_ind.acu(n) = ind_nmin;
1035 }
1036 }
1037}
#define mfunnamep(string)
Definition: FunNameStack.h:77
#define check_econd12(a, sign, b, stream)
Definition: FunNameStack.h:380
void pilfer(PILF_CONST DynLinArr< T > &f)
Definition: AbsArr.h:454
T & acu(long n)
Definition: AbsArr.h:372

◆ sort() [2/2]

template<class T >
void DynLinArr< T >::sort ( long  q_to_sort = 0)

Definition at line 923 of file AbsArr.h.

923 {
924 mfunnamep("void DynLinArr<T>::sort(long q_to_sort = 0)");
925
926 check_econd12(q_to_sort, >, qel, mcerr);
927 if (q_to_sort <= 0) q_to_sort = qel;
928 if (q_to_sort <= 1) return;
929
930 long n_possible_next = 1;
931 long q_comp = 0;
932 long n, m;
933 for (n = 0; n < q_to_sort - 1; n++) {
934 //Iprint2n(mcout, n, n_possible_next);
935 // first it finds the minimum along the rest and replaces if it is less
936 //long nmin = n+1;
937 long nmin = n_possible_next;
938 T el_min = el[nmin];
939 int s_change_possible_next = 0;
940
941 //for(m=n+2; m<q_to_sort; m++)
942 for (m = n_possible_next + 1; m < q_to_sort; m++) {
943 q_comp++;
944 //if(el[nmin] > el[m])
945 if (el_min > el[m]) {
946 n_possible_next = nmin;
947 s_change_possible_next = 1;
948 nmin = m;
949 el_min = el[nmin];
950 }
951 }
952 //Iprint4n(mcout, n_possible_next, s_change_possible_next, nmin, el_min);
953 if (s_change_possible_next == 0 || n_possible_next < n + 2) {
954 n_possible_next = n + 2;
955 }
956 //if(el[n] > el[nmin])
957 //{
958 // T t = el[nmin];
959 // el[nmin] = el[n];
960 // el[n] = t;
961 //}
962 //Iprintn(mcout, n_possible_next);
963 //Iprint2n(mcout, el[n], el_min);
964 if (el[n] > el_min) {
965 if (s_change_possible_next == 1) {
966 //if(n_possible_next < q_to_sort)
967 if (n_possible_next < q_to_sort && el[n] < el[n_possible_next]) {
968 n_possible_next = nmin;
969 }
970 }
971 //mcout<<"replacing el[n] and el_min\n";
972 T t = el_min;
973 el[nmin] = el[n];
974 el[n] = t;
975 }
976 //Iprintn(mcout, (*this));
977
978 }
979 //Iprintn(mcout, q_comp);
980}

◆ sort_select_decreasing()

template<class T >
void DynLinArr< T >::sort_select_decreasing ( DynLinArr< long > &  sort_ind,
long  q_to_sort = 0 
) const

Definition at line 1103 of file AbsArr.h.

1104 {
1105 mfunnamep("void DynLinArr<T>::sort_select_decreasing(DynLinArr< long >& "
1106 "sort_ind, long q_to_sort = 0) const");
1107
1108 check_econd12(q_to_sort, >, qel, mcerr);
1109 long s_last_noninc = 0;
1110 if (q_to_sort <= 0) {
1111 q_to_sort = qel;
1112 s_last_noninc = 1;
1113 } else if (q_to_sort == qel) {
1114 s_last_noninc = 1;
1115 }
1116 //Iprintn(mcout, q_to_sort);
1117
1118 //if(qel <= 1) return;
1119 sort_ind.clear();
1120 sort_ind.pilfer(DynLinArr<long>(qel));
1121 long n, m;
1122 for (n = 0; n < qel; n++) {
1123 sort_ind[n] = n;
1124 }
1125 if (q_to_sort <= 1) return;
1126
1127 long n_possible_next = 1;
1128
1129 for (n = 0; n < q_to_sort - s_last_noninc; n++) {
1130 //Iprintn(mcout, n);
1131 // first it finds the minimum along the rest and replaces if it is less
1132 long nmax = n_possible_next;
1133 //Iprintn(mcout, nmax);
1134 long ind_nmax = sort_ind[nmax];
1135 int s_change_possible_next = 0;
1136
1137 //for(m=n+2; m<q_to_sort; m++)
1138 for (m = n_possible_next + 1; m < qel; m++) {
1139 //Iprint3n(mcout, ind_nmax, m, sort_ind[m]);
1140 if (el[ind_nmax] < el[sort_ind[m]]) {
1141 n_possible_next = nmax;
1142 s_change_possible_next = 1;
1143 nmax = m;
1144 //Iprintn(mcout, nmax);
1145 ind_nmax = sort_ind[nmax];
1146 }
1147 }
1148 if (s_change_possible_next == 0 || n_possible_next < n + 2) {
1149 n_possible_next = n + 2;
1150 }
1151 //Iprint4n(mcout, n, sort_ind[n], ind_nmax, el[ind_nmax]);
1152 if (el[sort_ind[n]] < el[ind_nmax]) {
1153 if (s_change_possible_next == 1) {
1154 if (n_possible_next < q_to_sort &&
1155 el[sort_ind[n]] > el[sort_ind[n_possible_next]]) {
1156 n_possible_next = nmax;
1157 }
1158 }
1159 //long t = sort_ind.acu(nmin);
1160 sort_ind[nmax] = sort_ind[n];
1161 sort_ind[n] = ind_nmax;
1162 }
1163 }
1164 sort_ind.put_qel(qel);
1165}

◆ sort_select_increasing()

template<class T >
void DynLinArr< T >::sort_select_increasing ( DynLinArr< long > &  sort_ind,
long  q_to_sort = 0 
) const

Definition at line 1040 of file AbsArr.h.

1041 {
1042 mfunnamep("void DynLinArr<T>::sort_select_increasing(DynLinArr< long >& "
1043 "sort_ind, long q_to_sort = 0) const");
1044
1045 check_econd12(q_to_sort, >, qel, mcerr);
1046 long s_last_noninc = 0;
1047 if (q_to_sort <= 0) {
1048 q_to_sort = qel;
1049 s_last_noninc = 1;
1050 } else if (q_to_sort == qel) {
1051 s_last_noninc = 1;
1052 }
1053
1054 //if(qel <= 1) return;
1055 sort_ind.clear();
1056 sort_ind.pilfer(DynLinArr<long>(qel));
1057 long n, m;
1058 for (n = 0; n < qel; n++) {
1059 sort_ind[n] = n;
1060 }
1061 if (q_to_sort <= 1) return;
1062
1063 long n_possible_next = 1;
1064
1065 for (n = 0; n < q_to_sort - s_last_noninc; n++) {
1066 // first it finds the minimum along the rest and replaces if it is less
1067 long nmin = n_possible_next;
1068 long ind_nmin = sort_ind[nmin];
1069 int s_change_possible_next = 0;
1070
1071 //for(m=n+2; m<q_to_sort; m++)
1072 for (m = n_possible_next + 1; m < qel; m++) {
1073 if (el[ind_nmin] > el[sort_ind[m]])
1074 //if(el[sort_ind.acu(nmin)] > el[sort_ind.acu(m)])
1075 {
1076 n_possible_next = nmin;
1077 s_change_possible_next = 1;
1078 nmin = m;
1079 ind_nmin = sort_ind[nmin];
1080 }
1081 }
1082 if (s_change_possible_next == 0 || n_possible_next < n + 2) {
1083 n_possible_next = n + 2;
1084 }
1085 if (el[sort_ind[n]] > el[ind_nmin])
1086 //if(el[sort_ind.acu(n)] > el[sort_ind.acu(nmin)])
1087 {
1088 if (s_change_possible_next == 1) {
1089 if (n_possible_next < q_to_sort &&
1090 el[sort_ind[n]] < el[sort_ind[n_possible_next]]) {
1091 n_possible_next = nmin;
1092 }
1093 }
1094 //long t = sort_ind.acu(nmin);
1095 sort_ind[nmin] = sort_ind[n];
1096 sort_ind[n] = ind_nmin;
1097 }
1098 }
1099 sort_ind.put_qel(qel);
1100}

◆ top()

template<class T >
DynArr< T > DynLinArr< T >::top ( void  )

Definition at line 2924 of file AbsArr.h.

2924 {
2925 check();
2926 DynArr<T> r(1, qel);
2927 long n;
2928 for (n = 0; n < qel; n++) {
2929 r.ac(0, n) = el[n];
2930 }
2931 return r;
2932}

Friends And Related Function Documentation

◆ apply1

template<class T >
template<class P >
void apply1 ( DynLinArr< P > &  ar,
void(*)(P &f)  fun 
)
friend

◆ apply2

template<class T >
template<class P , class X >
void apply2 ( DynLinArr< P > &  ar,
void(*)(P &f, void(*fun21)(X &f))  fun1,
void(*)(X &f)  fun2 
)
friend

The documentation for this class was generated from the following file: