PrevNextUpHome BREW C++ Class Library & GUI Framework & XML Middleware : SophiaFramework 4.1
SFXArray
Class that represents an array.
#include <SFXArray.h.hpp>
class SFXArray;
SFMTYPEDEFCLASS(SFXArray)

Inheritance diagram

 Inheritance diagram of SFXArrayClass

Collaboration diagram

 Collaboration diagram of SFXArrayClass

Description

Each element of the SFXArray instance ( array ) 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 SFXArray instance ( array ), a pointer should be used.

// data more than 4 bytes or class instance cannot be an element of the SFXArray instance ( array )

// SFXArray<SInt64> ar64;           NG
// SFXArray<SFXAnsiString> arstr;   NG

// but a pointer to the data more than 4 bytes or class instance can be an element of the SFXArray instance ( array )

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

Reference

SFXList | SFXStack | Collection

Member

Constructor/Destructor
SFXArray( Void )
Constructor of SFXArray class.
SFXArray( UInt16 threshold , UInt16 cluster )
Constructor of SFXArray class.
Public Functions
SFCError Append( V value )
Append( SFXArray< V > const & collection )
[DEPRECATED] Append an element.
Void Clear( Void )
Clear the array.
Bool Contains( V value )
Check whether the value is contained or not.
static
SFXArray< V > const &
EmptyInstance( Void )
Get an empty array.
Bool Equals( SFXArray< V > const & collection )
Check whether to equal the specified array or not.
SInt32 FirstIndexOf( V value , SInt32 index = SINT32_MINIMUM )
Get the first index of the element to match with the specified value, searching from the beginning.
V Get( SInt32 index )
Get an element.
UInt16 GetCluster( Void )
Get the cluster size of internal buffer memory.
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).
UInt16 GetThreshold( Void )
Get the minimum value of internal buffer size.
SFCError Insert( SInt32 index , V value )
Insert( SInt32 index , SFXArray< V > const & collection )
Insert an element.
SFCError InsertFirst( SFXArray< V > const & collection )
InsertFirst( V value )
Insert an element at the beginning.
SFCError InsertLast( SFXArray< V > const & collection )
InsertLast( V value )
Insert an element at the end.
Bool IsEmpty( Void )
Check whether the array is empty or not.
SInt32 LastIndexOf( V value , SInt32 index = SINT32_MAXIMUM )
Get the last index of the element to match 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( SFXArray< V > const & collection )
Set( SInt32 index , V value )
Set a value to the element. Or set an array.
Void SetCluster( UInt16 size )
Set the cluster size of internal buffer memory.
SFCError SetFirst( V value )
Set a value to the first element.
SFCError SetLast( V value )
Set a value to the last element.
SFCError SetSize( SInt32 size )
Set the size of array.( Set the number of elements )
Void SetThreshold( UInt16 size )
Set the minimum value of internal buffer size.
V & operator[]( SInt32 index )
Get the element by index.
V const & operator[]( SInt32 index )
Get the element by index.
Types
DefaultEnum
Default values of minimun heap size and cluster size used inside the array.
Enumerator
Class for managing an enumerator.
Iterator
Class for managing an iterator.

SFXArray::SFXArray
Constructor of SFXArray class.
[ public, explicit ]
SFXArray(Void);
[ public, explicit ]
SFXArray(
    UInt16 threshold   // minimum value of buffer size
    UInt16 cluster     // cluster size
);

Description

When constructing an array, if you can guess the number of its elements, you should specify its initial size in order to improve performance. Because memory reallocation can be avoided.

delegates the control privilege of specified data to the SFXHeap object.

SFXArray::Set


