DATAKIT API  V2025.4
Dtk_tab< T > Class Template Reference

This is a high level array class. More...

Public Types

typedef const_pointer const_iterator
 
typedef T const * const_pointer
 
typedef pointer iterator
 
typedef T * pointer
 
typedef T value_type
 

Public Member Functions

T & at (Dtk_Size_t k)
 
const T & at (Dtk_Size_t k) const
 
T & back ()
 Return the elements at the end of the array. More...
 
const T & back () const
 Return the elements at the end of the array. More...
 
iterator begin ()
 
const_iterator begin () const
 
Dtk_Size_t capacity () const
 Returns the size of the storage space currently allocated for the array, expressed in terms of elements. More...
 
const_iterator cbegin () const
 
const_iterator cend () const
 
void clear (int no_delete=0)
 Resets the Dtk_tab content. More...
 
T * data ()
 
T const * data () const
 
 Dtk_tab ()
 Default constructor. More...
 
 Dtk_tab (const Dtk_tab< T > &t)
 
 Dtk_tab (Dtk_Size_t initreservesize, int resize=0)
 
 Dtk_tab (Dtk_tab< T > &&t) DTK_NOEXCEPT
 Move constructor. More...
 
iterator end ()
 
const_iterator end () const
 
int find (const T &e) const
 
template<typename comp >
int find (const T &e, const comp &C) const
 
T & front ()
 Return the elements at the beginning of the array. More...
 
const T & front () const
 Return the elements at the beginning of the array. More...
 
const T * GetArray () const
 Returns array of T elements. More...
 
Dtk_Size_t GetSize () const
 
max_element () const
 
Dtk_Size_t max_ithelement ()
 
min_element () const
 
Dtk_Size_t min_ithelement ()
 
Dtk_taboperator+= (const Dtk_tab &t)
 
Dtk_taboperator+= (Dtk_tab &&t)
 
int operator< (const Dtk_tab< T > &t) const
 
Dtk_taboperator= (const Dtk_tab< T > &t)
 
Dtk_tab< T > & operator= (Dtk_tab< T > &&t) DTK_NOEXCEPT
 Move assignment operator. More...
 
int operator== (const Dtk_tab< T > &t) const
 
T & operator[] (Dtk_Size_t k)
 Accesses the ith element - like a classic array -. More...
 
const T & operator[] (Dtk_Size_t k) const
 
void pop_back ()
 Removes the last element. More...
 
void push_back (const T &x)
 Inserts an element at the end of the array. More...
 
void push_back (T &&x)
 Inserts an element by moving it at the end of the array. More...
 
void reduce ()
 
void remove (const T &a)
 Removes the first element with the value a. More...
 
void reserve (Dtk_Size_t n)
 
void resize (Dtk_Size_t n)
 
void resize (Dtk_Size_t n, const T &t)
 Resizes the array. More...
 
void reverse ()
 
Dtk_Size_t size () const
 Returns the size of the array. More...
 
void sort ()
 Swap two elements. More...
 
template<typename comp >
void sort (const comp &C)
 Sorts the array with custom sorting. More...
 
Dtk_tab subtab (Dtk_Size_t a, Dtk_Size_t b)
 
void swap (const Dtk_Size_t inA, const Dtk_Size_t inB)
 Sorts the array. More...
 
 ~Dtk_tab ()
 

Detailed Description

template<typename T>
class Dtk_tab< T >

This is a high level array class.

This class lets you use optimized arrays.

Member Typedef Documentation

◆ const_iterator

template<typename T >
typedef const_pointer Dtk_tab< T >::const_iterator

◆ const_pointer

template<typename T >
typedef T const* Dtk_tab< T >::const_pointer

◆ iterator

template<typename T >
typedef pointer Dtk_tab< T >::iterator

◆ pointer

template<typename T >
typedef T* Dtk_tab< T >::pointer

◆ value_type

template<typename T >
typedef T Dtk_tab< T >::value_type

Constructor & Destructor Documentation

◆ Dtk_tab() [1/4]

template<typename T >
Dtk_tab< T >::Dtk_tab ( )

Default constructor.

Remarks
create an empty array

◆ Dtk_tab() [2/4]

template<typename T >
Dtk_tab< T >::Dtk_tab ( Dtk_Size_t  initreservesize,
int  resize = 0 
)

◆ ~Dtk_tab()

template<typename T >
Dtk_tab< T >::~Dtk_tab ( )

◆ Dtk_tab() [3/4]

