PrevNextUpHome BREW C++ Class Library & GUI Framework & XML Middleware : SophiaFramework 4.1
SFXList
Class that represents a bidirectional linked list.
#include <SFXList.h.hpp>
class SFXList;
SFMTYPEDEFCLASS(SFXList)

Inheritance diagram

 Inheritance diagram of SFXListClass

Collaboration diagram

 Collaboration diagram of SFXListClass

Description

Each element of the SFXList instance ( bidirectional linked list ) needs to be data not more than 4 bytes. In order to process data more than 4 bytes ( such as UInt64 type, Double 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 bytes 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 bytes or class instance can be an element of the SFXList instance ( bidirectional linked list )

SFXList<SInt64Ptr> ar64;        // oK
SFXList<SFXAnsiStringPtr> arstr;// oK

Reference

SFXArray

Member

Constructor/Destructor
SFXList( Void )
Constructor of SFXList class.
Public Functions
SFCError Append( SFXList< V > const & collection )
Append( V value )
[DEPRECATED] Append an element.
Void Clear( Void )
Clear the list.
Bool Contains( V value )
Check whether the value is contained or not.
static
SFXList< V > const &
EmptyInstance( Void )
Get an empty list.
Bool Equals( SFXList< V > const & collection )
Check whether to equal the specified list or not.
SInt32 FirstIndexOf( V value , SInt32 index = SINT32_MINIMUM )
Get the first index of the element matching with the specified value, searching from the beginning.
V Get( SInt32 index )
Get an element.
Enumerator GetEnumerator( SInt32 index )
Get an enumerator.
V GetFirst( Void )
Get the first element.
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 an iterator.
V GetLast( Void )
Get the last element.
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 elements).
SFCError Insert( SInt32 index , SFXList< V > const & collection )
Insert( SInt32 index , V value )
Insert an element.
SFCError InsertFirst( SFXList< V > const & collection )
InsertFirst( V value )
Insert an element at the beginning.
SFCError InsertLast( SFXList< V > const & collection )
InsertLast( V value )
Insert an element at the end.
Bool IsEmpty( Void )
Check whether the list is empty or not.
SInt32 LastIndexOf( V value , SInt32 index = SINT32_MAXIMUM )
Get the last index of the element matching with the specified value, searching from the end.
Void Remove( SInt32 index )
Remove( SInt32 begin , SInt32 end )
Remove the elements at the specified index or range.
Void RemoveFirst( Void )
Remove the first element.
Void RemoveLast( Void )
Remove the last element.
SFCError Set( SFXList< V > const & collection )
Set( SInt32 index , V value )
Set a value to the element. Or set a list.
SFCError SetFirst( V value )
Set a value to the first element.
SFCError SetLast( V value )
Set a value to the last element.
Types
Enumerator
Class for managing an enumerator.
Iterator
Class for managing an iterator.

SFXList::SFXList
Constructor of SFXList class.
[ public, explicit ]
SFXList(Void);

SFXList::Append
[DEPRECATED] Append an element.
[ public ]
SFCError Append(
    SFXList< V > const & collection   // list to append
);
[ public ]
SFCError Append(
    V value   // element to append
);

Return value

  • Success : SFERR_NO_ERROR
  • If insufficient memory : SFERR_NO_MEMOERY
  • If failed : SFERR_FAILED

Description

Append an element at the end of list. This function is deprecated, use InsertLast function.

Example

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 
        }
    }
}

Reference

SFXList::Insert | SFXList::InsertLast | SFXList::Get | SFXList::Remove | SFXList::Set


SFXList::Clear
Clear the list.
[ public ]
Void Clear(Void);

Description

If the type of element is a pointer to a class instance, the instance is not released automatically.

Example

SFXList<SInt32> list;
    
...
     
list.Clear();    // release all the data and memory for management

Reference

SFXList::Remove


SFXList::Contains
Check whether the value is contained or not.
[ public, const ]
Bool Contains(
    V value   // value to check
);

Return value

  • If contained : true
  • If not contained : false

Description

If the type of element is a pointer to a class instance, its address is compared with.

Example

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 the element is contained or not
        TRACE("Contains(2) = %s", (list.Contains(2)) ? ("true") : ("false"));  // contains(2) = true
        TRACE("Contains(4) = %s", (list.Contains(4)) ? ("true") : ("false"));  // contains(4) = false
    }
}

Reference

SFXList::FirstIndexOf


