description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Learn more about: CSimpleArray Class |
CSimpleArray Class |
11/04/2016 |
|
|
ee0c9f39-b61c-4c18-bc43-4eada21dca3a |
This class provides methods for managing a simple array.
template <class T, class TEqual = CSimpleArrayEqualHelper<T>>
class CSimpleArray
T
The type of data to store in the array.
TEqual
A trait object, defining the equality test for elements of type T.
Name | Description |
---|---|
CSimpleArray::CSimpleArray | The constructor for the simple array. |
CSimpleArray::~CSimpleArray | The destructor for the simple array. |
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. |
Name | Description |
---|---|
CSimpleArray::operator[] | Retrieves an element from the array. |
CSimpleArray::operator = | Assignment operator. |
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.
Header: atlsimpcoll.h
[!code-cppNVC_ATL_Utilities#86]
Adds a new element to the array.
BOOL Add(const T& t);
t
The element to add to the array.
Returns TRUE if the element is successfully added to the array, FALSE otherwise.
[!code-cppNVC_ATL_Utilities#87]
The constructor for the array object.
CSimpleArray(const CSimpleArray<T, TEqual>& src);
CSimpleArray();
src
An existing CSimpleArray
object.
Initializes the data members, creating a new empty CSimpleArray
object, or a copy of an existing CSimpleArray
object.
The destructor.
~CSimpleArray();
Frees all allocated resources.
Finds an element in the array.
int Find(const T& t) const;
t
The element for which to search.
Returns the index of the found element, or -1 if the element is not found.
[!code-cppNVC_ATL_Utilities#88]
Returns a pointer to the data stored in the array.
T* GetData() const;
Returns a pointer to the data in the array.
Returns the number of elements stored in the array.
int GetSize() const;
Returns the number of elements stored in the array.
Retrieves an element from the array.
T& operator[](int nindex);
nIndex
The element index.
Returns the element of the array referenced by nIndex.
[!code-cppNVC_ATL_Utilities#89]
Assignment operator.
CSimpleArray<T, TEqual>
& operator=(
const CSimpleArray<T, TEqual>& src);
src
The array to copy.
Returns a pointer to the updated CSimpleArray
object.
Copies all elements from the CSimpleArray
object referenced by src into the current array object, replacing all existing data.
[!code-cppNVC_ATL_Utilities#90]
Removes a given element from the array.
BOOL Remove(const T& t);
t
The element to remove from the array.
Returns TRUE if the element is found and removed, FALSE otherwise.
When an element is removed, the remaining elements in the array are renumbered to fill the empty space.
Removes all elements from the array.
void RemoveAll();
Removes all elements currently stored in the array.
Removes the specified element from the array.
BOOL RemoveAt(int nIndex);
nIndex
Index pointing to the element to remove.
Returns TRUE if the element was removed, FALSE if the index was invalid.
When an element is removed, the remaining elements in the array are renumbered to fill the empty space.
Set the specified element in the array.
BOOL SetAtIndex(
int nIndex,
const T& t);
nIndex
The index of the element to change.
t
The value to assign to the specified element.
Returns TRUE if successful, FALSE if the index was not valid.