STK++ 0.9.13
STK::MemAllocator< Type_, Size_ > Struct Template Reference

template base class for all Allocator classes. More...

#include <STK_MemAllocator.h>

Inheritance diagram for STK::MemAllocator< Type_, Size_ >:
Inheritance graph

Public Types

enum  { isNumeric_ = hidden::IsArithmetic<Type_>::yes }
 
typedef hidden::MemHandler< Type_, Size_MemHandler
 
typedef hidden::MemChooser< isNumeric_, Type_ > MemChooser
 
typedef Type_ Type
 
typedef hidden::RemoveConst< Type >::Type constTypeConst
 
typedef TRange< Size_AllocatorRange
 

Public Member Functions

 MemAllocator ()
 Default constructor.
 
 MemAllocator (AllocatorRange const &I)
 constructor with specified Range
 
 MemAllocator (AllocatorRange const &I, Type const &value)
 constructor with specified Range and initial value
 
 MemAllocator (MemAllocator const &T, bool ref=false)
 Copy constructor.
 
template<int OtherSize_>
 MemAllocator (MemAllocator< Type, OtherSize_ > const &T, bool ref=false)
 Copy constructor.
 
template<int OtherSize_>
 MemAllocator (MemAllocator< Type, OtherSize_ > const &T, AllocatorRange const &I, bool ref=true)
 Copy constructor.
 
 MemAllocator (Type *const &q, Range const &I, bool ref)
 Wrapper or copy constructor.
 
 MemAllocator (Type *const &q, int size, bool ref)
 Wrapper or copy constructor: second form.
 
 ~MemAllocator ()
 destructor.
 
AllocatorRange constrange () const
 
int begin () const
 
int end () const
 
int size () const
 
Type *constp_data () const
 Get constant pointer on data.
 
void setValue (TypeConst value)
 This method allows to set a value to the allocator.
 
void setValue (int pos, TypeConst value)
 This method allows to set a value to the position pos.
 
TypeConst elt (int pos) const
 Get the const element number pos.
 
TypeConst operator[] (int i) const
 
Typeelt (int pos)
 Get the element number pos.
 
Typeoperator[] (int i)
 
void swap (int pos1, int pos2)
 swap two elements of the Allocator.
 
template<int OtherSize>
void malloc (TRange< OtherSize > const &I)
 main method for memory allocation.
 
template<int OtherSize>
void realloc (TRange< OtherSize > const &I)
 function for main ptr memory reallocation.
 
void free ()
 function for main ptr memory deallocation.
 
template<int OtherSize_, int RangeSize_>
void memcpy (int pos, MemAllocator< Type, OtherSize_ > const &T, TRange< RangeSize_ > const &range)
 function copying a part of allocator T in this.
 
template<int RangeSize_>
void memmove (int pos, TRange< RangeSize_ > const &range)
 function moving a part of the allocator.
 
void memmove (int pos, int begin, int size)
 function moving a part of the allocator.
 
void exchange (MemAllocator &T)
 exchange this with T.
 
MemAllocatorassign (MemAllocator const &T)
 copy the Allocator T by value.
 
template<int OtherSize_>
MemAllocatorassign (TRange< OtherSize_ > const &I, Type const &value)
 assign a value to allocator.
 
MemAllocatormove (MemAllocator const &T)
 move the Allocator T to this.
 
MemAllocatorshift (int first)
 shift the first index of the data to first.
 
void setPtr (Type *p_data, Range const &range, bool ref)
 Set address and range of allocated data.
 
template<int OtherSize_>
MemAllocator< Type, Size_ > & assign (TRange< OtherSize_ > const &I, Type const &value)
 
bool isRef () const
 
void setRef (bool ref) const
 Modify the container : can become a reference or the owner of the data.
 
- Public Member Functions inherited from STK::TRef<-1 >
bool isRef () const
 
bool ref () const
 
void exchange (TRef const &T)
 swap this with the container T.
 
void setRef (bool ref) const
 Modify the container : can become a reference or the owner of the data.
 

Protected Attributes