SFXList::EmptyInstance
Get an empty list.
[ public, static ]
SFXList< V > const & EmptyInstance(Void);

Description

Get an instance that represents an empty list.


SFXList::Equals
Check whether to equal the specified list or not.
[ public, const ]
Bool Equals(
    SFXList< V > const & collection   // list to compare with
);

Return value

  • If equal : true
  • If not equal : false

Description

Check about two lists whether the same element is saved in the same order or not.

If the type of element is a pointer to a class instance, its address is compared.


SFXList::FirstIndexOf
Get the first index of the element matching with the specified value, searching from the beginning.
[ public, const ]
SInt32 FirstIndexOf(
    V value                         // value to search
    SInt32 index = SINT32_MINIMUM   // beginning index to search from
);

Return value

  • Success : index of the element to match with the value
  • If failed : -1

Description

Search from beginning to end, and get the first index of the element to match with the value.

By specifying a starting index, you can search from any position other than the beginning. (The origin index is 0.)

If the type of element is a pointer to a class instance, its address is compared.

Example

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 matching with 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
    }
}

Reference

SFXList::Contains | SFXList::LastIndexOf


SFXList::Get
Get an element.
[ public, const ]
V Get(
    SInt32 index   // index of the element to get
);

Reference

SFXList::GetFirst | SFXList::GetLast | SFXList::Insert | SFXList::Remove | SFXList::Set


SFXList::GetEnumerator
Get an enumerator.
[ public, const ]
Enumerator GetEnumerator(
    SInt32 index   // index to start
);

Reference

SFXList::GetIterator | SFXList::Enumerator


SFXList::GetFirst
Get the first element.
[ public, const ]
V GetFirst(Void);

Reference

SFXList::Get | SFXList::GetLast


SFXList::GetFirstEnumerator
Get the enumerator that points to the first element.
[ public, const ]
Enumerator GetFirstEnumerator(Void);

Example

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 
        }
    }
}

Reference

SFXList::GetFirstIterator | SFXList::Enumerator


SFXList::GetFirstIterator
Get the iterator that points to the first element.
[ public ]
Iterator GetFirstIterator(Void);

Example

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 
        }
    }
}

Reference

SFXList::GetFirstEnumerator | SFXList::Iterator


SFXList::GetIterator
Get an iterator.
[ public ]
Iterator GetIterator(
    SInt32 index   // index to start
);

Reference

SFXList::GetEnumerator | SFXList::Iterator


SFXList::GetLast
Get the last element.
[ public, const ]
V GetLast(Void);

Reference

SFXList::Get | SFXList::GetFirst


SFXList::GetLastEnumerator
Get the enumerator that points to the last element.
[ public, const ]
Enumerator GetLastEnumerator(Void);

Reference

SFXList::GetLastIterator | SFXList::Enumerator


SFXList::GetLastIterator
Get the iterator that points to the last element.
[ public ]
Iterator GetLastIterator(Void);

Reference

SFXList::GetLastEnumerator | SFXList::Iterator


SFXList::GetSize
Get the size(the number of elements).
[ public, const ]
SInt32 GetSize(Void);

Example

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 elements)
        TRACE("%d", list.GetSize());  // 2
    }
}

SFXList::Insert
Insert an element.
[ public ]
SFCError Insert(
    SInt32 index                      // index to insert
    SFXList< V > const & collection   // value of the element to insert
);
[ public ]
SFCError Insert(
    SInt32 index   // index to insert
    V value        // value of the element to insert
);

Return value

  • Success : SFERR_NO_ERROR
  • If insufficient memory: SFERR_NO_MEMOERY
  • If failed : SFERR_FAILED

Description

Insert an element before the specified index.

If the specified index is invalid, the element is inserted at the valid position automatically.

Example

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) {
        // insert an element at the first index
        if (list.Insert(0, 3) == SFERR_NO_ERROR) {
            // insert an element
            // if the specified index is invalid, the element is inserted at the valid position automatically
            if (list.Insert(10, 4) == SFERR_NO_ERROR) {
                // enumerate elements by index
                for (i = 0; i < list.GetSize(); ++i) {
                    TRACE("%d", list.Get(i));  // 3 2 5 4
               }
           }
       }
    }
}

Reference

SFXList::Get | SFXList::InsertFirst | SFXList::InsertLast | SFXList::Remove | SFXList::Set


SFXList::InsertFirst
Insert an element at the beginning.
[ public ]
SFCError InsertFirst(
    SFXList< V > const & collection   // list to insert
);
[ public ]
SFCError InsertFirst(
    V value   // value of the element to insert
);