template<typename T >
Dtk_tab< T >::Dtk_tab ( const Dtk_tab< T > &  t)

◆ Dtk_tab() [4/4]

template<typename T >
Dtk_tab< T >::Dtk_tab ( Dtk_tab< T > &&  t)

Move constructor.

Parameters
tthe Dtk_tab to move

Member Function Documentation

◆ at() [1/2]

template<typename T >
T& Dtk_tab< T >::at ( Dtk_Size_t  k)

◆ at() [2/2]

template<typename T >
const T& Dtk_tab< T >::at ( Dtk_Size_t  k) const

◆ back() [1/2]

template<typename T >
T& Dtk_tab< T >::back ( )

Return the elements at the end of the array.

Sample:

Dtk_tab<int> L; //we construct an array of int.
L.push_back(5);
L.push_back(35);
L.push_back(8); // array is now : 5 - 35 - 8
int a = L.back(); // a is 8

◆ back() [2/2]

template<typename T >
const T& Dtk_tab< T >::back ( ) const

Return the elements at the end of the array.

Sample:

Dtk_tab<int> L; //we construct an array of int.
L.push_back(5);
L.push_back(35);
L.push_back(8); // array is now : 5 - 35 - 8
int a = L.back(); // a is 8

◆ begin() [1/2]

template<typename T >
iterator Dtk_tab< T >::begin ( )

◆ begin() [2/2]

template<typename T >
const_iterator Dtk_tab< T >::begin ( ) const

◆ capacity()

template<typename T >
Dtk_Size_t Dtk_tab< T >::capacity ( ) const

Returns the size of the storage space currently allocated for the array, expressed in terms of elements.

This capacity is not necessarily equal to the size. It can be equal or greater. The capacity of the Dtk_tab can be explicitly altered by calling member Dtk_tab::reserve.

Sample:

Dtk_tab<int> tab; //we construct an array of int.
tab.reserve(5); //we reserve 5 element of type int.
tab.push_back(0); //we insert '0'
tab.push_back(2); //we insert '2'
tab.push_back(1); //we insert '1'
Dtk_Size_t size = tab.size(); //size is equal to 3
Dtk_Size_t capacity = tab.capacity(); //capacity is equal to 5

◆ cbegin()

template<typename T >
const_iterator Dtk_tab< T >::cbegin ( ) const

◆ cend()

template<typename T >
const_iterator Dtk_tab< T >::cend ( ) const

◆ clear()

template<typename T >
void Dtk_tab< T >::clear ( int  no_delete = 0)

Resets the Dtk_tab content.

Remarks
If the Dtk_tab has pointers, theses ones aren't deleted.

Sample:

Dtk_tab<int> tab; //we construct an array of int.
tab.push_back(0); //we insert '0'
tab.push_back(2); //we insert '2'
tab.push_back(1); //we insert '1'
Now tab has 3 elements...
tab.clear(); //Now tab hasn't any element.

◆ data() [1/2]

template<typename T >
T* Dtk_tab< T >::data ( )

◆ data() [2/2]

template<typename T >
T const* Dtk_tab< T >::data ( ) const

◆ end() [1/2]

template<typename T >
iterator Dtk_tab< T >::end ( )

◆ end() [2/2]

template<typename T >
const_iterator Dtk_tab< T >::end ( ) const

◆ find() [1/2]

template<typename T >
int Dtk_tab< T >::find ( const T &  e) const

◆ find() [2/2]

template<typename T >
template<typename comp >
int Dtk_tab< T >::find ( const T &  e,
const comp &  C 
) const

◆ front() [1/2]

template<typename T >
T& Dtk_tab< T >::front ( )

Return the elements at the beginning of the array.

Sample:

Dtk_tab<int> L; //we construct a list of array.
L.push_back(5);
L.push_back(35);
L.push_back(8); // array is now : 5 - 35 - 8
int a = L.front(); // a is 5

◆ front() [2/2]

template<typename T >
const T& Dtk_tab< T >::front ( ) const

Return the elements at the beginning of the array.

Sample:

Dtk_tab<int> L; //we construct a list of array.
L.push_back(5);
L.push_back(35);
L.push_back(8); // array is now : 5 - 35 - 8
int a = L.front(); // a is 5

◆ GetArray()

template<typename T >
const T* Dtk_tab< T >::GetArray ( ) const

Returns array of T elements.

Remarks
You should call size () method to know returned array size.

◆ GetSize()