SFXArray::Append
[DEPRECATED] Append an element.
[ public ]
SFCError Append(
    V value   // element to append
);
[ public ]
SFCError Append(
    SFXArray< V > const & collection   // array 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 array. This function is deprecated, use InsertLast function.

Example

SFXArray<SInt16> array;
SInt16 i;

// append an element
if (array.Append(2) == SFERR_NO_ERROR) {
    // append an element
    if (array.Append(5) == SFERR_NO_ERROR) {
        // enumerate by index
        for (i = 0; i < array.GetSize(); ++i) {
            TRACE("%d", array[i]);  // 2 5 
        }
    }
}

Reference

SFXArray::Insert | SFXArray::InsertLast | SFXArray::Get | SFXArray::Remove | SFXArray::Set


SFXArray::Clear
Clear the array.
[ public ]
Void Clear(Void);

Description

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

Example

SFXArray<SInt16> array;
    
...
     
array.Clear();    // release all the data and memory for management

Reference

SFXArray::Remove


SFXArray::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

SFXArray<SInt16> array;

// append an element
if (array.InsertLast(2) == SFERR_NO_ERROR) {
    // append an element
    if (array.InsertLast(5) == SFERR_NO_ERROR) {
        // check whether the element is contained or not
        TRACE("Contains(2) = %s", (array.Contains(2)) ? ("true") : ("false"));  // contains(2) = true
        TRACE("Contains(4) = %s", (array.Contains(4)) ? ("true") : ("false"));  // contains(4) = false
    }
}

Reference

SFXArray::FirstIndexOf


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

Description

Get an instance that represents an empty array.


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

Return value

  • If equal : true
  • If not equal : false

Description

Check about two arrays 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.


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

Return value

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

Description

Search from beginning to end, and get the first index of the element to match with the specified 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

SFXArray<SInt16> array;

// append an element
if (array.InsertLast(2) == SFERR_NO_ERROR) {
    // append an element
    if (array.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", array.FirstIndexOf(1));  // firstIndexOf(1) = -1
        TRACE("FirstIndexOf(2) = %d", array.FirstIndexOf(2));  // firstIndexOf(2) = 0
        TRACE("FirstIndexOf(5) = %d", array.FirstIndexOf(5));  // firstIndexOf(5) = 1
    }
}

Reference

SFXArray::Contains | SFXArray::LastIndexOf


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

Reference

SFXArray::GetFirst | SFXArray::GetLast | SFXArray::Insert | SFXArray::Remove | SFXArray::Set


SFXArray::GetCluster
Get the cluster size of internal buffer memory.
[ public, const ]
UInt16 GetCluster(Void);

Reference

SFXArray::SetCluster


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

Reference

SFXArray::GetIterator | SFXArray::Enumerator


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

Reference

SFXArray::Get | SFXArray::GetLast


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

Example

SFXArray<SInt16> array;
SFXArray<SInt16>::Enumerator en;

// append an element
if (array.InsertLast(2) == SFERR_NO_ERROR) {
    // append an element
    if (array.InsertLast(5) == SFERR_NO_ERROR) {
        
        // get the enumerator that points to the first element
        en = array.GetFirstEnumerator();
        
        // check whether the next element exists or not
        while(en.HasNext()) {
            TRACE("%d", en.GetNext());  // 2 5 
        }
    }
}

Reference

SFXArray::GetFirstIterator | SFXArray::Enumerator


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

Example

SFXArray<SInt16> array;
SFXArray<SInt16>::Iterator it;

// append an element
if (array.InsertLast(2) == SFERR_NO_ERROR) {
    // append an element
    if (array.InsertLast(5) == SFERR_NO_ERROR) {
        
        // get the iterator that points to the first element
        it = array.GetFirstIterator();
        
        // check whether the next element exists or not
        while(it.HasNext()) {
            TRACE("%d", it.GetNext());  // 2 5 
        }
    }
}

Reference

SFXArray::GetFirstEnumerator | SFXArray::Iterator


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

Reference

SFXArray::GetEnumerator | SFXArray::Iterator


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

Reference

SFXArray::Get | SFXArray::GetFirst


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

Reference

SFXArray::GetLastIterator | SFXArray::Enumerator


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

Reference

SFXArray::GetLastEnumerator | SFXArray::Iterator


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

Example

SFXArray<SInt16> array;

// append an element
if (array.InsertLast(2) == SFERR_NO_ERROR) {
    // append an element
    if (array.InsertLast(5) == SFERR_NO_ERROR) {
            // display the size(the number of elements)
            TRACE("%d",array.GetSize());  // 2
    }
}

Reference

SFXArray::SetSize


SFXArray::GetThreshold
Get the minimum value of internal buffer size.
[ public, const ]
UInt16 GetThreshold(Void);

Reference

SFXArray::SetThreshold


SFXArray::Insert
Insert an element.
[ public ]
SFCError Insert(
    SInt32 index   // index to insert
    V value        // value of the element to insert
);
[ public ]
SFCError Insert(
    SInt32 index                       // index to insert
    SFXArray< V > const & collection   // array 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

SFXArray<SInt16> array;
SInt16 i;

// append an element
if (array.InsertLast(2) == SFERR_NO_ERROR) {
    // append an element
    if (array.InsertLast(5) == SFERR_NO_ERROR) {
        // insert an element at the first index
        if (array.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 (array.Insert(10, 4) == SFERR_NO_ERROR) {
                // enumerate elements by index
                for (i = 0; i < array.GetSize(); ++i) {
                    TRACE("%d", array[i]);  // 3 2 5 4
               }
           }
       }
    }
}

Reference

SFXArray::Get | SFXArray::InsertFirst | SFXArray::InsertLast | SFXArray::Remove | SFXArray::Set


SFXArray::InsertFirst
Insert an element at the beginning.
[ public ]
SFCError InsertFirst(
    SFXArray< V > const & collection   // array 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

SFXArray::Insert | SFXArray::InsertLast


SFXArray::InsertLast
Insert an element at the end.
[ public ]
SFCError InsertLast(
    SFXArray< V > const & collection   // array 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

SFXArray::Insert | SFXArray::InsertFirst


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

Return value

  • If empty : true
  • If not empty : false

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

Return value

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

Description

Search from end to beginning, and get the last index of the element to match with the specified 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

SFXArray<SInt16> array;

// append an element
if (array.InsertLast(2) == SFERR_NO_ERROR) {
    // append an element
    if (array.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", array.LastIndexOf(1));  // lastIndexOf(1) = -1
        TRACE("LastIndexOf(2) = %d", array.LastIndexOf(2));  // lastIndexOf(2) = 0
        TRACE("LastIndexOf(5) = %d", array.LastIndexOf(5));  // lastIndexOf(5) = 1
    }
}

Reference

SFXArray::Contains | SFXArray::FirstIndexOf


SFXArray::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
);

Example

SFXArray<SInt16> array;
SInt16 i;

// append an element
if (array.InsertLast(2) == SFERR_NO_ERROR) {
    // append an element
    if (array.InsertLast(5) == SFERR_NO_ERROR) {
        // insert an element at the beginning index
        if (array.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 (array.Insert(10, 4) == SFERR_NO_ERROR) {

                // remove from array[1] to array[2]
                array.Remove(1, 3);

                // enumerate elements by index
                for (i = 0; i < array.GetSize(); ++i) {
                    TRACE("%d", array[i]);  // 3 4
               }
           }
       }
    }
}

Reference

SFXArray::Insert | SFXArray::Get | SFXArray::Set


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

Reference

SFXArray::Remove | SFXArray::RemoveLast


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

Reference

SFXArray::Remove | SFXArray::RemoveFirst


SFXArray::Set
Set a value to the element. Or set an array.
[ public ]
SFCError Set(
    SFXArray< V > const & collection   // array 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

SFXArray<SInt16> array;
SInt16 i;

// append an element
if (array.InsertLast(2) == SFERR_NO_ERROR) {
    // append an element
    if (array.InsertLast(5) == SFERR_NO_ERROR) {
        // set a value to the element of array 
        if (array.Set(1, 10) == SFERR_NO_ERROR) {
            // enumerate elements by index
            for (i = 0; i < array.GetSize(); ++i) {
                TRACE("%d", array[i]);  // 2 10
           }
       }
    }
}

Reference

SFXArray::Get | SFXArray::Insert | SFXArray::Remove


SFXArray::SetCluster
Set the cluster size of internal buffer memory.
[ public ]
Void SetCluster(
    UInt16 size   // cluster size to set
);

Reference

SFXArray::GetCluster


SFXArray::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

SFXArray::GetFirst


SFXArray::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

SFXArray::GetLast


SFXArray::SetSize
Set the size of array.( Set the number of elements )
[ public ]
SFCError SetSize(
    SInt32 size   // size to set
);

Return value

  • Success : SFERR_NO_ERROR
  • If insufficient memory: SFERR_NO_MEMOERY

Description

If the specified size is smaller than the size of current array, elements after the specified size are removed.

Reference

SFXArray::GetSize


SFXArray::SetThreshold
Set the minimum value of internal buffer size.
[ public ]
Void SetThreshold(
    UInt16 size   // minimum value to set
);

Reference

SFXArray::GetThreshold


SFXArray::operator[]
Get the element by index.
[ public ]
V & operator[](
    SInt32 index   // index of element to get
);
[ public, const ]
V const & operator[](
    SInt32 index   // index of element to get
);

Reference

SFXArray::Get | SFXArray::Set


SFXArray::DefaultEnum
Default values of minimun heap size and cluster size used inside the array.
enum DefaultEnum {
    DEFAULT_THRESHOLD = 4 * sizeof(VoidPtr),      // default value of minimum heap size
    DEFAULT_CLUSTER   = 8 * sizeof(VoidPtr)       // default value of cluster size
};

Description

SFXArray::DefaultEnum has default values of minimun heap size and cluster size used inside the SFXArray class.

Concretely, they are set as follows.

  • DEFAULT_THRESHOLD ( minimum heap size ) = 4 * sizeof(VoidPtr)
  • DEFAULT_CLUSTER ( cluster size ) = 8 * sizeof(VoidPtr)

Reference

SFXClusterHeap


SFXArray::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

SFXArray<SInt16> array;
SFXArray<SInt16>::Enumerator en;

// append an element
if (array.InsertLast(2) == SFERR_NO_ERROR) {
    // append an element
    if (array.InsertLast(5) == SFERR_NO_ERROR) {
        
        // get the enumerator that points to the first element
        en = array.GetFirstEnumerator();
        
        // check whether the next element exists or not
        while(en.HasNext()) {
            TRACE("%d", en.GetNext());  // 2 5 
        }
    }

Reference

SFXArray::Iterator


SFXArray::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);
        Vold                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

SFXArray<SInt16> array;
SFXArray<SInt16>::Iterator it;

// append an element
if (array.InsertLast(2) == SFERR_NO_ERROR) {
    // append an element
    if (array.InsertLast(5) == SFERR_NO_ERROR) {
        
        // get the iterator that points to the first element
        it = array.GetFirstIterator();
        
        // check whether the next element exists or not
        while(it.HasNext()) {
            TRACE("%d", it.GetNext());  // 2 5 
        }
    }
}

Reference

SFXArray::Enumerator