a Code for the Combination of Indirect and Direct Constraints on High Energy Physics Models Logo
BOL::VectorlikeArray< StoredClass > Class Template Reference

#include <VectorlikeArray.hpp>

Detailed Description

template<typename StoredClass>
class BOL::VectorlikeArray< StoredClass >

Definition at line 30 of file VectorlikeArray.hpp.

Public Member Functions

VectorlikeArray< StoredClass > & becomeCopyOf (VectorlikeArray< StoredClass > const &copySource, void(*firstArgumentBecomesCopyOfSecond)(StoredClass &, StoredClass const &)=NULL)
 
VectorlikeArray< StoredClass > & clearEntries ()
 
std::list< StoredClass * > & getAsList (std::list< StoredClass * > &listToFill) const
 
std::vector< StoredClass * > & getAsVector (std::vector< StoredClass * > &vectorToFill) const
 
StoredClass & getBack ()
 
StoredClass const & getBack () const
 
StoredClass & getFront ()
 
StoredClass const & getFront () const
 
int getLastIndex () const
 
StoredClass * getPointer (int const soughtIndex)
 
StoredClass const * getPointer (int const soughtIndex) const
 
int getSize () const
 
VectorlikeArray< StoredClass > & increaseSize (int const numberToAdd=1)
 
bool isEmpty () const
 
VectorlikeArray< StoredClass > & memoryFreeingResize (int const newSize=0)
 
StoredClass & newEnd ()
 
StoredClass & operator[] (int const soughtIndex)
 
StoredClass const & operator[] (int const soughtIndex) const
 
StoredClass & safeAt (int const soughtIndex)
 
StoredClass const & safeAt (int const soughtIndex) const
 
VectorlikeArray< StoredClass > & setSize (int const newSize)
 
 VectorlikeArray (int const initialSize=0)
 
 VectorlikeArray (VectorlikeArray< StoredClass > const &copySource, StoredClass *(*storedClassCopyFunction)(StoredClass const &)=NULL)
 
 ~VectorlikeArray ()
 

Protected Member Functions

StoredClass & getReference (int const soughtIndex)
 
StoredClass const & getReference (int const soughtIndex) const
 
StoredClass * safeGetPointer (int const soughtIndex)
 
StoredClass const * safeGetPointer (int const soughtIndex) const
 
StoredClass * unsafeGetPointer (int const soughtIndex)
 
StoredClass const * unsafeGetPointer (int const soughtIndex) const
 

Protected Attributes

int allocatedSizeOfArray
 
int currentEndIndex
 
int currentSizeOfArray
 
int indexOfEndConstructed
 
StoredClass ** pointerArray
 

Constructor & Destructor Documentation

◆ VectorlikeArray() [1/2]

template<typename StoredClass >
BOL::VectorlikeArray< StoredClass >::VectorlikeArray ( int const  initialSize = 0)
inline

Definition at line 176 of file VectorlikeArray.hpp.

176 :
177 pointerArray( new StoredClass*[ initialSize ] ),
178 allocatedSizeOfArray( initialSize ),
180 currentSizeOfArray( initialSize ),
181 currentEndIndex( initialSize - 1 )
182 {
184 {
186 pointerArray[ indexOfEndConstructed ] = new StoredClass;
187 }
188 }
StoredClass ** pointerArray

◆ VectorlikeArray() [2/2]

template<typename StoredClass >
BOL::VectorlikeArray< StoredClass >::VectorlikeArray ( VectorlikeArray< StoredClass > const &  copySource,
StoredClass *(*)(StoredClass const &)  storedClassCopyFunction = NULL 
)
inline

Definition at line 202 of file VectorlikeArray.hpp.

204 :
205 pointerArray( new StoredClass*[ copySource.currentSizeOfArray ] ),
206 allocatedSizeOfArray( copySource.currentSizeOfArray ),
208 currentSizeOfArray( copySource.currentSizeOfArray ),
209 currentEndIndex( copySource.currentEndIndex )
210 {
211 if( NULL == storedClassCopyFunction )
212 {
214 {
217 = new StoredClass( copySource[ indexOfEndConstructed ] );
218 }
219 }
220 else
221 {
223 {
226 = (*storedClassCopyFunction)( copySource[ indexOfEndConstructed ] );
227 }
228 }
229 }

◆ ~VectorlikeArray()

template<typename StoredClass >
BOL::VectorlikeArray< StoredClass >::~VectorlikeArray
inline

Definition at line 233 of file VectorlikeArray.hpp.

234 {
235 while( 0 <= indexOfEndConstructed )
236 {
239 }
240 delete[] pointerArray;
241 }

