DSL_numArray

<< Click to Display Table of Contents >>

Navigation:  Reference Manual > Arrays and matrices >

DSL_numArray

Header file: numarray.h

template <class T, int LOCAL_SIZE> class DSL_numArray;

The DSL_numArray template is a base class for non-templated DSL_intArray and DSL_doubleArray. Elements are stored in a contiguous buffer. The memory is not initialized on construction/resize. Small object optimization is implemented.


DSL_numArray();

DSL_numArray(int arraySize);

DSL_numArray(const DSL_numArray& other);

DSL_numArray(std::initializer_list<T> initList);

~DSL_numArray();

DSL_numArray& operator=(const DSL_numArray& other);

DSL_numArray& operator=(std::initializer_list<T> initList);

Implement the default constructor, copy constructors, operator=, and destructor. The methods accepting std::initializer_list as input are available only if C++11 standard is enabled during compilation. The constructor accepting an integer array size does not initialize the contents of the buffer.


template <class A> void CopyFrom(const std::vector<T, A>& v);

template <class A> void CopyTo(std::vector<T, A>& v) const

Copies array elements from/to std::vector.


T* begin();

T* end();

const T* begin() const;

const T* end() const;

const T* cbegin() const;

const T* cend() const;

The methods to enable C++ 11 range-based for loops. Can also be used with any Standard Library algorithm accepting random access iterators.


T& operator[](int index);

T operator[](int index) const;

Indexed access. The debug build of the library checks the index and asserts if the index is invalid.


T* Items();

const T* Items()

Return a pointer to the start of the memory buffer containing the array elements. Equivalent to begin.


int FindPosition(T value) const;

Returns the index of the specified value, or DSL_OUT_OF_RANGE (a negative number) if the value is not found.


bool Contains(T value) const;

Returns true if the specified value is present in the array, false otherwise.


bool IsEmpty() const

Returns true if the array is empty, false otherwise.


int GetSize() const;

Returns the number of elements in the array.


int SetSize(int newSize);

Sets the new size of the array. If the size increases, the buffer elements with indices above previous size are not initialized. Existing elements are always preserved.


int Reserve(int newReserved);

Reserves the buffer capacity, use in performance-critical scenarios. Does not change the size of the array returned from GetSize.


void Clear();

Sets the array size to zero.


void Add(T value);

Adds a new element at the end of the array


int AddExclusive(T value);

Adds new element at the end of the array only when the specified value is not already present in the array. If the element already exists, returns DSL_OUT_OF_RANGE, otherwise DSL_OKAY.


int Insert(int index, T value);

Inserts new element in the array at the specified index. Returns DSL_OKAY, or DSL_OUT_OF_RANGE if the index is negative or greater than the array size. Insert can be called with index equal to the array size. In such case, Add is invoked.


int Delete(int index);

Removes the element in the array at the specified index. The elements after the removed element are shifted toward the beginning of the array. Returns DSL_OKAY, or DSL_OUT_OF_RANGE if the index is negative or greater than the array size.


int DeleteByContent(T value);

Removes the element in the array at the specified index. The elements after the removed element are shifted toward the beginning of the array. Returns DSL_OKAY on success, or DSL_OUT_OF_RANGE if the specified value is not found.


int Assign(const T* src, int count);

Sets the size of the array to count, and copies the elements from the buffer starting at src.


void FillWith(T value);

Fills the array with the specified value. The array size does not change.


void Swap(DSL_numArray& other);

Swaps two arrays.


template <class T, int LOCAL_SIZE>

bool operator==(

    const DSL_numArray<T, LOCAL_SIZE>& lhs, 

    const DSL_numArray<T, LOCAL_SIZE>& rhs);

template <class T, int LOCAL_SIZE>

bool operator!=(

    const DSL_numArray<T, LOCAL_SIZE>& lhs, 

    const DSL_numArray<T, LOCAL_SIZE>& rhs);

Non-member function operator== returns true if the arrays have the same number of elements, and each element in lhs is equal to the corresponding element in rhs. operator!= calls operator== and performs the negation on the result.


int NumItems() const;

int IsInList(T x) const;

void UseAsList();

BACKWARD COMPATIBILITY ONLY. Available when SMILE_NO_V1_COMPATIBILITY is not defined.