Typep_data_
 Main pointer on the data.
 

Private Member Functions

void shiftPtr (int inc)
 move main pointer on data
 
void forcedFree ()
 function for main ptr memory deallocation.
 

Private Attributes

AllocatorRange range_
 Range of the data.
 

Additional Inherited Members

- Protected Member Functions inherited from STK::TRef<-1 >
 TRef (bool ref)
 Default constructor We have to specify the member ref_.
 
 ~TRef ()
 destructor.
 

Detailed Description

template<typename Type_, int Size_>
struct STK::MemAllocator< Type_, Size_ >

template base class for all Allocator classes.

The MemAllocator class is the base class of all memory allocators. This class manages the main pointer on the data. It derives from the IContainerRef class as an array stored in memory can always be wrapped in some way or be a wrapper of some data stored in memory.

Template Parameters
Type_can be any type of data that can be stored in memory.
Size_size of the data if it is known at compile time

Definition at line 180 of file STK_MemAllocator.h.

Member Typedef Documentation

◆ AllocatorRange

template<typename Type_ , int Size_>
typedef TRange<Size_> STK::MemAllocator< Type_, Size_ >::AllocatorRange

Definition at line 189 of file STK_MemAllocator.h.

◆ MemChooser

template<typename Type_ , int Size_>
typedef hidden::MemChooser<isNumeric_, Type_> STK::MemAllocator< Type_, Size_ >::MemChooser

Definition at line 184 of file STK_MemAllocator.h.

◆ MemHandler

template<typename Type_ , int Size_>
typedef hidden::MemHandler<Type_, Size_> STK::MemAllocator< Type_, Size_ >::MemHandler

Definition at line 183 of file STK_MemAllocator.h.

◆ Type

template<typename Type_ , int Size_>
typedef Type_ STK::MemAllocator< Type_, Size_ >::Type

Definition at line 186 of file STK_MemAllocator.h.

◆ TypeConst

template<typename Type_ , int Size_>
typedef hidden::RemoveConst<Type>::Type const& STK::MemAllocator< Type_, Size_ >::TypeConst

Definition at line 187 of file STK_MemAllocator.h.

Member Enumeration Documentation

◆ anonymous enum

template<typename Type_ , int Size_>
anonymous enum

Constructor & Destructor Documentation

◆ MemAllocator() [1/8]

template<typename Type , int Size_>
STK::MemAllocator< Type, Size_ >::MemAllocator ( )

Default constructor.

Definition at line 412 of file STK_MemAllocator.h.

412 : IContainerRef(false)
413 , p_data_(0)
414 , range_()
415{ malloc(range_);}
TRef<-1 > IContainerRef
AllocatorRange range_
Range of the data.
void malloc(TRange< OtherSize > const &I)
main method for memory allocation.
Type * p_data_
Main pointer on the data.

References STK::MemAllocator< Type_, Size_ >::malloc(), and STK::MemAllocator< Type_, Size_ >::range_.

◆ MemAllocator() [2/8]

template<typename Type , int Size_>
STK::MemAllocator< Type, Size_ >::MemAllocator ( AllocatorRange const I)

constructor with specified Range

Parameters
Irange of the data

Definition at line 420 of file STK_MemAllocator.h.

421 : IContainerRef(false), p_data_(0), range_(I)
422{ malloc(I);}

References STK::MemAllocator< Type_, Size_ >::malloc().

◆ MemAllocator() [3/8]

template<typename Type , int Size_>
STK::MemAllocator< Type, Size_ >::MemAllocator ( AllocatorRange const I,
Type const value 
)

constructor with specified Range and initial value

Parameters
I,valuerange and value of the data

Definition at line 428 of file STK_MemAllocator.h.

429 : IContainerRef(false), p_data_(0), range_(I)
430{ malloc(I);
431 assign(I, value);
432}
MemAllocator & assign(MemAllocator const &T)
copy the Allocator T by value.

References STK::MemAllocator< Type_, Size_ >::assign(), and STK::MemAllocator< Type_, Size_ >::malloc().