Member Function Documentation

◆ becomeCopyOf()

template<typename StoredClass >
VectorlikeArray< StoredClass > & BOL::VectorlikeArray< StoredClass >::becomeCopyOf ( VectorlikeArray< StoredClass > const &  copySource,
void(*)(StoredClass &, StoredClass const &)  firstArgumentBecomesCopyOfSecond = NULL 
)
inline

Definition at line 595 of file VectorlikeArray.hpp.

606 {
607 setSize( copySource.getSize() );
608 if( NULL == firstArgumentBecomesCopyOfSecond )
609 {
610 for( int copyIndex( copySource.getLastIndex() );
611 0 <= copyIndex;
612 --copyIndex )
613 {
614 *(pointerArray[ copyIndex ]) = copySource[ copyIndex ];
615 }
616 }
617 else
618 {
619 for( int copyIndex( copySource.getLastIndex() );
620 0 <= copyIndex;
621 --copyIndex )
622 {
623 (*firstArgumentBecomesCopyOfSecond)( *(pointerArray[ copyIndex ]),
624 copySource[ copyIndex ] );
625 }
626 }
627 return *this;
628 }
VectorlikeArray< StoredClass > & setSize(int const newSize)

◆ clearEntries()

template<typename StoredClass >
VectorlikeArray< StoredClass > & BOL::VectorlikeArray< StoredClass >::clearEntries
inline

Definition at line 372 of file VectorlikeArray.hpp.

374 {
375 return setSize( 0 );
376 }

◆ getAsList()

template<typename StoredClass >
std::list< StoredClass * > & BOL::VectorlikeArray< StoredClass >::getAsList ( std::list< StoredClass * > &  listToFill) const
inline

Definition at line 488 of file VectorlikeArray.hpp.

