Dynamic Arrays are the most common collection classes in Symbian OS. array elements can be of any type, but the most common element types in applications are:
1. Point to the C-type object pointer that inherits cbase.
2. T-type objects and R-type objects.
Dynamic Arrays in Symbian OS Are Template classes, and template parameters define the Element Types of arrays. You can select a fixed-length or variable-length object for the array type as needed.
Rarray and rpointerarray are the most common collection classes. Rarray is a simple array of fixed-length objects. The template parameters should be simple type, T-type, or R-type. rpointerarray is an array of object pointers, and the template parameters can be of any type. Generally, it tends to be constructed on the stack or as a data member based on the heap object.
Rarray (rpointerarray)
Create an array
As a simple array, the array element type must be T-or R-type.
Inline rarray ();
Example: rarray array;
The default constructor uses the default granularity (8) and offset (0) to instantiate the array. The granularity is the maximum number of elements expanded when the bucket is re-allocated.
Inline rarray (tint agranularity );
Example: rarray array (4 );
Creates an array by default offset and specified granularity.
Inline rarray (tint agranularity, tint akeyoffset );
Example: rarray array (4, 1 );
Creates an array by specifying the granularity and offset.
Release an array
To prevent memory leakage before closing the array, you need to release the memory allocated to the array.
Inline void close ();
Close the array and release all memory allocated to the array.
Inline tint count () const;
Close the array and release all memory allocated to the array, and return the number of elements in the array.
Reference array elements
Inline const T & operator [] (tint anindex) const;
Inline T & operator [] (tint anindex );
The access element through operator [] provides two overload functions, one returning a const type reference and the other returning a non-const type reference.
Add, insert, and delete Elements
Inline tint append (const T & anentry );
Add new elements to the end of the array.
Inline tint insert (const T & anentry, tint APOs );
Insert a new element at the specified position of the array.
Inline void remove (tint anindex );
Deletes an element at the specified position of the array.
Element sorting
Inline void sort (tlinearorder <t> anorder );
The general sorting method is:
1. Determine which attribute value of the element object to sort. Defines the attribute values of a comparison function comparison element. If the object value is equal, the function returns 0. If the first value is small, the function returns-1. If the second value is small, the function returns + 1. The comparison function can be implemented as a static member function, global function, or namespace member. The two parameter types of the comparison function must be the const reference type.
2. Use the comparison function pointer to construct a tlinearorder object.
3. Call sort () on the array and pass the tlinearorder object.
Search Element
Inline tint find (const T & anentry, tidentityrelation <t> anidentity) const;
In the array, use the specified matching rule to search for array elements equal to the specified object and return the element index value. The matching rule provides a function to determine whether two objects match. The search order starts from the index value of the low-level array, and the array elements are not necessarily ordered.
The common search method is:
1. Determine which attribute value of the element object to search. Defines the attribute value of a comparison function comparison element. If the object value is equal, the function returns etrue; otherwise, the function returns efalse. The comparison function can be implemented as a static member function, global function, or namespace member. The two parameter types of the comparison function must be the const reference type.
2. Construct a matching object as the search target.
3. Use the comparison function pointer to construct a tidentityrelation object.
4. Call find () on the array and pass the tlinearorder object and matching object.
Insert elements in an ordered array
Inline tint insertinorder (const T & anentry, tlinearorder <t> anorder );
Insert a new object using the specified comparative method on the array whose elements are arranged in the order of a certain attribute. After the new object is inserted, the array elements are still arranged in the order of this attribute value. The comparison method provides a function to determine the position of the new object to be inserted. If the inserted object has the same attribute value in the array element, the insert operation is not performed.
The general insert method is:
1. Define a comparison function to compare the attribute values of the inserted object and the array element. If the object value is equal, the function returns 0. If the first value is small, the function returns-1; if the second value is small, + 1 is returned. The comparison function can be implemented as a static member function, global function, or namespace member. The two parameter types of the comparison function must be the const reference type.
2. Use the comparison function pointer to construct a tlinearorder object.
3. Call inserinorder () on the array, and pass the tlinearorder object and the object to be inserted.
Obtains the number of elements in the array.
Inline tint count () const;
Compressing array space
Inline void compress ();
Compress the array space. The compressed array space will accommodate the contained elements. To insert a new element, the array is allocated with a new space.
Reset an array
Inline void reset ();
Resetting the array will release the memory space occupied by all elements and reset the internal status of the array for reuse.