template<typename T >
Dtk_Size_t Dtk_tab< T >::GetSize ( ) const

◆ max_element()

template<typename T >
T Dtk_tab< T >::max_element ( ) const

◆ max_ithelement()

template<typename T >
Dtk_Size_t Dtk_tab< T >::max_ithelement ( )

◆ min_element()

template<typename T >
T Dtk_tab< T >::min_element ( ) const

◆ min_ithelement()

template<typename T >
Dtk_Size_t Dtk_tab< T >::min_ithelement ( )

◆ operator+=() [1/2]

template<typename T >
Dtk_tab& Dtk_tab< T >::operator+= ( const Dtk_tab< T > &  t)

◆ operator+=() [2/2]

template<typename T >
Dtk_tab& Dtk_tab< T >::operator+= ( Dtk_tab< T > &&  t)

◆ operator<()

template<typename T >
int Dtk_tab< T >::operator< ( const Dtk_tab< T > &  t) const

◆ operator=() [1/2]

template<typename T >
Dtk_tab& Dtk_tab< T >::operator= ( const Dtk_tab< T > &  t)

◆ operator=() [2/2]

template<typename T >
Dtk_tab<T>& Dtk_tab< T >::operator= ( Dtk_tab< T > &&  t)

Move assignment operator.

Parameters
tthe Dtk_tab to move

◆ operator==()

template<typename T >
int Dtk_tab< T >::operator== ( const Dtk_tab< T > &  t) const

◆ operator[]() [1/2]

template<typename T >
T& Dtk_tab< T >::operator[] ( Dtk_Size_t  k)

Accesses the ith element - like a classic array -.

Parameters
[in]k: The element position.
Warning
There isn't any check for the element position validity !!!

Sample:

Dtk_tab<int> tab; //we construct an array of int.
tab.push_back(0); //we insert '0'
tab.push_back(2); //we insert '2'
tab.push_back(1); //we insert '1'
// tab is {0,2,1}
int elt = tab[2]; //elt is equal to 1
tab[1] = 5; // tab is {0,5,1}
tab[5] = 5; // Error !!! The program will crash :(

◆ operator[]() [2/2]

template<typename T >
const T& Dtk_tab< T >::operator[] ( Dtk_Size_t  k) const

◆ pop_back()

template<typename T >
void Dtk_tab< T >::pop_back ( )

Removes the last element.

Sample:

Dtk_tab<int> tab; //we construct an array of int.
tab.push_back(0); //we insert '0'
tab.push_back(2); //we insert '2'
tab.push_back(1); //we insert '1'
Now tab is {0,2,1}...

◆ push_back() [1/2]

template<typename T >
void Dtk_tab< T >::push_back ( const T &  x)

Inserts an element at the end of the array.

Parameters
[in]xThe element to insert.

Sample:

Dtk_tab<int> tab; //we construct an array of int.
tab.push_back(0); //we insert '0'
tab.push_back(2); //we insert '2'
tab.push_back(1); //we insert '1'
Now tab is {0,2,1}...

◆ push_back() [2/2]

template<typename T >
void Dtk_tab< T >::push_back ( T &&  x)

Inserts an element by moving it at the end of the array.

Parameters
[in]xThe element to insert.

Sample:

Dtk_tab<int> tab; //we construct an array of int.
tab.push_back(0); //we insert '0'
tab.push_back(2); //we insert '2'
tab.push_back(1); //we insert '1'
Now tab is {0,2,1}...

◆ reduce()

template<typename T >
void Dtk_tab< T >::reduce ( )

◆ remove()

template<typename T >
void Dtk_tab< T >::remove ( const T &  a)

Removes the first element with the value a.

Parameters
[in]aThe value of the element that should be removed
Remarks
: The order of the elements of the tab won't be conserved, the last element is moved to the old position of the removed element

Sample:

Dtk_tab<int> tab; //we construct an array of int.
tab.push_back(0); //we insert '0'
tab.push_back(1); //we insert '1'
tab.push_back(2); //we insert '2'
tab.push_back(3); //we insert '3'
tab.remove(1); //Now tab is {0,3,2}
tab.remove(2); //Now tab is {0,3}

◆ reserve()

template<typename T >
void Dtk_tab< T >::reserve ( Dtk_Size_t  n)

◆ resize() [1/2]

template<typename T >
void Dtk_tab< T >::resize ( Dtk_Size_t  n)

◆ resize() [2/2]