◆ MemAllocator() [4/8]

template<typename Type , int Size_>
STK::MemAllocator< Type, Size_ >::MemAllocator ( MemAllocator< Type_, Size_ > const T,
bool  ref = false 
)

Copy constructor.

Parameters
Tthe array to copy or reference
refis this a wrapper of T ? (false by default)

Definition at line 441 of file STK_MemAllocator.h.

443 , p_data_(ref ? T.p_data(): 0)
444 , range_(T.range())
445{
446 if (!ref)
447 {
448 malloc(range());
449 memcpy(begin(), T, range());
450 }
451}
void memcpy(int pos, MemAllocator< Type, OtherSize_ > const &T, TRange< RangeSize_ > const &range)
function copying a part of allocator T in this.
AllocatorRange const & range() const

References STK::MemAllocator< Type_, Size_ >::begin(), STK::MemAllocator< Type_, Size_ >::malloc(), STK::MemAllocator< Type_, Size_ >::memcpy(), STK::MemAllocator< Type_, Size_ >::range(), and STK::TRef<-1 >::ref().

◆ MemAllocator() [5/8]

template<typename Type , int Size_>
template<int OtherSize_>
STK::MemAllocator< Type, Size_ >::MemAllocator ( MemAllocator< Type, OtherSize_ > const T,
bool  ref = false 
)

Copy constructor.

Copy data or create a reference.

Parameters
Tthe array to copy or reference
refis this a wrapper of T ? (false by default)

Definition at line 461 of file STK_MemAllocator.h.

463 , p_data_(ref ? T.p_data(): 0)
464 , range_(T.range())
465{
466 if (!ref)
467 {
468 malloc(range());
469 memcpy(begin(), T, range());
470 }
471}

References STK::MemAllocator< Type_, Size_ >::begin(), STK::MemAllocator< Type_, Size_ >::malloc(), STK::MemAllocator< Type_, Size_ >::memcpy(), STK::MemAllocator< Type_, Size_ >::range(), and STK::TRef<-1 >::ref().

◆ MemAllocator() [6/8]

template<typename Type , int Size_>
template<int OtherSize_>
STK::MemAllocator< Type, Size_ >::MemAllocator ( MemAllocator< Type, OtherSize_ > const T,
AllocatorRange const I,
bool  ref = true 
)

Copy constructor.

Map a range of T.

Parameters
T,Ithe allocator and range to reference
refis this a wrapper of a part of T ? (true by default)

Definition at line 477 of file STK_MemAllocator.h.

478 : IContainerRef(true)
479 , p_data_(ref ? T.p_data() : 0)
480 , range_(I)
481{
482 if (!ref)
483 {
484 malloc(I);
485 for(int i=I.begin(); i< I.end(); ++i)
486 { p_data_[i] = T.elt(i);}
487 }
488}

References STK::MemAllocator< Type_, Size_ >::malloc(), STK::MemAllocator< Type_, Size_ >::p_data_, and STK::TRef<-1 >::ref().

◆ MemAllocator() [7/8]

template<typename Type , int Size_>
STK::MemAllocator< Type, Size_ >::MemAllocator ( Type *const q,
Range const I,
bool  ref 
)

Wrapper or copy constructor.

Parameters
q,Iptr and range of the data to wrap
refis this a wrapper ? If true data will not be freed when this object is released

Definition at line 496 of file STK_MemAllocator.h.

498{ /* derived class have to delete data if ref==false */}

◆ MemAllocator() [8/8]

template<typename Type , int Size_>
STK::MemAllocator< Type, Size_ >::MemAllocator ( Type *const q,
int  size,
bool  ref 
)

Wrapper or copy constructor: second form.

This constructor assumes the data as a C-like array. Thus first index is 0.

Parameters
q,sizeptr and size of the data to wrap
refis this a wrapper ? If true data will not be freed when this object is released

Definition at line 507 of file STK_MemAllocator.h.

509{ /* derived class have to copy the data if ref==false */}
TRange< Size_ > AllocatorRange

◆ ~MemAllocator()