Return value

  • Success : SFERR_NO_ERROR
  • If insufficient memory: SFERR_NO_MEMOERY
  • If failed : SFERR_FAILED

Reference

SFXList::Insert | SFXList::InsertLast


SFXList::InsertLast
Insert an element at the end.
[ public ]
SFCError InsertLast(
    SFXList< V > const & collection   // list to insert
);
[ public ]
SFCError InsertLast(
    V value   // value of the element to insert
);

Return value

  • Success : SFERR_NO_ERROR
  • If insufficient memory: SFERR_NO_MEMOERY
  • If failed : SFERR_FAILED

Reference

SFXList::Insert | SFXList::InsertFirst


SFXList::IsEmpty
Check whether the list is empty or not.
[ public, const ]
Bool IsEmpty(Void);

Return value

  • If empty : true
  • If not empty : false

SFXList::LastIndexOf
Get the last index of the element matching with the specified value, searching from the end.
[ public, const ]
SInt32 LastIndexOf(
    V value                         // value to search
    SInt32 index = SINT32_MAXIMUM   // index to search from
);

Return value

  • Success : index of the element to match with the value
  • If failed : -1

Description

Search from end to beginning, and get the last index of the element to match with the value.

By specifying a starting index, you can search from any position other than the end. (The origin index is 0.)

If the type of element is a pointer to a class instance, its address is compared.

Example

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 matching with 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
    }
}

Reference

SFXList::Contains | SFXList::FirstIndexOf


SFXList::Remove
Remove the elements at the specified index or range.
[ public ]
Void Remove(
    SInt32 index   // index to remove
);
[ public ]
Void Remove(
    SInt32 begin   // beginning index to remove
    SInt32 end     // end index to remove
);

Reference

SFXList::Insert | SFXList::Get | SFXList::Set


SFXList::RemoveFirst
Remove the first element.
[ public ]
Void RemoveFirst(Void);

Reference

SFXList::Remove | SFXList::RemoveLast


SFXList::RemoveLast
Remove the last element.
[ public ]
Void RemoveLast(Void);

Reference

SFXList::Remove | SFXList::RemoveFirst


SFXList::Set
Set a value to the element. Or set a list.
[ public ]
SFCError Set(
    SFXList< V > const & collection   // list to set
);
[ public ]
SFCError Set(
    SInt32 index   // index to set
    V value        // value to set
);

Return value

  • Success : SFERR_NO_ERROR
  • If insufficient memory : SFERR_NO_MEMOERY
  • If invalid parameter : SFERR_INVALID_PARAM
  • If failed : SFERR_FAILED

Example

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
           }
       }
    }
}

Reference

SFXList::Get | SFXList::Insert | SFXList::Remove


SFXList::SetFirst
Set a value to the first element.
[ public ]
SFCError SetFirst(
    V value   // value to set
);

Return value

  • Success : SFERR_NO_ERROR
  • If failed : SFERR_INVALID_STATE

Reference

SFXList::GetFirst


SFXList::SetLast
Set a value to the last element.
[ public ]
SFCError SetLast(
    V value   // value to set
);

Return value

  • Success : SFERR_NO_ERROR
  • If failed : SFERR_INVALID_STATE

Reference

SFXList::GetLast


SFXList::Enumerator
Class for managing an enumerator.
[ 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;
};

Description

The Enumerator class is a class that manages an enumerator.

The Enumerator class has the following member functions.

GetNext Get the next element. If no next element, return null.
GetPrevious Get the previous element. If no previous element, return null.
HasNext Check whether the next element exists or not.
HasPrevious Check whether the previous element exists or not.
IsValid Check whether the enumerator is valid or not.

Example

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 
        }
    }
}

Reference

SFXList::Iterator


SFXList::Iterator
Class for managing an iterator.
[ 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;
};

Description

The Iterator class is a class that manages an iterator.

The Iterator class has the following member functions.

Set Set a value to the element of current iterator.
GetNext Get the next element. If no next element, return null.
GetPrevious Get the previous element. If no previous element, return null.
HasNext Check whether the next element exists or not.
HasPrevious Check whether the previous element exists or not.
IsValid Check whether the iterator is valid or not.
Insert Insert an element after the element of current iterator.
Remove Remove the element of current iterator.

Example

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 
        }
    }
}

Reference

SFXList::Enumerator