492 {
493 listToFill.assign( pointerArray,
495 return listToFill;
496 }

◆ getAsVector()

template<typename StoredClass >
std::vector< StoredClass * > & BOL::VectorlikeArray< StoredClass >::getAsVector ( std::vector< StoredClass * > &  vectorToFill) const
inline

Definition at line 476 of file VectorlikeArray.hpp.

480 {
481 vectorToFill.assign( pointerArray,
483 return vectorToFill;
484 }

◆ getBack() [1/2]

template<typename StoredClass >
StoredClass & BOL::VectorlikeArray< StoredClass >::getBack
inline

Definition at line 458 of file VectorlikeArray.hpp.

461 {
462 return *(safeGetPointer( currentEndIndex ));
463 }
StoredClass * safeGetPointer(int const soughtIndex)

◆ getBack() [2/2]

template<typename StoredClass >
StoredClass const & BOL::VectorlikeArray< StoredClass >::getBack
inline

Definition at line 467 of file VectorlikeArray.hpp.

470 {
471 return *(safeGetPointer( currentEndIndex ));
472 }

◆ getFront() [1/2]

template<typename StoredClass >
StoredClass & BOL::VectorlikeArray< StoredClass >::getFront
inline

Definition at line 440 of file VectorlikeArray.hpp.

443 {
444 return *(safeGetPointer( 0 ));
445 }

◆ getFront() [2/2]

template<typename StoredClass >
StoredClass const & BOL::VectorlikeArray< StoredClass >::getFront
inline

Definition at line 449 of file VectorlikeArray.hpp.

452 {
453 return *(safeGetPointer( 0 ));
454 }

◆ getLastIndex()

template<typename StoredClass >
int BOL::VectorlikeArray< StoredClass >::getLastIndex
inline

Definition at line 289 of file VectorlikeArray.hpp.

292 {
293 return currentEndIndex;
294 }

◆ getPointer() [1/2]

template<typename StoredClass >
StoredClass * BOL::VectorlikeArray< StoredClass >::getPointer ( int const  soughtIndex)
inline

Definition at line 380 of file VectorlikeArray.hpp.

382 {
383 return safeGetPointer( soughtIndex );
384 }

◆ getPointer() [2/2]

template<typename StoredClass >
StoredClass const * BOL::VectorlikeArray< StoredClass >::getPointer ( int const  soughtIndex) const
inline

Definition at line 388 of file VectorlikeArray.hpp.

390 {
391 return safeGetPointer( soughtIndex );
392 }

◆ getReference() [1/2]

template<typename StoredClass >
StoredClass & BOL::VectorlikeArray< StoredClass >::getReference ( int const  soughtIndex)
inlineprotected

Definition at line 412 of file VectorlikeArray.hpp.

414 {
415 StoredClass* soughtPointer( safeGetPointer( soughtIndex ) );
416 if( NULL == soughtPointer )
417 {
418 throw std::out_of_range(
419 "VectorlikeArray::getReference(...) out of range" );
420 }
421 return *soughtPointer;
422 }

◆ getReference() [2/2]

template<typename StoredClass >
StoredClass const & BOL::VectorlikeArray< StoredClass >::getReference ( int const  soughtIndex) const
inlineprotected

Definition at line 426 of file VectorlikeArray.hpp.

428 {
429 StoredClass* soughtPointer( safeGetPointer( soughtIndex ) );
430 if( NULL == soughtPointer )
431 {
432 throw std::out_of_range(
433 "VectorlikeArray::getReference(...) out of range" );
434 }
435 return *soughtPointer;
436 }

◆ getSize()

template<typename StoredClass >
int BOL::VectorlikeArray< StoredClass >::getSize
inline

Definition at line 280 of file VectorlikeArray.hpp.

283 {
284 return currentSizeOfArray;
285 }

◆ increaseSize()

template<typename StoredClass >
VectorlikeArray< StoredClass > & BOL::VectorlikeArray< StoredClass >::increaseSize ( int const  numberToAdd = 1)
inline

Definition at line 353 of file VectorlikeArray.hpp.

356 {
357 return setSize( numberToAdd + currentSizeOfArray );
358 }

◆ isEmpty()

template<typename StoredClass >
bool BOL::VectorlikeArray< StoredClass >::isEmpty
inline

Definition at line 264 of file VectorlikeArray.hpp.

267 {
268 if( 0 < currentSizeOfArray )
269 {
270 return false;
271 }
272 else
273 {
274 return true;
275 }
276 }

◆ memoryFreeingResize()

template<typename StoredClass >
VectorlikeArray< StoredClass > & BOL::VectorlikeArray< StoredClass >::memoryFreeingResize ( int const  newSize = 0)
inline

Definition at line 500 of file VectorlikeArray.hpp.

503 {
504 currentSizeOfArray = newSize;
505 currentEndIndex = ( newSize - 1 );
506 while( indexOfEndConstructed >= newSize )
507 {
510 }
511 if( newSize != allocatedSizeOfArray )
512 {
513 allocatedSizeOfArray = newSize;
514 StoredClass**
515 newPointerArray = new StoredClass*[ allocatedSizeOfArray ];
516 // now newCurrentPointersArray is a new array where the pointers
517 // can be put.
518
519 for( int copyIndex( indexOfEndConstructed );
520 0 <= copyIndex;
521 --copyIndex )
522 {
523 newPointerArray[ copyIndex ] = pointerArray[ copyIndex ];
524 }
525 // now newCurrentPointersArray has copied all the contents of
526 // pointerArray, so it is OK to delete[] pointerArray:
527 delete[] pointerArray;
528 pointerArray = newPointerArray;
529 }
530
531 // next it is ensured that enough pointers point to constructed instances:
533 {
534 pointerArray[ ++indexOfEndConstructed ] = new StoredClass;
535 // the index is increased then the pointer at the incremented index is
536 // set to point at a new StoredClass instance.
537 }
538
539 return *this;
540 }

◆ newEnd()

template<typename StoredClass >
StoredClass & BOL::VectorlikeArray< StoredClass >::newEnd
inline

Definition at line 362 of file VectorlikeArray.hpp.

365 {
366 increaseSize( 1 );
368 }
VectorlikeArray< StoredClass > & increaseSize(int const numberToAdd=1)
StoredClass * unsafeGetPointer(int const soughtIndex)

◆ operator[]() [1/2]

template<typename StoredClass >
StoredClass & BOL::VectorlikeArray< StoredClass >::operator[] ( int const  soughtIndex)
inline

Definition at line 246 of file VectorlikeArray.hpp.

249 {
250 return *(unsafeGetPointer( soughtIndex ));
251 }

◆ operator[]() [2/2]

template<typename StoredClass >
StoredClass const & BOL::VectorlikeArray< StoredClass >::operator[] ( int const  soughtIndex) const
inline

Definition at line 255 of file VectorlikeArray.hpp.

258 {
259 return *(unsafeGetPointer( soughtIndex ));
260 }

◆ safeAt() [1/2]

template<typename StoredClass >
StoredClass & BOL::VectorlikeArray< StoredClass >::safeAt ( int const  soughtIndex)
inline

Definition at line 396 of file VectorlikeArray.hpp.

398 {
399 return getReference( soughtIndex );
400 }
StoredClass & getReference(int const soughtIndex)

◆ safeAt() [2/2]

template<typename StoredClass >
StoredClass const & BOL::VectorlikeArray< StoredClass >::safeAt ( int const  soughtIndex) const
inline

Definition at line 404 of file VectorlikeArray.hpp.

406 {
407 return getReference( soughtIndex );
408 }

◆ safeGetPointer() [1/2]

template<typename StoredClass >
StoredClass * BOL::VectorlikeArray< StoredClass >::safeGetPointer ( int const  soughtIndex)
inlineprotected

Definition at line 561 of file VectorlikeArray.hpp.

563 {
564 if( ( 0 <= soughtIndex )
565 &&
566 ( currentEndIndex >= soughtIndex ) )
567 {
568 return unsafeGetPointer( soughtIndex );
569 }
570 else
571 {
572 return NULL;
573 }
574 }

◆ safeGetPointer() [2/2]

template<typename StoredClass >
StoredClass const * BOL::VectorlikeArray< StoredClass >::safeGetPointer ( int const  soughtIndex) const
inlineprotected

Definition at line 578 of file VectorlikeArray.hpp.

580 {
581 if( ( 0 <= soughtIndex )
582 &&
583 ( currentEndIndex >= soughtIndex ) )
584 {
585 return unsafeGetPointer( soughtIndex );
586 }
587 else
588 {
589 return NULL;
590 }
591 }

◆ setSize()

template<typename StoredClass >
VectorlikeArray< StoredClass > & BOL::VectorlikeArray< StoredClass >::setSize ( int const  newSize)
inline

Definition at line 298 of file VectorlikeArray.hpp.

301 {
302 // first the conceptual end of the array is moved:
303 currentSizeOfArray = newSize;
304 currentEndIndex = ( newSize - 1 );
305
306 // then the array of pointers is ensured to be large enough:
308 {
309 if( !(0 < allocatedSizeOfArray ) )
310 {
312 }
313 else
314 {
316 {
318 // the array size is doubled if it gets increased, following the
319 // logic of the std::vector class.
320 }
321 }
322 // now allocatedSizeOfArray is large enough.
323
324 StoredClass**
325 newPointerArray = new StoredClass*[ allocatedSizeOfArray ];
326 // now newCurrentPointersArray is a new, larger array where the pointers
327 // can be put.
328
329 for( int copyIndex( indexOfEndConstructed );
330 0 <= copyIndex;
331 --copyIndex )
332 {
333 newPointerArray[ copyIndex ] = pointerArray[ copyIndex ];
334 }
335 // now newCurrentPointersArray has copied all the contents of
336 // pointerArray, so it is OK to delete[] pointerArray:
337 delete[] pointerArray;
338 pointerArray = newPointerArray;
339 }
340
341 // next it is ensured that enough pointers point to constructed instances:
343 {
345 pointerArray[ indexOfEndConstructed ] = new StoredClass;
346 }
347
348 return *this;
349 }

◆ unsafeGetPointer() [1/2]

template<typename StoredClass >
StoredClass * BOL::VectorlikeArray< StoredClass >::unsafeGetPointer ( int const  soughtIndex)
inlineprotected

Definition at line 544 of file VectorlikeArray.hpp.

546 {
547 return pointerArray[ soughtIndex ];
548 }

◆ unsafeGetPointer() [2/2]

template<typename StoredClass >
StoredClass const * BOL::VectorlikeArray< StoredClass >::unsafeGetPointer ( int const  soughtIndex) const
inlineprotected

Definition at line 552 of file VectorlikeArray.hpp.

555 {
556 return pointerArray[ soughtIndex ];
557 }

Member Data Documentation

◆ allocatedSizeOfArray

template<typename StoredClass >
int BOL::VectorlikeArray< StoredClass >::allocatedSizeOfArray
protected

Definition at line 139 of file VectorlikeArray.hpp.

◆ currentEndIndex

template<typename StoredClass >
int BOL::VectorlikeArray< StoredClass >::currentEndIndex
protected

Definition at line 146 of file VectorlikeArray.hpp.

◆ currentSizeOfArray

template<typename StoredClass >
int BOL::VectorlikeArray< StoredClass >::currentSizeOfArray
protected

Definition at line 144 of file VectorlikeArray.hpp.

◆ indexOfEndConstructed

template<typename StoredClass >
int BOL::VectorlikeArray< StoredClass >::indexOfEndConstructed
protected

Definition at line 141 of file VectorlikeArray.hpp.

◆ pointerArray

template<typename StoredClass >
StoredClass** BOL::VectorlikeArray< StoredClass >::pointerArray
protected

Definition at line 136 of file VectorlikeArray.hpp.


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