template<typename Type , int Size_>
STK::MemAllocator< Type, Size_ >::~MemAllocator ( )

destructor.

Release memory.

Definition at line 513 of file STK_MemAllocator.h.

514{ forcedFree();}
void forcedFree()
function for main ptr memory deallocation.

Member Function Documentation

◆ assign() [1/3]

template<typename Type , int Size_>
MemAllocator< Type, Size_ > & STK::MemAllocator< Type, Size_ >::assign ( MemAllocator< Type_, Size_ > const T)

copy the Allocator T by value.

The memory is free and the Allocator T is physically copied in this.

Parameters
Tthe allocator to copy by value
Returns
a copy of T

Definition at line 532 of file STK_MemAllocator.h.

533{
534 // allocate memory if necessary
535 malloc(T.range_);
536 memcpy(begin(), T, range());
537 return *this;
538}

Referenced by STK::MemAllocator< Type_, Size_ >::MemAllocator().

◆ assign() [2/3]

template<typename Type_ , int Size_>
template<int OtherSize_>
MemAllocator & STK::MemAllocator< Type_, Size_ >::assign ( TRange< OtherSize_ > const I,
Type const value 
)

assign a value to allocator.

Parameters
I,valuerange and value to assign
Returns
a copy

◆ assign() [3/3]

template<typename Type_ , int Size_>
template<int OtherSize_>
MemAllocator< Type, Size_ > & STK::MemAllocator< Type_, Size_ >::assign ( TRange< OtherSize_ > const I,
Type const value 
)

Definition at line 543 of file STK_MemAllocator.h.

544{
545 for (int pos= I.begin(); pos < I.end(); ++pos) { p_data_[pos] = value;}
546 return *this;
547}

◆ begin()

◆ elt() [1/2]

template<typename Type_ , int Size_>
Type & STK::MemAllocator< Type_, Size_ >::elt ( int  pos)
inline

Get the element number pos.

Parameters
posthe position of the element we get

Definition at line 290 of file STK_MemAllocator.h.

290{ return p_data_[pos];}

References STK::MemAllocator< Type_, Size_ >::p_data_.

◆ elt() [2/2]

template<typename Type_ , int Size_>
TypeConst STK::MemAllocator< Type_, Size_ >::elt ( int  pos) const
inline

◆ end()

◆ exchange()

template<typename Type , int Size_>
void STK::MemAllocator< Type, Size_ >::exchange ( MemAllocator< Type_, Size_ > &  T)

exchange this with T.

Parameters
Tthe container to exchange with T

Definition at line 520 of file STK_MemAllocator.h.

521{
522 std::swap(p_data_, T.p_data_);
523 std::swap(range_, T.range_);
525}
void exchange(TRef const &T)
swap this with the container T.

References STK::TRef<-1 >::exchange().

◆ forcedFree()

template<typename Type_ , int Size_>
void STK::MemAllocator< Type_, Size_ >::forcedFree ( )
inlineprivate

function for main ptr memory deallocation.

Force memory deallocation, even for fixed size allocators.

Definition at line 403 of file STK_MemAllocator.h.

404 {
405 if(!isRef())
407 }
static Type_ * free(Type_ *p_data, AllocatorRange const &range)
do nothing for fixed size allocators !

References STK::hidden::MemHandler< Type_, Size_ >::free(), STK::MemAllocator< Type_, Size_ >::isRef(), STK::MemAllocator< Type_, Size_ >::p_data_, and STK::MemAllocator< Type_, Size_ >::range_.

◆ free()

template<typename Type , int Size_>
void STK::MemAllocator< Type, Size_ >::free ( )

function for main ptr memory deallocation.

Definition at line 626 of file STK_MemAllocator.h.

627{
628 // nothing to do for reference
629 if (isRef()) return;
631 // if there is no elements range_ is set to default
632 if (!p_data_) { range_ = AllocatorRange();}
633}

◆ isRef()

template<typename Type_ , int Size_>
bool STK::TRef<-1 >::isRef ( ) const
inline
Returns
true if *this is reference container, false otherwise

