![]() ![]() ![]()
|
BREW C++ Class Library & GUI Framework & XML Middleware : SophiaFramework 4.1 |
There are 4 types of collection classes: variable-length array, stack, list, and hashmap.
To add, update, delete, or retrieve items against the collection of multiple items, use the Collection class.
Table 13.1. Collection Class
| Class Name | Description |
|---|---|
| SFXArray | Data structure for operating the variable-length array. |
| SFXStack | Data structure for operating the stack. |
| SFXList | Data structure for operating the two-way list. |
| SFXHashmap | Data structure for operating the hashmap where its item consist of key and value. |
![]() |
Limitation on the Collection Class |
|---|---|
|
The item stored in the Collection class must not exceed 4 bytes in length. In case of the item more than 4 bytes, its pointer can be stored in the Collection class. Reference: Collection of Instances | |
SFXArray is the data structure to store a number of items sequentially.
Example 13.1. Define the variable-length array
// Define variable-length array for storing items of SInt32
SFXArray<SInt32> array;
Example 13.2. Append items
array.InsertLast(3);
array.InsertLast(-15);
array.InsertLast(0);
array.InsertLast(1003);
// array = (3, -15, 0, 1003)
Example 13.3. Set and get items
SInt32 n = array[1]; // n = -15 array[2] = 6; // array = (3, -15, 6, 1003) SInt32 m = array.GetFirst(); // m = 3 SInt32 r = array.GetLast(); // r = 1003
Example 13.5. Insert items
// insert 99 after second item array.Insert(2, 99); // array = (3, -15, 99, 6, 1003) // insert -100 at first position array.InsertFirst(-100); // array = (-100, 3, -15, 99, 6, 1003)
Example 13.6. Delete items partially
// delete from array[3] to array[4] array.Remove(3, 5); // array = (-100, 3, -15, 1003)
Example 13.8. Extend the size of array
array.SetSize(5); // array = (undefined, undefined, undefined, undefined, undefined) SInt32 i; for (i = 0; i < array.GetSize(); ++i) { array[i] = 10 * (i - 2) * (i - 2); } // array becomes (40, 10, 0, 10, 40)
Example 13.9. Retrieve and check items
SInt32 n1 = array.FirstIndexOf(10); // n1 = 1 SInt32 n2 = array.FirstIndexOf(5); // n2 = -1 SInt32 n3 = array.LastIndexOf(10); // n3 = 3 Bool b = array.Contains(40); // b = true
Example 13.10. Process each item using the iterator 1
SFXArray<SInt32>::Iterator iterator = array.GetFirstIterator();
while(iterator.HasNext()) {
SInt32 n = iterator.GetNext(); // n holds item
// process n
}
The above code is similar to the following:
SFXStack is the data structure in which the most recently added item is removed first.
SFXList is the data structure for operating on the two-way list.
Example 13.17. Append items
list.InsertLast(3);
list.InsertLast(-15);
list.InsertLast(0);
list.InsertLast(1003);
// list = ( 3 , -15 , 0 , 1003 )
Example 13.18. Set and get items
// SInt32 n = list[1]; invalid statement // list[2] = 6; invalid statement SInt32 m = list.GetFirst(); // m = 3 SInt32 r = list.GetLast(); // r = 1003
Other operations are similar to those of SFXArray class.
SFXHashmap is the data structure for operating on the hashmap where its item consist of key and value.
Example 13.20. Define the hashmap
// Define hashmap for storing items of SFXAnsiString and SInt32 // (Exception) SFXAnsiString and SFXWideString can be used in hashmap. SFXHashmap<SFXAnsiString, SInt32> hashmap;
|
Copyright (C) 2002 - 2008 Sophia Cradle, Inc. All Rights Reserved. |
![]() ![]() ![]()
|