Scippy

SoPlex

Sequential object-oriented simPlex

Array< T > Class Template Reference

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. 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 ()
 
void append (int n)
 append n uninitialized elements. More...
 
void append (int n, const T *p_array)
 append n elements from p_array. More...
 
void append (const Array< T > &p_array)
 append all elements from p_array. More...
 
void insert (int i, int n)
 
void insert (int i, int n, const T *p_array)
 insert n elements from p_array before i 'th element. More...
 
void insert (int i, const Array< T > &p_array)
 insert all elements from p_array before i 'th element. More...
 
void remove (int n=0, int m=1)
 
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...
 
 Array (int n=0)
 default constructor. More...
 
 Array (const Array< T > &old)
 copy constructor More...
 
 ~Array ()
 destructor More...
 
bool isConsistent () const
 consistency check More...
 

Protected Attributes

Data
int num
 the length of array data More...
 
T * data
 the array of elements More...
 

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 destructure 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 62 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 300 of file array.h.

◆ Array() [2/2]

Array ( const Array< T > &  old)

copy constructor

Definition at line 321 of file array.h.

◆ ~Array()

~Array ( )

destructor

Definition at line 345 of file array.h.

Member Function Documentation

◆ append() [1/3]

void append ( int  n)

append n uninitialized elements.

Definition at line 100 of file array.h.

Referenced by Array< soplex::UnitVectorBase >::reSize().

◆ append() [2/3]

void append ( int  n,
const T *  p_array 
)

append n elements from p_array.

Definition at line 105 of file array.h.

◆ append() [3/3]

void append ( const Array< T > &  p_array)

append all elements from p_array.

Definition at line 110 of file array.h.

◆ clear()

void clear ( )

remove all elements.

Definition at line 242 of file array.h.

◆ 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 94 of file array.h.

◆ insert() [1/3]

void insert ( int  i,
int  n 
)

insert n uninitialized elements before i 'th element.

You must not! use realloc, memcpy or memmove, because some data element points inside itself, and therefore you always need to copy all elements by hand.

Definition at line 120 of file array.h.

Referenced by Array< soplex::UnitVectorBase >::append(), and Array< soplex::UnitVectorBase >::insert().

◆ insert() [2/3]

void insert ( int  i,
int  n,
const T *  p_array 
)

insert n elements from p_array before i 'th element.

Definition at line 162 of file array.h.

◆ insert() [3/3]

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

insert all elements from p_array before i 'th element.

Definition at line 171 of file array.h.

◆ isConsistent()

bool isConsistent ( ) const

consistency check

Definition at line 358 of file array.h.

Referenced by Array< soplex::UnitVectorBase >::Array(), and Array< soplex::UnitVectorBase >::operator=().

◆ operator=()

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

assignment operator.

Assigning an rvalue Array to an lvalue Array involves resizing the lvalue to the rvalues size() and copying all elements via the Array element's assignment operator=().

Definition at line 281 of file array.h.

◆ operator[]() [1/2]

T& operator[] ( int  n)

reference n 'th element.

Definition at line 79 of file array.h.

◆ operator[]() [2/2]

const T& operator[] ( int  n) const

reference n 'th element.

Definition at line 85 of file array.h.

◆ remove()

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

remove m elements starting at n.

You must not! use realloc, memcpy or memmove, because some data element points inside itself, and therefore you always need to copy all elements by hand.

Definition at line 185 of file array.h.

◆ reSize()

void reSize ( int  newsize)

reset the number of elements.

Definition at line 264 of file array.h.

Referenced by Array< soplex::UnitVectorBase >::operator=().

◆ size()

int size ( ) const

Member Data Documentation

◆ data

◆ num