Definition at line 81 of file STK_IContainerRef.h.

81{ return ref_;}
bool ref_
Is it a "true" container or a wrapper ? ref_ should be false if this own its own data,...

Referenced by STK::MemAllocator< Type_, Size_ >::forcedFree(), and STK::IArray2D< Derived >::isRef().

◆ malloc()

template<typename Type , int Size_>
template<int OtherSize>
void STK::MemAllocator< Type, Size_ >::malloc ( TRange< OtherSize > const I)

main method for memory allocation.

Parameters
Irange of the data allocated

Definition at line 581 of file STK_MemAllocator.h.

582{
583 // there is no necessity to allocate if data is already allocated, range_
584 // is the same and the data is not owned by an other allocator
585 if ((range_ == I)&&(p_data_)&&(!isRef())) return;
586 // allocate memory
587 try
588 {
589 // free any existing data and allocate it again (do nothing for fixed size allocators)
592 setPtr(p_data_, I, false);
593 }
594 catch (std::bad_alloc const& error)
595 {
596 setPtr(0, AllocatorRange(), false);
597 STKRUNTIME_ERROR_1ARG(MemAllocator::malloc, I, memory allocation failed);
598 }
599}
#define STKRUNTIME_ERROR_1ARG(Where, Arg, Error)
Definition STK_Macros.h:129
void setPtr(Type *p_data, Range const &range, bool ref)
Set address and range of allocated data.
static Type_ * malloc(Type_ *p_data, AllocatorRange const &range)
malloc memory.

References STK::IRunnerBase::error(), STK::MemAllocator< Type_, Size_ >::malloc(), and STKRUNTIME_ERROR_1ARG.

Referenced by STK::MemAllocator< Type_, Size_ >::malloc(), STK::MemAllocator< Type_, Size_ >::MemAllocator(), STK::MemAllocator< Type_, Size_ >::MemAllocator(), STK::MemAllocator< Type_, Size_ >::MemAllocator(), STK::MemAllocator< Type_, Size_ >::MemAllocator(), STK::MemAllocator< Type_, Size_ >::MemAllocator(), and STK::MemAllocator< Type_, Size_ >::MemAllocator().

◆ memcpy()

template<typename Type , int Size_>
template<int OtherSize_, int RangeSize_>
void STK::MemAllocator< Type, Size_ >::memcpy ( int  pos,
MemAllocator< Type, OtherSize_ > const T,
TRange< RangeSize_ > const range 
)

function copying a part of allocator T in this.

Parameters
posposition where will be copied data
T,rangethe array of data and the range of the data to copy

Definition at line 637 of file STK_MemAllocator.h.

638{
639 if (range.size() <= 0) return;
640#ifdef STK_BOUNDS_CHECK
641 if (pos < begin()) { STKOUT_OF_RANGE_1ARG(MemAllocator::memcpy,pos,begin() > pos);}
642 if (pos >= end()) { STKOUT_OF_RANGE_1ARG(MemAllocator::memcpy,pos,end() <= pos);}
643 if (!T.range().isContaining(range))
644 { STKOUT_OF_RANGE_1ARG(MemAllocator::memcopy,range,range not in T.range());}
645#endif
646 MemChooser::memcpy(p_data_+pos, T.p_data()+range.begin(), range.size());
647}

References STK::MemAllocator< Type_, Size_ >::memcpy(), and STKOUT_OF_RANGE_1ARG.

Referenced by STK::MemAllocator< Type_, Size_ >::MemAllocator(), STK::MemAllocator< Type_, Size_ >::MemAllocator(), and STK::MemAllocator< Type_, Size_ >::memcpy().

◆ memmove() [1/2]

template<typename Type , int Size_>
void STK::MemAllocator< Type, Size_ >::memmove ( int  pos,
int  begin,
int  size 
)

function moving a part of the allocator.

Parameters
pos,begin,sizerange in form [begin,begin+size) to move at position pos

Definition at line 650 of file STK_MemAllocator.h.

