SophiaFramework UNIVERSE 5.3 |
SFXList is data structure for operating a multiple of the elements as a two-way linked list. Memory allocation and release will be performed for each element.
SFXList and SFXArray | |
---|---|
In the SFXList class, inserting or deleting an element is only to maintain the pointers of the element in question and the neighboring elements. On the other hand, in the SFXArray class, it is necessay to to move elements after the element in question in the internal buffer memory. Therefore, inserting or deleting an element is faster than in the SFXArray class. In the SFXList class, accessing an element needs to be traversed via a two-way linked list. On the other hand, in the SFXArray class, an element can be directly accessed using the index. Therefore, accessing an element is slower than in the SFXArray class. |
Each element size of SFXList needs to be less than or equal 4 byte. In order to process data more than 4 byte ( such as UInt64 type, Float64 type, and so on ) or class instance as an element of the SFXList instance ( bidirectional linked list ), a pointer should be used.
// data more than 4 byte or class instance cannot be an element of the SFXList instance ( bidirectional linked list ) // SFXList<SInt64> ar64; NG // SFXList<SFXAnsiString> arstr; NG // but a pointer to the data more than 4 byte or class instance can be an element of the SFXList instance ( bidirectional linked list ) SFXList<SInt64Ptr> ar64; // OK SFXList<SFXAnsiStringPtr> arstr;// OK
Constructor/Destructor |
---|
SFXList( Void ) Constructor of the SFXList class.
|
Public Functions | |
---|---|
SFCError |
Append(
SFXList< V > const & collection
) [DEPRECATED] Append an element.
|
SFCError |
Append(
V value
) [DEPRECATED] Append an element.
|
Void |
Clear( Void ) Clear this list.
|
Bool |
Contains(
V value
) Check whether or not this list contains the specified value.
|
static SFXList< V > const & |
EmptyInstance( Void ) Get an empty list.
|
Bool |
Equals(
SFXList< V > const & collection
) Check whether or not this list equals the specified list.
|
SInt32 |
FirstIndexOf(
V value
, SInt32 index = SINT32_MINIMUM
) Get the first index of the element that equals the specified value, searching from the head.
|
V |
Get(
SInt32 index
) Get the element at the specified index.
|
Enumerator |
GetEnumerator(
SInt32 index
) Get the enumerator that points to the element at the specified index.
|
V |
GetFirst( Void ) Get the element at the head.
|
Enumerator |
GetFirstEnumerator( Void ) Get the enumerator that points to the first element.
|
Iterator |
GetFirstIterator( Void ) Get the iterator that points to the first element.
|
Iterator |
GetIterator(
SInt32 index
) Get the iterator that points to the element at the specified index.
|
V |
GetLast( Void ) Get the element at the tail.
|
Enumerator |
GetLastEnumerator( Void ) Get the enumerator that points to the last element.
|
Iterator |
GetLastIterator( Void ) Get the iterator that points to the last element.
|
SInt32 |
GetSize( Void ) Get the size(the number of the elements).
|
SFCError |
Insert(
SInt32 index
, SFXList< V > const & collection
) Insert the specified element or list before the specified index.
|
SFCError |
Insert(
SInt32 index
, V value
) Insert the specified element or list before the specified index.
|
SFCError |
InsertFirst(
SFXList< V > const & collection
) Insert the specified element or list at the head.
|
SFCError |
InsertFirst(
V value
) Insert the specified element or list at the head.
|
SFCError |
InsertLast(
SFXList< V > const & collection
) Insert the specified element or list at the tail.
|
SFCError |
InsertLast(
V value
) Insert the specified element or list at the tail.
|
Bool |
IsEmpty( Void ) Check whether or not this list is empty.
|
SInt32 |
LastIndexOf(
V value
, SInt32 index = SINT32_MAXIMUM
) Get the last index of the element that equals the specified value, searching from the tail.
|
SFCError |
Move(
SInt32 destination
, SInt32 source
) Move the element at the specified index to the specified index.
|
SFCError |
MoveFirst(
SInt32 source
) Move the element at the specified index to the head.
|
SFCError |
MoveLast(
SInt32 source
) Move the element at the specified index to the tail.
|
Void |
Remove(
SInt32 index
) Remove the elements at the specified index or range.
|
Void |
Remove(
SInt32 begin
, SInt32 end
) Remove the elements at the specified index or range.
|
Void |
RemoveFirst( Void ) Remove the element at the head.
|
Void |
RemoveLast( Void ) Remove the element at the tail.
|
SFCError |
Set(
SFXList< V > const & collection
)
Set the element at the specified index of this list to the specified value.
Or set this list to the specified list.
|
SFCError |
Set(
SInt32 index
, V value
)
Set the element at the specified index of this list to the specified value.
Or set this list to the specified list.
|
SFCError |
SetFirst(
V value
) Set the element at the head to the specified value.
|
SFCError |
SetLast(
V value
) Set the element at the tail to the specified value.
|
SFCError |
Swap(
SInt32 destination
, SInt32 source
) Swap two elements at the specified indexes.
|
SFCError |
SwapFirst(
SInt32 source
) Swap the element at the specified index for the element at the head.
|
SFCError |
SwapLast(
SInt32 source
) Swap the element at the specified index for the element at the tail.
|
Types |
---|
Enumerator Class for managing the enumerator of this list.
|
Iterator Class for managing the iterator of this list.
|
[ public, explicit ] SFXList(Void);
[ public ] SFCError Append( SFXList< V > const & collection // list to append );
[ public ] SFCError Append( V value // element to append );
Append an element at the end of list. This function is deprecated, use the SFXList::InsertLast function.
SFXList<SInt32> list; SInt16 i; // append an element if (list.Append(2) == SFERR_NO_ERROR) { // append an element if (list.Append(5) == SFERR_NO_ERROR) { // enumerate by index for (i = 0; i < list.GetSize(); ++i) { TRACE("%d", list.Get(i)); // 2 5 } } }
SFXList::Insert | SFXList::InsertLast | SFXList::Get | SFXList::Remove | SFXList::Set
[ public ] Void Clear(Void);
This function clears this list. All the memory areas allocated to the elements of this list will be released.
After this function is executed, the size of this list will become 0.
Caution | |
---|---|
If the type of the element is a pointer to a class instance or data bigger than 4 bytes, memory area that the pointer points to will not be released automatically. Before clearing this list, it is necessary to release that area explicitly using the delete statement. Otherwise, memory leakage will occur. |
Note | |
---|---|
This function will be called automatically when this list goes out of scope. |
SFXList<SInt32> list;
...
list.Clear(); // clear the list
[ public, const ] Bool Contains( V value // value to check );
This function checks whether or not this list contains the specified value.
Note | |
---|---|
If the type of the element is a pointer to a class instance or data bigger than 4 bytes, their addresses will be compared with. |
SFXList<SInt32> list; // append an element if (list.InsertLast(2) == SFERR_NO_ERROR) { // append an element if (list.InsertLast(5) == SFERR_NO_ERROR) { // check whether or not the stack contains the elements below TRACE("Contains(2) = %s", (list.Contains(2)) ? ("true") : ("false")); // contains(2) = true TRACE("Contains(4) = %s", (list.Contains(4)) ? ("true") : ("false")); // contains(4) = false } }
[ public, static ] SFXList< V > const & EmptyInstance(Void);
Get an instance that represents an empty list.
[ public, const ] Bool Equals( SFXList< V > const & collection // list to compare with );
This function checks whether or not this list equals the specified list (whether or not the same elements are saved in the same order).
Note | |
---|---|
If the type of the element is a pointer, its address will be compared. |
[ public, const ] SInt32 FirstIndexOf( V value // value to search SInt32 index = SINT32_MINIMUM // index to search from );
This function gets the first index of the element of this list that equals the specified value, searching from the head to the tail.
By specifying the beginning index in the argument, you can search from any position other than the head. (The index of the head is 0.)
Note | |
---|---|
If the type of the element is a pointer, its address will be compared. |
SFXList<SInt32> list; // append an element if (list.InsertLast(2) == SFERR_NO_ERROR) { // append an element if (list.InsertLast(5) == SFERR_NO_ERROR) { // get the first index of the element that equals the specified value, searching from the beginning TRACE("FirstIndexOf(1) = %d", list.FirstIndexOf(1)); // firstIndexOf(1) = -1 TRACE("FirstIndexOf(2) = %d", list.FirstIndexOf(2)); // firstIndexOf(2) = 0 TRACE("FirstIndexOf(5) = %d", list.FirstIndexOf(5)); // firstIndexOf(5) = 1 } }
[ public, const ] V Get( SInt32 index // index of the element to get );
Element at the index specified in the argument. 0 or null will be returned if no element exists at the specified index.
This function gets the element at the index specified in the argument.
Caution | |
---|---|
In case no element exists at the specified index, no error will occur but this function will return 0 or null. |
SFXList::GetFirst | SFXList::GetLast | SFXList::Insert | SFXList::Remove | SFXList::Set
[ public, const ] Enumerator GetEnumerator( SInt32 index // index to start );
Enumerator that points to the element at the specified index
This function gets the enumerator of this list that points to the element at the specified index.
Note | |
---|---|
If the specified index is less than or equals 0, this function is same as the SFXList::GetFirstEnumerator function. If the specified index is more than or equals the size of this list, this function is same as the SFXList::GetLastEnumerator function. |
SFXList::GetFirstEnumerator | SFXList::GetLastEnumerator | SFXList::GetIterator | SFXList::Enumerator
[ public, const ] V GetFirst(Void);
Element at the head. 0 or null will be returned if no element exists in this list.
This function gets the element at the head.
Caution | |
---|---|
In case no element exists in this list, no error will occur but this function will return 0 or null. |
SFXList::Get | SFXList::GetLast | SFXList::InsertFirst | SFXList::RemoveFirst
[ public, const ] Enumerator GetFirstEnumerator(Void);
Enumerator that points to the first element
This function gets the enumerator of this list that points to the first element.
SFXList<SInt32> list; SFXList<SInt32>::Enumerator en; // append an element if (list.InsertLast(2) == SFERR_NO_ERROR) { // append an element if (list.InsertLast(5) == SFERR_NO_ERROR) { // get the enumerator that points to the first element en = list.GetFirstEnumerator(); // check whether the next element exists or not while(en.HasNext()) { TRACE("%d", en.GetNext()); // 2 5 } } }
[ public ] Iterator GetFirstIterator(Void);
Iterator that points to the first element
This function gets the iterator of this list that points to the first element.
SFXList<SInt32> list; SFXList<SInt32>::Iterator it; // append an element if (list.InsertLast(2) == SFERR_NO_ERROR) { // append an element if (list.InsertLast(5) == SFERR_NO_ERROR) { // get the iterator that points to the first element it = list.GetFirstIterator(); // check whether the next element exists or not while(it.HasNext()) { TRACE("%d", it.GetNext()); // 2 5 } } }
SFXList::GetIterator | SFXList::GetFirstEnumerator | SFXList::Iterator
[ public ] Iterator GetIterator( SInt32 index // index to start );
Iterator that points to the element at the specified index
This function gets the iterator of this list that points to the element at the specified index.
Note | |
---|---|
If the specified index is less than or equals 0, this function is same as the SFXList::GetFirstIterator function. If the specified index is more than or equals the size of this list, this function is same as the SFXList::GetLastIterator function. |
SFXList::GetFirstIterator | SFXList::GetLastIterator | SFXList::GetEnumerator | SFXList::Iterator
[ public, const ] V GetLast(Void);
Element at the tail. 0 or null will be returned if no element exists in this list.
This function gets the element at the tail.
Caution | |
---|---|
In case no element exists in this list, no error will occur but this function will return 0 or null. |
SFXList::Get | SFXList::GetFirst | SFXList::InsertLast | SFXList::RemoveLast
[ public, const ] Enumerator GetLastEnumerator(Void);
Enumerator that points to the last element
This function gets the enumerator of this list that points to the last element.
[ public ] Iterator GetLastIterator(Void);
Iterator that points to the last element
This function gets the iterator of this list that points to the last element.
SFXList::GetIterator | SFXList::GetLastEnumerator | SFXList::Iterator
[ public, const ] SInt32 GetSize(Void);
SFXList<SInt32> list; SInt16 i; // append an element if (list.InsertLast(2) == SFERR_NO_ERROR) { // append an element if (list.InsertLast(5) == SFERR_NO_ERROR) { // display the size(the number of the elements) TRACE("%d", list.GetSize()); // 2 } }
[ public ] SFCError Insert( SInt32 index // index to insert SFXList< V > const & collection // list to insert );
[ public ] SFCError Insert( SInt32 index // index to insert V value // value of the element to insert );
This function inserts the specified element or list before the specified index.
If the value of the specified index is less than or equals 0, the element will be inserted at the head.
If the value of the specified index is greater than or equals the number of the elements, the element will be inserted at the tail.
SFXList<SInt16> list; SInt16 i; // insert an element at the tail if (list.InsertLast(2) == SFERR_NO_ERROR) { // insert an element at the tail if (list.InsertLast(5) == SFERR_NO_ERROR) { // insert an element at the head if (list.Insert(0, 3) == SFERR_NO_ERROR) { // insert an element at the specified index // if the value of the specified index is less than or equals 0, an element will be inserted at head // if the value of the specified index is greater than or equals the number of the elements, an element will be inserted at the tail if (list.Insert(10, 4) == SFERR_NO_ERROR) { // remove elements from the 1st index to the 2nd index list.Remove(1, 3); // enumerate elements by index for (i = 0; i < list.GetSize(); ++i) { TRACE("%d", list.Get(i)); // 3 4 } } } } }
SFXList::InsertFirst | SFXList::InsertLast | SFXList::Set | SFXList::Get | SFXList::Remove
[ public ] SFCError InsertFirst( SFXList< V > const & collection // list to insert );
[ public ] SFCError InsertFirst( V value // value of the element to insert );
This function inserts the specified element or list at the head.
SFXList::Insert | SFXList::InsertLast | SFXList::RemoveFirst | SFXList::GetFirst
[ public ] SFCError InsertLast( SFXList< V > const & collection // list to insert );
[ public ] SFCError InsertLast( V value // value of the element to insert );
This function inserts the specified element or list at the tail.
SFXList::Insert | SFXList::InsertFirst | SFXList::GetLast | SFXList::RemoveLast
[ public, const ] Bool IsEmpty(Void);
This function checks whether or not this list is empty.
[ public, const ] SInt32 LastIndexOf( V value // value to search SInt32 index = SINT32_MAXIMUM // index to search from );
This function gets the last index of the element of this list that equals the specified value, searching from the tail to the head.
By specifying the beginning index in the argument, you can search from any position other than the tail. (The index of the head is 0.)
Note | |
---|---|
If the type of the element is a pointer, its address will be compared. |
SFXList<SInt32> list; // append an element if (list.InsertLast(2) == SFERR_NO_ERROR) { // append an element if (list.InsertLast(5) == SFERR_NO_ERROR) { // get the last index of the element that equals the specified value, searching from the end TRACE("LastIndexOf(1) = %d", list.LastIndexOf(1)); // lastIndexOf(1) = -1 TRACE("LastIndexOf(2) = %d", list.LastIndexOf(2)); // lastIndexOf(2) = 0 TRACE("LastIndexOf(5) = %d", list.LastIndexOf(5)); // lastIndexOf(5) = 1 } }
[ public ] SFCError Move( SInt32 destination // destination index of the element to move SInt32 source // source index of the element to move );
This function moves the element at the specified index to the specified index.
This function moves the element at the specified index to the head.
This function moves the element at the specified index to the tail.
[ public ] Void Remove( SInt32 index // index of the element to remove );
[ public ] Void Remove( SInt32 begin // beginning index(this index is included) SInt32 end // ending index(this index is not included) );
This function removes the element at the specified index or the elements in the specified index range.
If the specified index is less than 0 or greater than or equals the number of the elements, no element will be removed.
If the beginning index to remove is greater than or equals the number of the elements or the ending index to remove is less than or equals 0, no element will be removed.
If the beginning index to remove is less than or equals 0, it will be reset to 0.
If the ending index to remove is greater than the number of the elements, it will be reset to the number of the elements.
Caution | |
---|---|
If no element exists at the specified index or range, no error will occur and nothing will happen. |
SFXList<SInt16> list; SInt16 i; // insert an element at the tail if (list.InsertLast(2) == SFERR_NO_ERROR) { // insert an element at the tail if (list.InsertLast(5) == SFERR_NO_ERROR) { // insert an element at the head if (list.Insert(0, 3) == SFERR_NO_ERROR) { // insert an element at the specified index // if the value of the specified index is less than or equals 0, an element will be inserted at head // if the value of the specified index is greater than or equals the number of the elements, an element will be inserted at the tail if (list.Insert(10, 4) == SFERR_NO_ERROR) { // remove elements from 2nd to 3rd list.Remove(1, 3); // enumerate elements by index for (i = 0; i < list.GetSize(); ++i) { TRACE("%d", list.Get(i)); // 3 4 } } } } }
SFXList::RemoveFirst | SFXList::RemoveLast | SFXList::Insert | SFXList::Get | SFXList::Set
[ public ] Void RemoveFirst(Void);
This function removes the element at the head.
Caution | |
---|---|
If no element exists in this list, no error will occur and nothing will happen. |
SFXList::Remove | SFXList::RemoveLast | SFXList::GetFirst | SFXList::InsertFirst
[ public ] Void RemoveLast(Void);
This function removes the element at the tail.
Caution | |
---|---|
If no element exists in this list, no error will occur and nothing will happen. |
SFXList::Remove | SFXList::RemoveFirst | SFXList::GetLast | SFXList::InsertLast
[ public ] SFCError Set( SFXList< V > const & collection // list to set );
[ public ] SFCError Set( SInt32 index // index to set V value // value to set );
This function sets the element at the specified index of this list to the specified value, or sets this list to the specified list.
* In case an error occurs during processing, this list will be restored.
SFXList<SInt32> list; SInt16 i; // append an element if (list.InsertLast(2) == SFERR_NO_ERROR) { // append an element if (list.InsertLast(5) == SFERR_NO_ERROR) { // set a value to the element if (list.Set(1, 10) == SFERR_NO_ERROR) { // enumerate elements by index for (i = 0; i < list.GetSize(); ++i) { TRACE("%d", list.Get(i)); // 2 10 } } } }
[ public ] SFCError SetFirst( V value // value to set );
This function sets the element at the head to the specified value.
[ public ] SFCError SetLast( V value // value to set );
This function sets the element at the tail to the specified value.
This function swaps two elements at the specified indexes.
This function swaps the element at the specified index for the element at the head.
This function swaps the element at the specified index for the element at the tail.
[ public ] SFMTYPEDEFCLASS(Enumerator) friend class Enumerator; class Enumerator { public: explicit Enumerator (Void) : Enumeratoa(); Enumerator (IteratorConstRef iterator) : Enumeratoa(iterator); EnumeratorRef operator= (IteratorConstRef iterator); V GetNext (Void); V GetPrevious (Void); Bool HasNext (Void) const; Bool HasPrevious (Void) const; Bool IsValid (Void) const; };
This class is for managing the enumerator of this list.
This class has the following member functions.
GetNext | Get the next element. If no next element exists, null or 0 will be returned. |
GetPrevious | Get the previous element. If no previous element exists, null or 0 will be returned. |
HasNext | Check whether or not the next element exists. |
HasPrevious | Check whether or not the previous element exists. |
IsValid | Check whether or not the enumerator is valid. |
SFXList<SInt32> list; SFXList<SInt32>::Enumerator en; // append an element if (list.InsertLast(2) == SFERR_NO_ERROR) { // append an element if (list.InsertLast(5) == SFERR_NO_ERROR) { // get the enumerator that points to the first element en = list.GetFirstEnumerator(); // check whether the next element exists or not while(en.HasNext()) { TRACE("%d", en.GetNext()); // 2 5 } } }
[ public ] SFMTYPEDEFCLASS(Iterator) friend class Iterator; class Iterator { public: explicit Iterator (Void) : Iteratoa(); SFCError Set (V value); V GetNext (Void); V GetPrevious (Void); Bool HasNext (Void) const; Bool HasPrevious (Void) const; Bool IsValid (Void) const; SFCError Insert (V value); Void Remove (Void); friend class Enumerator; };
This class is for managing the iterator of this list.
This class has the following member functions.
Set | Set the element of current iterator to the specified value. |
GetNext | Get the next element. If no next element exists, null or 0 will be returned. |
GetPrevious | Get the previous element. If no previous element exists, null or 0 will be returned. |
HasNext | Check whether or not the next element exists. |
HasPrevious | Check whether or not the previous element exists. |
IsValid | Check whether or not the iterator is valid. |
Insert | Insert an element after the element of current iterator. |
Remove | Remove the element of current iterator. |
SFXList<SInt32> list; SFXList<SInt32>::Iterator it; // append an element if (list.InsertLast(2) == SFERR_NO_ERROR) { // append an element if (list.InsertLast(5) == SFERR_NO_ERROR) { // get the iterator that points to the first element it = list.GetFirstIterator(); // check whether the next element exists or not while(it.HasNext()) { TRACE("%d", it.GetNext()); // 2 5 } } }
Copyright(c) 2002 - 2024 Sophia Cradle Incorporated All Rights Reserved. |