Scippy

SoPlex

Sequential object-oriented simPlex

Array< T > Class Template Reference

Safe arrays of arbitrary types. More...

#include <array.h>

Public Member Functions

Access / modification
T & operator[] (int n)
 reference n 'th element. More...
 
const T & operator[] (int n) const
 reference n 'th element. More...
 
T * get_ptr ()
 
const T * get_const_ptr () const
 get a const C pointer to the data. More...
 
void append (const T &t)
 append 1 elements with value t. More...
 
void append (int n)
 append n uninitialized elements. More...
 
void append (int n, const T &t)
 append n elements with value t. More...
 
void append (int n, const T t[])
 append n elements from t. More...
 
void append (const Array< T > &t)
 append all elements from p_array. More...
 
void insert (int i, int n)
 insert n uninitialized elements before i 'th element. More...
 
void insert (int i, int n, const T &t)
 insert n elements with value t before i 'the element. More...
 
void insert (int i, int n, const T t[])
 insert n elements from p_array before i 'th element. More...
 
void insert (int i, const Array< T > &t)
 insert all elements from p_array before i 'th element. More...
 
void remove (int n=0, int m=1)
 remove m elements starting at n. More...
 
void clear ()
 remove all elements. More...
 
int size () const
 return the number of elements. More...
 
void reSize (int newsize)
 reset the number of elements. More...
 
Construction / destruction
Array< T > & operator= (const Array< T > &rhs)
 assignment operator. More...
 
Arrayoperator= (const Array &&rhs)
 
 Array (int n=0)
 default constructor. More...
 
 Array (const Array &old)
 copy constructor More...
 
 ~Array ()
 destructor More...
 
void push_back (const T &val)
 
void push_back (T &&val)
 
bool isConsistent () const
 Consistency check. More...
 

Protected Attributes

Data
std::vector< T > data
 

Detailed Description

template<class T>
class soplex::Array< T >

Safe arrays of arbitrary types.

Class Array provides safe arrays of arbitrary type. Array elements are accessed just like ordinary C++ array elements by means of the index operator[](). Safety is provided by

  • automatic memory management in constructor and destructor preventing memory leaks
  • checking of array bound when accessing elements with the indexing operator[]() (only when compiled without -DNDEBUG).

Moreover, Arrays may easily be extended by inserting or appending elements to the Array or shrunken by removing elements. Method reSize(int n) resets the Array's length to n, thereby appending elements or truncating the Array to the required size.

An Array is implemented in a C++-compliant way with respect to how memory is managed: Only operators new and delete are used for allocating memory. This involves some overhead for all methods effecting the length of an Array, i.e., all methods insert(), append(), remove() and reSize(). This involves allocating a new C++ array of the new size and copying all elements with the template parameters operator=().

For this reason, it is not convenient to use class Array if its elements are Data Objects. In this case use class DataArray instead.

See also
DataArray, Data Objects

Definition at line 72 of file array.h.

Constructor & Destructor Documentation

◆ Array() [1/2]

Array ( int  n = 0)
explicit

default constructor.

The constructor allocates an Array of n uninitialized elements.

Definition at line 239 of file array.h.

References Array< T >::data.

◆ Array() [2/2]

Array ( const Array< T > &  old)

copy constructor

Definition at line 245 of file array.h.

References Array< T >::data.

◆ ~Array()

~Array ( )

destructor

Definition at line 251 of file array.h.

Member Function Documentation

◆ append() [1/5]

void append ( const Array< T > &  t)

append all elements from p_array.

Definition at line 137 of file array.h.

References Array< T >::data.

◆ append() [2/5]

void append ( const T &  t)

append 1 elements with value t.

Definition at line 116 of file array.h.

References Array< T >::data.

Referenced by Array< T >::append().

◆ append() [3/5]

void append ( int  n)

append n uninitialized elements.

Definition at line 121 of file array.h.

References Array< T >::append().

◆ append() [4/5]

void append ( int  n,
const T &  t 
)

append n elements with value t.

Definition at line 127 of file array.h.

References Array< T >::data.

◆ append() [5/5]

void append ( int  n,
const T  t[] 
)

append n elements from t.

Definition at line 132 of file array.h.

References Array< T >::data.

◆ clear()

void clear ( )

remove all elements.

Definition at line 194 of file array.h.

References Array< T >::data.

◆ get_const_ptr()

const T * get_const_ptr ( ) const

get a const C pointer to the data.

Definition at line 110 of file array.h.

References Array< T >::data.

◆ get_ptr()

T * get_ptr ( )

This function serves for using a Vector in an C-style function. It returns a pointer to the first value of the array.

Definition at line 105 of file array.h.

References Array< T >::data.

◆ insert() [1/4]

void insert ( int  i,
const Array< T > &  t 
)

insert all elements from p_array before i 'th element.

Definition at line 170 of file array.h.

References Array< T >::data, and Array< T >::size().

◆ insert() [2/4]

void insert ( int  i,
int  n 
)

insert n uninitialized elements before i 'th element.

Definition at line 143 of file array.h.

References Array< T >::data.

◆ insert() [3/4]

void insert ( int  i,
int  n,
const T &  t 
)

insert n elements with value t before i 'the element.

Definition at line 152 of file array.h.

References Array< T >::data.

◆ insert() [4/4]

void insert ( int  i,
int  n,
const T  t[] 
)

insert n elements from p_array before i 'th element.

Definition at line 161 of file array.h.

References Array< T >::data.

◆ isConsistent()

bool isConsistent ( ) const

Consistency check.

Definition at line 267 of file array.h.

◆ operator=() [1/2]

Array & operator= ( const Array< T > &&  rhs)

Definition at line 229 of file array.h.

References Array< T >::data.

◆ operator=() [2/2]

Array< T > & operator= ( const Array< T > &  rhs)

assignment operator.

Definition at line 217 of file array.h.

References Array< T >::data, Array< T >::reSize(), and Array< T >::size().

◆ operator[]() [1/2]

T & operator[] ( int  n)

reference n 'th element.

Definition at line 90 of file array.h.

References Array< T >::data.

◆ operator[]() [2/2]

const T & operator[] ( int  n) const

reference n 'th element.

Definition at line 96 of file array.h.

References Array< T >::data.

◆ push_back() [1/2]

void push_back ( const T &  val)

Definition at line 256 of file array.h.

References Array< T >::data.

◆ push_back() [2/2]

void push_back ( T &&  val)

Definition at line 261 of file array.h.

References Array< T >::data.

◆ remove()

void remove ( int  n = 0,
int  m = 1 
)

remove m elements starting at n.

Definition at line 179 of file array.h.

References Array< T >::data, and Array< T >::size().

◆ reSize()

void reSize ( int  newsize)

reset the number of elements.

Definition at line 206 of file array.h.

References Array< T >::data.

Referenced by Array< T >::operator=().

◆ size()

int size ( ) const

return the number of elements.

Definition at line 200 of file array.h.

References Array< T >::data.

Referenced by Array< T >::insert(), Array< T >::operator=(), DataHashTable< HashItem, Info >::reMax(), and Array< T >::remove().

Member Data Documentation

◆ data