651{
652 if ((size <= 0)||(start == pos)) return;
653#ifdef STK_BOUNDS_CHECK
654 if (pos < begin())
656 if (pos >= end())
658 if (!range_.isContaining(Range(start,size)))
660#endif
661 MemChooser::memmove( p_data_+pos, p_data_+ start, size);
662}
#define STKOUT_OF_RANGE_2ARG(Where, Arg1, Arg2, Error)
Definition STK_Macros.h:102
TRange< UnknownSize > Range
Definition STK_Range.h:59
void memmove(int pos, TRange< RangeSize_ > const &range)
function moving a part of the allocator.

References STK::MemAllocator< Type_, Size_ >::begin(), STK::MemAllocator< Type_, Size_ >::end(), STK::MemAllocator< Type_, Size_ >::memmove(), STKOUT_OF_RANGE_1ARG, and STKOUT_OF_RANGE_2ARG.

◆ memmove() [2/2]

template<typename Type , int Size_>
template<int RangeSize_>
void STK::MemAllocator< Type, Size_ >::memmove ( int  pos,
TRange< RangeSize_ > const range 
)

function moving a part of the allocator.

Parameters
pos,rangerange in form [begin,end) to move at position pos

Definition at line 666 of file STK_MemAllocator.h.

667{
668 if ((range.size() <= 0)||(range.begin() == pos)) return;
669#ifdef STK_BOUNDS_CHECK
670 if (pos < begin())
672 if (pos >= end())
674 if (!range_.isContaining(range))
676#endif
677 MemChooser::memmove( p_data_+pos, p_data_+range.begin(), range.size());
678}

References STK::MemAllocator< Type_, Size_ >::begin(), STK::MemAllocator< Type_, Size_ >::end(), STK::MemAllocator< Type_, Size_ >::memmove(), and STKOUT_OF_RANGE_1ARG.

Referenced by STK::MemAllocator< Type_, Size_ >::memmove(), and STK::MemAllocator< Type_, Size_ >::memmove().

◆ move()

template<typename Type , int Size_>
MemAllocator< Type, Size_ > & STK::MemAllocator< Type, Size_ >::move ( MemAllocator< Type_, Size_ > const T)

move the Allocator T to this.

The memory of this is freed and T becomes a reference of this. This method allow to move the data of T to this without using physical copy.

Parameters
Tthe allocator to move to this
Returns
this object.
Note
the data member ref_ is mutable so that T can be passed as a constant reference.

Definition at line 558 of file STK_MemAllocator.h.

559{
560 if (this == &T) return *this;
561 forcedFree();
562 setPtr(T.p_data_, T.range_, T.isRef());
563 T.setRef(true); // T become a reference of the data it own
564 return *this;
565}

◆ operator[]() [1/2]

template<typename Type_ , int Size_>
Type & STK::MemAllocator< Type_, Size_ >::operator[] ( int  i)
inline
Returns
ith element
Parameters
iindex of the element to get

Definition at line 294 of file STK_MemAllocator.h.

294{ return elt(i);}

References STK::MemAllocator< Type_, Size_ >::elt().

◆ operator[]() [2/2]

template<typename Type_ , int Size_>
TypeConst STK::MemAllocator< Type_, Size_ >::operator[] ( int  i) const
inline
Returns
a constant reference on the ith element
Parameters
iindex of the element to get

Definition at line 286 of file STK_MemAllocator.h.

286{ return elt(i);}

References STK::MemAllocator< Type_, Size_ >::elt().

◆ p_data()

template<typename Type_ , int Size_>
Type *const & STK::MemAllocator< Type_, Size_ >::p_data ( ) const
inline

Get constant pointer on data.

Definition at line 246 of file STK_MemAllocator.h.

246{ return p_data_;}

References STK::MemAllocator< Type_, Size_ >::p_data_.

Referenced by STK::IArray2D< Derived >::merge(), and STK::MemAllocator< Type_, Size_ >::setPtr().

◆ range()

template<typename Type_ , int Size_>
AllocatorRange const & STK::MemAllocator< Type_, Size_ >::range ( ) const
inline

