Skip to content

Latest commit

 

History

History
295 lines (181 loc) · 6.95 KB

csimplearray-class.md

File metadata and controls

295 lines (181 loc) · 6.95 KB
description title ms.date f1_keywords helpviewer_keywords ms.assetid
Learn more about: CSimpleArray Class
CSimpleArray Class
11/04/2016
CSimpleArray
ATLSIMPCOLL/ATL::CSimpleArray
ATLSIMPCOLL/ATL::CSimpleArray::CSimpleArray
ATLSIMPCOLL/ATL::CSimpleArray::Add
ATLSIMPCOLL/ATL::CSimpleArray::Find
ATLSIMPCOLL/ATL::CSimpleArray::GetData
ATLSIMPCOLL/ATL::CSimpleArray::GetSize
ATLSIMPCOLL/ATL::CSimpleArray::Remove
ATLSIMPCOLL/ATL::CSimpleArray::RemoveAll
ATLSIMPCOLL/ATL::CSimpleArray::RemoveAt
ATLSIMPCOLL/ATL::CSimpleArray::SetAtIndex
CSimpleArray class
ee0c9f39-b61c-4c18-bc43-4eada21dca3a

CSimpleArray Class

This class provides methods for managing a simple array.

Syntax

template <class T, class TEqual = CSimpleArrayEqualHelper<T>>
class CSimpleArray

Parameters

T
The type of data to store in the array.

TEqual
A trait object, defining the equality test for elements of type T.

Members

Public Constructors

Name Description
CSimpleArray::CSimpleArray The constructor for the simple array.
CSimpleArray::~CSimpleArray The destructor for the simple array.

Public Methods

Name Description
CSimpleArray::Add Adds a new element to the array.
CSimpleArray::Find Finds an element in the array.
CSimpleArray::GetData Returns a pointer to the data stored in the array.
CSimpleArray::GetSize Returns the number of elements stored in the array.
CSimpleArray::Remove Removes a given element from the array.
CSimpleArray::RemoveAll Removes all elements from the array.
CSimpleArray::RemoveAt Removes the specified element from the array.
CSimpleArray::SetAtIndex Sets the specified element in the array.

Public Operators

Name Description
CSimpleArray::operator[] Retrieves an element from the array.
CSimpleArray::operator = Assignment operator.

Remarks

CSimpleArray provides methods for creating and managing a simple array, of any given type T.

The parameter TEqual provides a means of defining an equality function for two elements of type T. By creating a class similar to CSimpleArrayEqualHelper, it is possible to alter the behavior of the equality test for any given array. For example, when dealing with an array of pointers, it may be useful to define the equality as depending on the values the pointers reference. The default implementation utilizes operator=().

Both CSimpleArray and CSimpleMap are designed for a small number of elements. CAtlArray and CAtlMap should be used when the array contains a large number of elements.

Requirements

Header: atlsimpcoll.h

Example

[!code-cppNVC_ATL_Utilities#86]

CSimpleArray::Add

Adds a new element to the array.

BOOL Add(const T& t);

Parameters

t
The element to add to the array.

Return Value

Returns TRUE if the element is successfully added to the array, FALSE otherwise.

Example

[!code-cppNVC_ATL_Utilities#87]

CSimpleArray::CSimpleArray

The constructor for the array object.

CSimpleArray(const CSimpleArray<T, TEqual>& src);
CSimpleArray();

Parameters

src
An existing CSimpleArray object.

Remarks

Initializes the data members, creating a new empty CSimpleArray object, or a copy of an existing CSimpleArray object.

CSimpleArray::~CSimpleArray

The destructor.

~CSimpleArray();

Remarks

Frees all allocated resources.

CSimpleArray::Find

Finds an element in the array.

int Find(const T& t) const;

Parameters

t
The element for which to search.

Return Value

Returns the index of the found element, or -1 if the element is not found.

Example

[!code-cppNVC_ATL_Utilities#88]

CSimpleArray::GetData

Returns a pointer to the data stored in the array.

T* GetData() const;

Return Value

Returns a pointer to the data in the array.

CSimpleArray::GetSize

Returns the number of elements stored in the array.

int GetSize() const;

Return Value

Returns the number of elements stored in the array.

CSimpleArray::operator []

Retrieves an element from the array.

T& operator[](int nindex);

Parameters

nIndex
The element index.

Return Value

Returns the element of the array referenced by nIndex.

Example

[!code-cppNVC_ATL_Utilities#89]

CSimpleArray::operator =

Assignment operator.

CSimpleArray<T, TEqual>
& operator=(
    const CSimpleArray<T, TEqual>& src);

Parameters

src
The array to copy.

Return Value

Returns a pointer to the updated CSimpleArray object.

Remarks

Copies all elements from the CSimpleArray object referenced by src into the current array object, replacing all existing data.

Example

[!code-cppNVC_ATL_Utilities#90]

CSimpleArray::Remove

Removes a given element from the array.

BOOL Remove(const T& t);

Parameters

t
The element to remove from the array.

Return Value

Returns TRUE if the element is found and removed, FALSE otherwise.

Remarks

When an element is removed, the remaining elements in the array are renumbered to fill the empty space.

CSimpleArray::RemoveAll

Removes all elements from the array.

void RemoveAll();

Remarks

Removes all elements currently stored in the array.

CSimpleArray::RemoveAt

Removes the specified element from the array.

BOOL RemoveAt(int nIndex);

Parameters

nIndex
Index pointing to the element to remove.

Return Value

Returns TRUE if the element was removed, FALSE if the index was invalid.

Remarks

When an element is removed, the remaining elements in the array are renumbered to fill the empty space.

CSimpleArray::SetAtIndex

Set the specified element in the array.

BOOL SetAtIndex(
    int nIndex,
    const T& t);

Parameters

nIndex
The index of the element to change.

t
The value to assign to the specified element.

Return Value

Returns TRUE if successful, FALSE if the index was not valid.

See also

Class Overview