template<typename T >
void Dtk_tab< T >::resize ( Dtk_Size_t  n,
const T &  t 
)

Resizes the array.

Parameters
[in]nThe new size.
[in]tThe filling element.
Remarks
If the new size is lower than the old one, the last elements are removed.
If the new size is greater than the old one, inserts t in the new elements.

Sample:

Dtk_tab<int> tab; //we construct an array of int.
tab.push_back(0); //we insert '0'
tab.push_back(2); //we insert '2'
tab.push_back(1); //we insert '1'
tab.resize(2); //Now tab is {0,2}
tab.resize(5,6); //Now tab is {0,2,6,6,6}

◆ reverse()

template<typename T >
void Dtk_tab< T >::reverse ( )

◆ size()

template<typename T >
Dtk_Size_t Dtk_tab< T >::size ( ) const

Returns the size of the array.

Sample:

Dtk_tab<int> tab; //we construct an array of int.
tab.push_back(0); //we insert '0'
tab.push_back(2); //we insert '2'
tab.push_back(1); //we insert '1'
int size = tab.size(); //size is equal to 3

◆ sort() [1/2]

template<typename T >
void Dtk_tab< T >::sort ( )

Swap two elements.

Sample:

Dtk_tab<int> tab; //we construct an array of int.
tab.push_back(0); //we insert '0'
tab.push_back(2); //we insert '2'
tab.push_back(1); //we insert '1'
//tab is {0,2,1}
tab.swap(tab[0],tab[1]);
//tab is {2,0,1}

◆ sort() [2/2]

template<typename T >
template<typename comp >
void Dtk_tab< T >::sort ( const comp &  C)

Sorts the array with custom sorting.

Parameters
[in]CComparison Functor
Remarks
Comparison functor need to be instanciated with default : use (). See sample.
Use a custom functor or one of the two internal functors available : Dtk_less (default) and Dtk_greater

Sample:

Dtk_tab<int> tab; //we construct an array of int.
tab.push_back(0); //we insert '0'
tab.push_back(2); //we insert '2'
tab.push_back(1); //we insert '1'
//tab is {0,2,1}
//tab is {2,1,0}

◆ subtab()

template<typename T >
Dtk_tab Dtk_tab< T >::subtab ( Dtk_Size_t  a,
Dtk_Size_t  b 
)

◆ swap()

template<typename T >
void Dtk_tab< T >::swap ( const Dtk_Size_t  inA,
const Dtk_Size_t  inB 
)

Sorts the array.

Sample:

Dtk_tab<int> tab; //we construct an array of int.
tab.push_back(0); //we insert '0'
tab.push_back(2); //we insert '2'
tab.push_back(1); //we insert '1'
//tab is {0,2,1}
tab.sort();
//tab is {0,1,2}
Dtk_greater
Functor comparison object.
Definition: util_stl_dtk.hpp:27
Dtk_tab::capacity
Dtk_Size_t capacity() const
Returns the size of the storage space currently allocated for the array, expressed in terms of elemen...
Definition: util_stl_dtk.hpp:524
Dtk_Size_t
size_t Dtk_Size_t
Definition: define.h:714
Dtk_tab::sort
void sort()
Swap two elements.
Definition: util_stl_dtk.hpp:713
Dtk_tab::back
T & back()
Return the elements at the end of the array.
Definition: util_stl_dtk.hpp:539
Dtk_tab::remove
void remove(const T &a)
Removes the first element with the value a.
Definition: util_stl_dtk.hpp:692
Dtk_tab::front
T & front()
Return the elements at the beginning of the array.
Definition: util_stl_dtk.hpp:569
Dtk_tab::resize
void resize(Dtk_Size_t n, const T &t)
Resizes the array.
Definition: util_stl_dtk.hpp:605
Dtk_tab::reserve
void reserve(Dtk_Size_t n)
Definition: util_stl_dtk.hpp:799
Dtk_tab< int >
Dtk_tab::size
Dtk_Size_t size() const
Returns the size of the array.
Definition: util_stl_dtk.hpp:504
Dtk_tab::swap
void swap(const Dtk_Size_t inA, const Dtk_Size_t inB)
Sorts the array.
Definition: util_stl_dtk.hpp:667
Dtk_tab::push_back
void push_back(const T &x)
Inserts an element at the end of the array.
Definition: util_stl_dtk.hpp:417
Dtk_tab::clear
void clear(int no_delete=0)
Resets the Dtk_tab content.
Definition: util_stl_dtk.hpp:353