◆ realloc()

template<typename Type , int Size_>
template<int OtherSize>
void STK::MemAllocator< Type, Size_ >::realloc ( TRange< OtherSize > const I)

function for main ptr memory reallocation.

If the size requested is greater than the allocated size, the Type stored are saved and copied using the operator=. the Type class have to provide this operator.

If the size requested is lesser than the allocated size, only the first elements fitting in the container are copied.

Parameters
Irange of the data to reserve

Definition at line 603 of file STK_MemAllocator.h.

604{
605 // there is no necessity to allocate if data is already allocated, range_
606 // is the same and the data is not owned by an other allocator
607 if ((range_ == I)&&(p_data_)&&(!isRef())) return;
608
609 try
610 {
611 // allocate memory and copy data in the same range
613 // copy data in common range
614 Range r = inf(range_, I);
615 if (r.size()>0)
616 { MemChooser::memcpy(p+r.begin(), p_data_+r.begin(), r.size()); }
617// for (int i = r.begin(); i<r.end(); ++i) { p[i] = p_data_[i];}
619 setPtr(p, I, false);
620 }
621 catch (std::bad_alloc const& error)
622 { STKRUNTIME_ERROR_1ARG(MemAllocator::realloc, I, memory allocation failed);}
623}
Range inf(TRange< SizeI_ > const &I, TRange< SizeJ_ > const &J)
compute inf(I,J).
Definition STK_Range.h:477
void realloc(TRange< OtherSize > const &I)
function for main ptr memory reallocation.

References STK::RangeBase< Derived >::begin(), STK::IRunnerBase::error(), STK::inf(), STK::MemAllocator< Type_, Size_ >::realloc(), STK::TRange< UnknownSize >::size(), and STKRUNTIME_ERROR_1ARG.

Referenced by STK::MemAllocator< Type_, Size_ >::realloc().

◆ setPtr()

template<typename Type_ , int Size_>
void STK::MemAllocator< Type_, Size_ >::setPtr ( Type p_data,
Range const range,
bool  ref 
)
inline

Set address and range of allocated data.

This method is to be used when the memory have been allocated outside. If allocator wrap allocated memory, it is not freed.

Parameters
p_datathe address to set
rangerange of the data
refis p_data_ a wrapper ?

Definition at line 382 of file STK_MemAllocator.h.

Type *const & p_data() const
Get constant pointer on data.
void setRef(bool ref) const
Modify the container : can become a reference or the owner of the data.

References STK::MemAllocator< Type_, Size_ >::p_data(), STK::MemAllocator< Type_, Size_ >::p_data_, STK::MemAllocator< Type_, Size_ >::range(), STK::MemAllocator< Type_, Size_ >::range_, STK::TRef<-1 >::ref(), and STK::MemAllocator< Type_, Size_ >::setRef().

◆ setRef()

template<typename Type_ , int Size_>
void STK::TRef<-1 >::setRef ( bool  ref) const
inline

Modify the container : can become a reference or the owner of the data.

To use with care if we want to avoid memory leak.

Parameters
ref: false if this own its own data.

Definition at line 92 of file STK_IContainerRef.h.

92{ ref_ = ref;}

Referenced by STK::MemAllocator< Type_, Size_ >::setPtr().

◆ setValue() [1/2]

template<typename Type_ , int Size_>
void STK::MemAllocator< Type_, Size_ >::setValue ( int  pos,
TypeConst  value 
)
inline

This method allows to set a value to the position pos.

Parameters
pos,valueindex and value to set

Definition at line 259 of file STK_MemAllocator.h.

260 {
261#ifdef STK_BOUNDS_CHECK
262 if (pos < begin())
264 if (pos >= end())
266#endif
267 p_data_[pos] = value;
268 }

References STK::MemAllocator< Type_, Size_ >::begin(), STK::MemAllocator< Type_, Size_ >::elt(), STK::MemAllocator< Type_, Size_ >::end(), STK::MemAllocator< Type_, Size_ >::p_data_, and STKOUT_OF_RANGE_1ARG.

