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 ()
 
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 63 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 230 of file array.h.

◆ Array() [2/2]

Array ( const Array< T > &  old)

copy constructor

Definition at line 236 of file array.h.

◆ ~Array()

~Array ( )

destructor

Definition at line 242 of file array.h.

Member Function Documentation

◆ append() [1/5]

void append ( const T &  t)

append 1 elements with value t.

Definition at line 107 of file array.h.

Referenced by Array< soplex::UnitVectorBase * >::append().

◆ append() [2/5]

void append ( int  n)

append n uninitialized elements.

Definition at line 112 of file array.h.

◆ append() [3/5]

void append ( int  n,
const T &  t 
)

append n elements with value t.

Definition at line 118 of file array.h.

◆ append() [4/5]

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

append n elements from t.

Definition at line 123 of file array.h.

◆ append() [5/5]

void append ( const Array< T > &  t)

append all elements from p_array.

Definition at line 128 of file array.h.

◆ clear()

void clear ( )

remove all elements.

Definition at line 185 of file array.h.

◆ get_const_ptr()

const T* get_const_ptr ( ) const

get a const C pointer to the data.

Definition at line 101 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 96 of file array.h.

◆ insert() [1/4]

void insert ( int  i,
int  n 
)

insert n uninitialized elements before i 'th element.

Definition at line 134 of file array.h.

◆ insert() [2/4]

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

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

Definition at line 143 of file array.h.

◆ insert() [3/4]

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

insert n elements from p_array before i 'th element.

Definition at line 152 of file array.h.

◆ insert() [4/4]

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

insert all elements from p_array before i 'th element.

Definition at line 161 of file array.h.

◆ isConsistent()

bool isConsistent ( ) const

Consistency check.

Definition at line 258 of file array.h.

Referenced by DataHashTable< soplex::NameSet::Name, soplex::DataKey >::isConsistent().

◆ operator=() [1/2]

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

assignment operator.

Definition at line 208 of file array.h.

◆ operator=() [2/2]

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

Definition at line 220 of file array.h.

◆ operator[]() [1/2]

T& operator[] ( int  n)

reference n 'th element.

Definition at line 81 of file array.h.

◆ operator[]() [2/2]

const T& operator[] ( int  n) const

reference n 'th element.

Definition at line 87 of file array.h.

◆ push_back() [1/2]

void push_back ( const T &  val)

Definition at line 247 of file array.h.

◆ push_back() [2/2]

void push_back ( T &&  val)

Definition at line 252 of file array.h.

◆ remove()

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

remove m elements starting at n.

Definition at line 170 of file array.h.

◆ reSize()

void reSize ( int  newsize)

reset the number of elements.

Definition at line 197 of file array.h.

Referenced by Array< soplex::UnitVectorBase * >::operator=(), and DataHashTable< soplex::NameSet::Name, soplex::DataKey >::reMax().

◆ size()

Member Data Documentation

◆ data