◆ setValue() [2/2]

template<typename Type_ , int Size_>
void STK::MemAllocator< Type_, Size_ >::setValue ( TypeConst  value)
inline

This method allows to set a value to the allocator.

Parameters
valuevalue to set

Definition at line 251 of file STK_MemAllocator.h.

252 {
253 for(int pos=begin(); pos < end(); ++pos)
254 { p_data_[pos] = value;}
255 }

References STK::MemAllocator< Type_, Size_ >::begin(), STK::MemAllocator< Type_, Size_ >::end(), and STK::MemAllocator< Type_, Size_ >::p_data_.

◆ shift()

template<typename Type , int Size_>
MemAllocator< Type, Size_ > & STK::MemAllocator< Type, Size_ >::shift ( int  first)

shift the first index of the data to first.

Parameters
firstthe index of the first data to set

Definition at line 567 of file STK_MemAllocator.h.

568{
569 // check if there is something to do
570 if (first == begin()) return *this;
571 // check for reference
572 if (isRef())
573 STKRUNTIME_ERROR_1ARG(MemAllocator::shift,first,cannot operate on reference);
574 // translate data
575 shiftPtr(first - begin());
576 return *this;
577}
MemAllocator & shift(int first)
shift the first index of the data to first.
void shiftPtr(int inc)
move main pointer on data

References STK::MemAllocator< Type_, Size_ >::shift(), and STKRUNTIME_ERROR_1ARG.

Referenced by STK::MemAllocator< Type_, Size_ >::shift().

◆ shiftPtr()

template<typename Type_ , int Size_>
void STK::MemAllocator< Type_, Size_ >::shiftPtr ( int  inc)
inlineprivate

move main pointer on data

Parameters
incthe increment to apply

Definition at line 395 of file STK_MemAllocator.h.

396 {
397 if (p_data_) { p_data_ -= inc;}
398 range_.inc(inc);
399 }

References STK::MemAllocator< Type_, Size_ >::p_data_, and STK::MemAllocator< Type_, Size_ >::range_.

◆ size()

template<typename Type_ , int Size_>
int STK::MemAllocator< Type_, Size_ >::size ( ) const
inline
Returns
the size of the data

Definition at line 243 of file STK_MemAllocator.h.

243{ return range_.size();}

References STK::MemAllocator< Type_, Size_ >::range_.

Referenced by STK::IArray2D< Derived >::availableCols().

◆ swap()

template<typename Type_ , int Size_>
void STK::MemAllocator< Type_, Size_ >::swap ( int  pos1,
int  pos2 
)
inline

swap two elements of the Allocator.

Parameters
pos1,pos2the positions to swap

Definition at line 298 of file STK_MemAllocator.h.

299 {
300#ifdef STK_BOUNDS_CHECK
301 if (begin() > pos1) { STKOUT_OF_RANGE_2ARG(MemAllocator::swap, pos1, pos2, begin() > pos1);}
302 if (begin() > pos2) { STKOUT_OF_RANGE_2ARG(MemAllocator::swap, pos1, pos2, begin() > pos2);}
303 if (end() <= pos1) { STKOUT_OF_RANGE_2ARG(MemAllocator::swap[], pos1, pos2, end() <= pos1);}
304 if (end() <= pos2) { STKOUT_OF_RANGE_2ARG(MemAllocator::swap[], pos1, pos2, end() <= pos2);}
305#endif
306 std::swap(p_data_[pos1], p_data_[pos2]);
307 }
void swap(int pos1, int pos2)
swap two elements of the Allocator.

References STK::MemAllocator< Type_, Size_ >::begin(), STK::MemAllocator< Type_, Size_ >::end(), STK::MemAllocator< Type_, Size_ >::p_data_, STKOUT_OF_RANGE_2ARG, and STK::MemAllocator< Type_, Size_ >::swap().

Referenced by STK::MemAllocator< Type_, Size_ >::swap(), and STK::IArray2D< Derived >::swapCols().

Member Data Documentation

◆ p_data_

◆ range_


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