PrevNextUpHome SophiaFramework UNIVERSE 5.3
SFXStack
Class which represents a stack.
#include <SFXStack.h.hpp>
class SFXStack;
SFMTYPEDEFCLASS(SFXStack)

Inheritance diagram

 Inheritance diagram of SFXStackClass

Collaboration diagram

 Collaboration diagram of SFXStackClass

Description

SFXStack is the data structure to store all its elements into the consecutive memory area(internal buffer) in which the last added element is removed first.

In the default settings, when the first element is inserted, the internal buffer will be allocated by the size set with the SFXStack::SetThreshold function(default: size for 4 elements). Then, in case memory becomes insufficient while elements are inserted one by one, the internal buffer will be expanded by the cluster size set with the SFXStack::SetCluster function(default: size for 8 elements). Here, the size of one element is 4 byte.

[Caution] Caution

When the internal buffer is expanded, new consecutive memory area bigger than the current one by the cluster size will be allocated and all data of existing elements will be copied there. Therefore, if expansion is performed frequently, it may become the cause of performance deterioration

If the number of the elements are known in advance, it is recommended to set the internal buffer size with the SFXStack::SetThreshold / SFXStack::SetCluster functions or to set the number of the elements with the SFXStack::SetSize function(*).

* If the internal buffer is expanded with the SFXStack::SetSize function, each element in the expanded area will be set to 0.

Each element size of SFXStack 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 SFXStack instance ( stack ), a pointer should be used.

// data more than 4 byte or class instance cannot be an element of the SFXStack instance ( stack )

// SFXStack<SInt64> st64;           NG
// SFXStack<SFXAnsiString> ststr;   NG

// but a pointer to the data more than 4 byte or class instance can be an element of the SFXStack instance ( stack )

SFXStack<SInt64Ptr> st64;        // OK
SFXStack<SFXAnsiStringPtr> ststr;// OK

Reference

SFXArray | SFXList | Stack

Member

Constructor/Destructor
SFXStack( Void )
Constructor of the SFXStack class.
SFXStack( UInt16 threshold , UInt16 cluster )
Constructor of the SFXStack class.
Public Functions
SFCError Append( SFXStack< V > const & collection )
[DEPRECATED] Append an element.
SFCError Append( V value )
[DEPRECATED] Append an element.
Void Clear( Void )
Clear this stack.
Bool Contains( V value )
Check whether or not this stack contains the specified value.
static
SFXStack< V > const &
EmptyInstance( Void )
Get an empty stack.
Bool Equals( SFXStack< V > const & collection )
Check whether or not this stack equals the specified stack.
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.
UInt16 GetCluster( Void )
Get the cluster size of the internal buffer memory. [in bytes]
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).
UInt16 GetThreshold( Void )
Get the minimum size of the internal buffer memory. [in bytes]
SFCError Insert( SInt32 index , SFXStack< V > const & collection )
Insert the specified element or stack before the specified index.
SFCError Insert( SInt32 index , V value )
Insert the specified element or stack before the specified index.
SFCError InsertFirst( SFXStack< V > const & collection )
Insert the specified element or stack at the head.
SFCError InsertFirst( V value )
Insert the specified element or stack at the head.
SFCError InsertLast( SFXStack< V > const & collection )
Insert the specified element or stack at the tail.
SFCError InsertLast( V value )
Insert the specified element or stack at the tail.
Bool IsEmpty( Void )
Check whether or not this stack 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.
V Peek( Void )
Get the top element from this stack.
V Pop( Void )
Get the top element of this stack and remove it.
SFCError Push( V value )
Append an element onto the stack.
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.
SInt32 Search( V value )
Get the index of the element that equals the specified value, searching from the top.
SFCError Set( SFXStack< V > const & collection )
Set the element at the specified index of this stack to the specified value. Or set this stack to the specified stack.
SFCError Set( SInt32 index , V value )
Set the element at the specified index of this stack to the specified value. Or set this stack to the specified stack.
Void SetCluster( UInt16 size )
Set the cluster size of the internal buffer memory. [in bytes]
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 SetSize( SInt32 size )
Set the size of this stack to the specified value.
Void SetThreshold( UInt16 size )
Set the minimum size of the internal buffer memory. [in bytes]
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.
V & operator[]( SInt32 index )
Get the element by index.
V const & operator[]( SInt32 index )
Get the element by index.
Types
DefaultEnum
Constants that represent the default values for the minimum size and the cluster size of the internal buffer memory. [in bytes]
Enumerator
Class for managing the enumerator of this stack.
Iterator
Class for managing the iterator of this stack.

SFXStack::SFXStack
Constructor of the SFXStack class.
[ public, explicit ]
SFXStack(Void);
[ public, explicit ]
SFXStack(
    UInt16 threshold   // minimum size of the internal buffer memory
    UInt16 cluster     // cluster size
);

Description

It is possible to improve performance by specifying the minimum size of the internal buffer memory and the cluster size optimized for your application in order to minimize the occurrence of memory reallocation.

[Tip] Tip
The minimum size of the internal buffer memory or the cluster size can be set with the SFXStack::SetThreshold or SFXStack::SetCluster function.

Reference

SFXStack::Set | SFXStack::SetThreshold | SFXStack::SetCluster


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

Return value

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

Description

Append an element at the end of stack. This function is deprecated, use the SFXStack::InsertLast function.

Example

SFXStack<SInt08> stack;
SInt16 i;

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

Reference

SFXStack::Insert | SFXStack::InsertLast | SFXStack::Get | SFXStack::Push | SFXStack::Remove | SFXStack::Set


SFXStack::Clear
Clear this stack.
[ public ]
Void Clear(Void);

Description

This function clears this stack. All the internal buffer allocated to this stack will be released.

After this function is executed, the size of this stack will become 0.

[Caution] 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 stack, it is necessary to release that area explicitly using the delete statement. Otherwise, memory leakage will occur.

[Note] Note
This function will be called automatically when this stack goes out of scope.

Example

SFXStack<SInt08> stack;
    
...
     
stack.Clear();    // clear the stack

Reference

SFXStack::Remove | SFXStack::SetCluster | SFXStack::SetThreshold | SFXStack::GetSize


SFXStack::Contains
Check whether or not this stack contains the specified value.
[ public, const ]
Bool Contains(
    V value   // value to check
);

Return value

  • If the specified value is contained: true
  • Otherwise: false

Description

This function checks whether or not this stack contains the specified value.

[Note] 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.

Example

SFXStack<SInt08> stack;

// push an element
if (stack.Push(2) == SFERR_NO_ERROR) {

    // push an element
    if (stack.InsertLast(5) == SFERR_NO_ERROR) {

        // check whether or not the stack contains the elements below
        TRACE("Contains(2) = %s", (stack.Contains(2)) ? ("true") : ("false"));  // contains(2) = true
        TRACE("Contains(4) = %s", (stack.Contains(4)) ? ("true") : ("false"));  // contains(4) = false
    }
}

Reference

SFXStack::FirstIndexOf | SFXStack::LastIndexOf


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

Description

Get an instance that represents an empty stack.


SFXStack::Equals
Check whether or not this stack equals the specified stack.
[ public, const ]
Bool Equals(
    SFXStack< V > const & collection   // stack to compare with
);

Return value

  • If this stack equals the specified stack: true
  • Otherwise: false

Description

This function checks whether or not this stack equals the specified stack (whether or not the same elements are saved in the same order).

[Note] Note
If the type of the element is a pointer, its address will be compared.

SFXStack::FirstIndexOf
Get the first index of the element that equals the specified value, searching from the head.
[ public, const ]
SInt32 FirstIndexOf(
    V value                         // value to search
    SInt32 index = SINT32_MINIMUM   // index to search from
);

Return value

  • If succeeds: index of the element that equals the specified value
  • If failed: -1

Description

This function gets the first index of the element of this stack 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] Note
If the type of the element is a pointer, its address will be compared.

Example

SFXStack<SInt08> stack;

// push an element onto the stack
if (stack.Push(2) == SFERR_NO_ERROR) {

    // push an element onto the stack
    if (stack.Push(5) == SFERR_NO_ERROR) {

        // get the first index of the element that equals the specified value, searching from the head to the tail
        TRACE("FirstIndexOf(1) = %d", stack.FirstIndexOf(1));  // firstIndexOf(1) = -1
        TRACE("FirstIndexOf(2) = %d", stack.FirstIndexOf(2));  // firstIndexOf(2) = 0
        TRACE("FirstIndexOf(5) = %d", stack.FirstIndexOf(5));  // firstIndexOf(5) = 1
    }
}

Reference

SFXStack::Contains | SFXStack::LastIndexOf


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

Return value

Element at the index specified in the argument. 0 or null will be returned if no element exists at the specified index.

Description

This function gets the element at the index specified in the argument.

[Caution] Caution
In case no element exists at the specified index, no error will occur but this function will return 0 or null.

Reference

SFXStack::GetFirst | SFXStack::GetLast | SFXStack::Insert | SFXStack::Remove | SFXStack::Set


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

Return value

Cluster size of the internal buffer memory [in bytes]

Description

This function gets the cluster size, by which the size of the internal buffer memory increases. [in bytes]

Reference

SFXStack::SetCluster


SFXStack::GetEnumerator
Get the enumerator that points to the element at the specified index.
[ public, const ]
Enumerator GetEnumerator(
    SInt32 index   // index to start
);

Return value

Enumerator that points to the element at the specified index

Description

This function gets the enumerator of this stack that points to the element at the specified index.

[Note] Note

If the specified index is less than or equals 0, this function is same as the SFXStack::GetFirstEnumerator function.

If the specified index is more than or equals the size of this stack, this function is same as the SFXStack::GetLastEnumerator function.

Reference

SFXStack::GetFirstEnumerator | SFXStack::GetLastEnumerator | SFXStack::GetIterator | SFXStack::Enumerator


SFXStack::GetFirst
Get the element at the head.
[ public, const ]
V GetFirst(Void);

Return value

Element at the head. 0 or null will be returned if no element exists in this stack.

Description

This function gets the element at the head.

[Caution] Caution
In case no element exists in this stack, no error will occur but this function will return 0 or null.

Reference

SFXStack::Get | SFXStack::GetLast | SFXStack::InsertFirst | SFXStack::RemoveFirst


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

Return value

Enumerator that points to the first element

Description

This function gets the enumerator of this stack that points to the first element.

Example

SFXStack<SInt08> stack;
SFXStack<SInt08>::Enumerator en;

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

Reference

SFXStack::GetEnumerator | SFXStack::GetFirstIterator | SFXStack::Enumerator


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

Return value

Iterator that points to the first element

Description

This function gets the iterator of this stack that points to the first element.

Example

SFXStack<SInt08> stack;
SFXStack<SInt08>::Iterator it;

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

Reference

SFXStack::GetIterator | SFXStack::GetFirstEnumerator | SFXStack::Iterator


SFXStack::GetIterator
Get the iterator that points to the element at the specified index.
[ public ]
Iterator GetIterator(
    SInt32 index   // index to start
);

Return value

Iterator that points to the element at the specified index

Description

This function gets the iterator of this stack that points to the element at the specified index.

[Note] Note

If the specified index is less than or equals 0, this function is same as the SFXStack::GetFirstIterator function.

If the specified index is more than or equals the size of this stack, this function is same as the SFXStack::GetLastIterator function.

Reference

SFXStack::GetFirstIterator | SFXStack::GetLastIterator | SFXStack::GetEnumerator | SFXStack::Iterator


SFXStack::GetLast
Get the element at the tail.
[ public, const ]
V GetLast(Void);

Return value

Element at the tail. 0 or null will be returned if no element exists in this stack.

Description

This function gets the element at the tail.

[Caution] Caution
In case no element exists in this stack, no error will occur but this function will return 0 or null.

Reference

SFXStack::Get | SFXStack::GetFirst | SFXStack::Peek | SFXStack::InsertLast | SFXStack::RemoveLast


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

Return value

Enumerator that points to the last element

Description

This function gets the enumerator of this stack that points to the last element.

Reference

SFXStack::GetEnumerator | SFXStack::GetLastIterator | SFXStack::Enumerator


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

Return value

Iterator that points to the last element

Description

This function gets the iterator of this stack that points to the last element.

Reference

SFXStack::GetIterator | SFXStack::GetLastEnumerator | SFXStack::Iterator


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

Example

SFXStack<SInt08> stack;
SInt16 i;

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

Reference

SFXStack::SetSize


SFXStack::GetThreshold
Get the minimum size of the internal buffer memory. [in bytes]
[ public, const ]
UInt16 GetThreshold(Void);

Return value

Minimum size of the internal buffer memory. [in bytes]

Description

This function gets the minimum size of the internal buffer memory. [in bytes]

Reference

SFXStack::SetThreshold


SFXStack::Insert
Insert the specified element or stack before the specified index.
[ public ]
SFCError Insert(
    SInt32 index                       // index to insert
    SFXStack< V > const & collection   // stack to insert
);
[ public ]
SFCError Insert(
    SInt32 index   // index to insert
    V value        // value of the element to insert
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If insufficient memory: SFERR_NO_MEMOERY

Description

This function inserts the specified element or stack 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.

Example

SFXStack<SInt08> stack;
SInt16 i;

// insert an element at the tail
if (stack.InsertLast(2) == SFERR_NO_ERROR) {
    // insert an element at the tail
    if (stack.InsertLast(5) == SFERR_NO_ERROR) {
        // insert an element at the head
        if (stack.Insert(0, 3) == SFERR_NO_ERROR) {
            // insert an element before 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 (stack.Insert(10, 4) == SFERR_NO_ERROR) {

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

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

Reference

SFXStack::InsertFirst | SFXStack::InsertLast | SFXStack::Set | SFXStack::Get | SFXStack::Remove


SFXStack::InsertFirst
Insert the specified element or stack at the head.
[ public ]
SFCError InsertFirst(
    SFXStack< V > const & collection   // stack to insert
);
[ public ]
SFCError InsertFirst(
    V value   // value of the element to insert
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If insufficient memory: SFERR_NO_MEMOERY

Description

This function the specified element or stack at the head.

Reference

SFXStack::Insert | SFXStack::InsertLast | SFXStack::RemoveFirst | SFXStack::GetFirst


SFXStack::InsertLast
Insert the specified element or stack at the tail.
[ public ]
SFCError InsertLast(
    SFXStack< V > const & collection   // stack to insert
);
[ public ]
SFCError InsertLast(
    V value   // value of the element to insert
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If insufficient memory: SFERR_NO_MEMOERY

Description

This function inserts the specified element or stack at the tail.

Reference

SFXStack::Insert | SFXStack::InsertFirst | SFXStack::Push | SFXStack::GetLast | SFXStack::RemoveLast


SFXStack::IsEmpty
Check whether or not this stack is empty.
[ public, const ]
Bool IsEmpty(Void);

Return value

  • If empty: true
  • Otherwise: false

Description

This function checks whether or not this stack is empty.


SFXStack::LastIndexOf
Get the last index of the element that equals the specified value, searching from the tail.
[ public, const ]
SInt32 LastIndexOf(
    V value                         // value to search
    SInt32 index = SINT32_MAXIMUM   // index to search from
);

Return value

  • If succeeds: index of the element that equals the specified value
  • If failed: -1

Description

This function gets the last index of the element of this stack 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] Note
If the type of the element is a pointer, its address will be compared.

Example

SFXStack<SInt08> stack;

// push an element onto the stack
if (stack.Push(2) == SFERR_NO_ERROR) {

    // push an element onto the stack
    if (stack.Push(5) == SFERR_NO_ERROR) {

        // get the last index of the element that equals the specified value, searching from the tail to the head
        TRACE("LastIndexOf(1) = %d", stack.LastIndexOf(1));  // lastIndexOf(1) = -1
        TRACE("LastIndexOf(2) = %d", stack.LastIndexOf(2));  // lastIndexOf(2) = 0
        TRACE("LastIndexOf(5) = %d", stack.LastIndexOf(5));  // lastIndexOf(5) = 1
    }
}

Reference

SFXStack::Contains | SFXStack::FirstIndexOf | SFXStack::Search


SFXStack::Move
Move the element at the specified index to the specified index.
[ public ]
SFCError Move(
    SInt32 destination   // destination index of the element to move
    SInt32 source        // source index of the element to move
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If no element exists at the specified index: SFERR_INVALID_PARAM

Description

This function moves the element at the specified index to the specified index.

Reference

SFXStack::MoveFirst | SFXStack::MoveLast


SFXStack::MoveFirst
Move the element at the specified index to the head.
[ public ]
SFCError MoveFirst(
    SInt32 source   // index of the element to move
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If this stack is empty: SFERR_INVALID_STATE
  • If no element exists at the specified index: SFERR_INVALID_PARAM

Description

This function moves the element at the specified index to the head.

Reference

SFXStack::Move | SFXStack::MoveLast


SFXStack::MoveLast
Move the element at the specified index to the tail.
[ public ]
SFCError MoveLast(
    SInt32 source   // index of the element to move
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If this stack is empty: SFERR_INVALID_STATE
  • If no element exists at the specified index: SFERR_INVALID_PARAM

Description

This function moves the element at the specified index to the tail.

Reference

SFXStack::Move | SFXStack::MoveFirst


SFXStack::Peek
Get the top element from this stack.
[ public, const ]
V Peek(Void);

Return value

Top element of this stack (Last pushed element)

Description

This function gets the the top element from this stack, which is the last pushed element.

[Caution] Caution
If this stack is empty, no error will occur, and 0 or null will be returned depending on the type of the element.
[Note] Note
After this function is executed, the contents of this stack will remain the same as before.

Example

SFXStack<SInt08> stack;

// push an element onto the stack
if (stack.Push(1) == SFERR_NO_ERROR) {    

    // get the top element from the stack
    TRACE("%d", stack.Peek());  // 1

    // push an element onto the stack
    if (stack.Push(2) == SFERR_NO_ERROR) { 
    
    	// get the top element from the stack
        TRACE("%d", stack.Peek());  // 2
        
        // push an element onto the stack
        if (stack.Push(3) == SFERR_NO_ERROR) {
        
            // get the top element from the stack
            TRACE("%d", stack.Peek());  // 3
        }
    }
}

Reference

SFXStack::Push | SFXStack::Pop | SFXStack::Get | SFXStack::GetFirst | SFXStack::GetLast


SFXStack::Pop
Get the top element of this stack and remove it.
[ public ]
V Pop(Void);

Return value

Top element of this stack. If this stack is empty, no error will occur and 0 will be returned.

Description

This function gets the top element of this stack and remove it.

[Caution] Caution
If this stack is empty, no error will occur, and 0 or null will be returned depending on the type of the element.

Example

SFXStack<SInt08> stack;

// append an element onto the stack
if (stack.Push(1) == SFERR_NO_ERROR) {    

    // append an element onto the stack
    if (stack.Push(2) == SFERR_NO_ERROR) { 
         
        // append an element onto the stack
        if (stack.Push(3) == SFERR_NO_ERROR) {
  
            // get the top element of stack and remove it
            TRACE("%d", stack.Pop());  // 3
            TRACE("%d", stack.Pop());  // 2
            TRACE("%d", stack.Pop());  // 1
        }
    }
}

Reference

SFXStack::Peek | SFXStack::Push| SFXStack::IsEmpty | SFXStack::Get | SFXStack::GetFirst | SFXStack::GetLast | SFXStack::Remove | SFXStack::RemoveFirst | SFXStack::RemoveLast


SFXStack::Push
Append an element onto the stack.
[ public ]
SFCError Push(
    V value   // element to append(push)
);

Return value

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

Description

Inside the Push function, the SFXStack::InsertLast function is called.

Example

SFXStack<SInt08> stack;

// append an element onto the stack
if (stack.Push(1) == SFERR_NO_ERROR) {    

    // get the top element of stack, but don't remove it
    TRACE("%d", stack.Peek());  // 1

    // append an element onto the stack
    if (stack.Push(2) == SFERR_NO_ERROR) { 
    
    	// get the top element of stack, but don't remove it
        TRACE("%d", stack.Peek());  // 2
        
        // append an element onto the stack
        if (stack.Push(3) == SFERR_NO_ERROR) {
        
            // get the top element of stack, but don't remove it
            TRACE("%d", stack.Peek());  // 3
        }
    }
}

Reference

SFXStack::Insert | SFXStack::InsertLast | SFXStack::Set | SFXStack::Pop | SFXStack::Peek


SFXStack::Remove
Remove the elements at the specified index or range.
[ 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)
);

Description

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] Caution
If no element exists at the specified index or range, no error will occur and nothing will happen.

Example

SFXStack<SInt08> stack;
SInt16 i;

// insert an element at the tail
if (stack.InsertLast(2) == SFERR_NO_ERROR) {

    // insert an element at the tail
    if (stack.InsertLast(5) == SFERR_NO_ERROR) {

        // insert an element at the head
        if (stack.Insert(0, 3) == SFERR_NO_ERROR) {

            // insert an element before 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 (stack.Insert(10, 4) == SFERR_NO_ERROR) {

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

                // enumerate elements by index
                for (i = 0; i < stack.GetSize(); ++i) {

                    TRACE("%d", stack[i]);  // 3 4
               }
           }
       }
    }
}

Reference

SFXStack::RemoveFirst | SFXStack::RemoveLast | SFXStack::Insert | SFXStack::Get | SFXStack::Set


SFXStack::RemoveFirst
Remove the element at the head.
[ public ]
Void RemoveFirst(Void);

Description

This function removes the element at the head.

[Caution] Caution
If no element exists in this stack, no error will occur and nothing will happen.

Reference

SFXStack::Remove | SFXStack::RemoveLast | SFXStack::GetFirst | SFXStack::InsertFirst


SFXStack::RemoveLast
Remove the element at the tail.
[ public ]
Void RemoveLast(Void);

Description

This function removes the element at the tail.

[Caution] Caution
If no element exists in this stack, no error will occur and nothing will happen.

Reference

SFXStack::Remove | SFXStack::RemoveFirst | SFXStack::GetLast | SFXStack::InsertLast | SFXStack::Pop


SFXStack::Search
Get the index of the element that equals the specified value, searching from the top.
[ public, const ]
SInt32 Search(
    V value   // value of the element to search for
);

Return value

  • If the element that equals the specified value is found: index of the element from the top of stack to match the value
  • Otherwise: -1

Description

This function gets the first index of the element of this stack that equals the specified value, searching from the top of this stack. (The index of the top is 1.)

[Note] Note
If the type of the element is a pointer, its address will be compared.

Example

SFXStack<SInt08> stack;

// append an element onto the stack
if (stack.Push(1) == SFERR_NO_ERROR) {    

    // append an element onto the stack
    if (stack.Push(2) == SFERR_NO_ERROR) { 
         
        // append an element onto the stack
        if (stack.Push(3) == SFERR_NO_ERROR) {
  
            // search from the top of stack
            TRACE("Search(3) = %d", stack.Search(3));  // 1
            TRACE("Search(5) = %d", stack.Search(5));  // -1
        }
    }
}

Reference

SFXStack::Contains | SFXStack::FirstIndexOf | SFXStack::LastIndexOf


SFXStack::Set
Set the element at the specified index of this stack to the specified value. Or set this stack to the specified stack.
[ public ]
SFCError Set(
    SFXStack< V > const & collection   // stack to set
);
[ public ]
SFCError Set(
    SInt32 index   // index to set
    V value        // value of the element to set
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If insufficient memory: SFERR_NO_MEMOERY
  • If no element exists at the specified index: SFERR_INVALID_PARAM

Description

This function sets the element at the specified index of this stack to the specified value, or sets this stack to the specified stack.

* In case an error occurs during processing, this stack will be restored.

Example

SFXStack<SInt08> stack;
SInt16 i;

// append an element
if (stack.Push(2) == SFERR_NO_ERROR) {

    // append an element
    if (stack.Push(5) == SFERR_NO_ERROR) {

        // set a value to the element
        if (stack.Set(1, 10) == SFERR_NO_ERROR) {

            // enumerate elements by index
            for (i = 0; i < stack.GetSize(); ++i) {

                TRACE("%d", stack[i]);  // 2 10
           }
       }
    }
}

Reference

SFXStack::Get | SFXStack::SetFirst | SFXStack::SetLast | SFXStack::Insert | SFXStack::Remove


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

Description

This function sets the minimum unit to allocate the internal buffer memory(SFXClusterHeap). [in bytes]

Default: SFXStack::DEFAULT_CLUSTER bytes

For the value of SFXStack::DEFAULT_CLUSTER, refer to SFXStack::DefaultEnum.

[Tip] Tip
Since the size of one element is 4 byte, a multiple of four should be specified in the size argument.
[Note] Internal buffer memory

In the SFXStack class, an element will be stored into the internal buffer memory when appended.

Initially, the size set with the SFXStack::SetThreshold function will be allocated as the internal buffer memory.

If an element cannot be stored into the internal buffer memory when tried to be appended, the size added by the cluster size set with the SFXStack::SetCluster function will be re-allocated as the internal buffer memory.

To minimize the re-allocation of the the internal buffer memory, it is recommended to optimize the size set with the SFXStack::SetThreshold / SFXStack::SetCluster function depending on the application characteristics.

Reference

SFXStack::GetCluster | SFXStack::SetThreshold | SFXStack::DefaultEnum | SFXClusterHeap::SetCluster | SFXClusterHeap


SFXStack::SetFirst
Set the element at the head to the specified value.
[ public ]
SFCError SetFirst(
    V value   // value of the element to set
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If this stack is empty: SFERR_INVALID_STATE

Description

This function sets the element at the head to the specified value.

Reference

SFXStack::GetFirst | SFXStack::Set | SFXStack::SetLast


SFXStack::SetLast
Set the element at the tail to the specified value.
[ public ]
SFCError SetLast(
    V value   // value of the element to set
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If this stack is empty: SFERR_INVALID_STATE

Description

This function sets the element at the tail to the specified value.

Reference

SFXStack::GetLast | SFXStack::Set | SFXStack::SetFirst


SFXStack::SetSize
Set the size of this stack to the specified value.
[ public ]
SFCError SetSize(
    SInt32 size   // size to set
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If insufficient memory: SFERR_NO_MEMOERY

Description

This function sets the size of this stack to the specified value.

[Note] Note
If the specified size is smaller than the current size of this stack, elements after the specified size will be removed. On the contrary, if it is bigger than the current size of this stack, each of the expanded elements will be set to 0.

Reference

SFXStack::GetSize


SFXStack::SetThreshold
Set the minimum size of the internal buffer memory. [in bytes]
[ public ]
Void SetThreshold(
    UInt16 size   // minimum size of the internal buffer memory to set
);

Description

This function sets the minimum memory of the internal buffer memory(SFXClusterHeap). [in bytes]

Default: SFXStack::DEFAULT_THRESHOLD bytes

For the value of SFXStack::DEFAULT_THRESHOLD, refer to SFXStack::DefaultEnum.

[Tip] Tip
Since the size of one element is 4 byte, a multiple of four should be specified in the size argument.
[Note] Internal buffer memory

In the SFXStack class, an element will be stored into the internal buffer memory when appended.

Initially, the size set with the SFXStack::SetThreshold function will be allocated as the internal buffer memory.

If an element cannot be stored into the internal buffer memory when tried to be appended, the size added by the cluster size set with the SFXStack::SetCluster function will be re-allocated as the internal buffer memory.

To minimize the re-allocation of the the internal buffer memory, it is recommended to optimize the size set with the SFXStack::SetThreshold / SFXStack::SetCluster function depending on the application characteristics.

Reference

SFXStack::GetThreshold | SFXStack::SetCluster | SFXStack::DefaultEnum | SFXClusterHeap::SetThreshold | SFXClusterHeap


SFXStack::Swap
Swap two elements at the specified indexes.
[ public ]
SFCError Swap(
    SInt32 destination   // destination index
    SInt32 source        // source index
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If no element exists at the specified index: SFERR_INVALID_PARAM

Description

This function swaps two elements at the specified indexes.

Reference

SFXStack::SwapFirst | SFXStack::SwapLast


SFXStack::SwapFirst
Swap the element at the specified index for the element at the head.
[ public ]
SFCError SwapFirst(
    SInt32 source   // source index
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If this stack is empty: SFERR_INVALID_STATE
  • If no element exists at the specified index: SFERR_INVALID_PARAM

Description

This function swaps the element at the specified index for the element at the head.

Reference

SFXStack::Swap | SFXStack::SwapLast


SFXStack::SwapLast
Swap the element at the specified index for the element at the tail.
[ public ]
SFCError SwapLast(
    SInt32 source   // source index
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If this stack is empty: SFERR_INVALID_STATE
  • If no element exists at the specified index: SFERR_INVALID_PARAM

Description

This function swaps the element at the specified index for the element at the tail.

Reference

SFXStack::Swap | SFXStack::SwapFirst


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

Reference

SFXStack::Get | SFXStack::Set


SFXStack::DefaultEnum
Constants that represent the default values for the minimum size and the cluster size of the internal buffer memory. [in bytes]
enum DefaultEnum {
    DEFAULT_THRESHOLD = 4 * 4,     // default minimum size of the internal buffer memory [in bytes]
    DEFAULT_CLUSTER   = 8 * 4      // default cluster size to allocate the internal buffer memory [in bytes]
};

Description

DEFAULT_THRESHOLD and DEFAULT_CLUSTER are the constants that represent the default values for the minimum size and the cluster size of the internal buffer memory(SFXClusterHeap). [in bytes]

Reference

SFXStack::SetCluster | SFXStack::SetThreshold | SFXClusterHeap


SFXStack::Enumerator
Class for managing the enumerator of this stack.
[ public ]

SFMTYPEDEFCLASS(Enumerator)
friend class Enumerator;
class Enumerator {
    public:
        explicit            Enumerator          (Void) : Enumeratoa();
                            Enumerator          (IteratorConstRef iterator) : Enumeratox(iterator);
        EnumeratorRef       operator=           (IteratorConstRef iterator);
        V                   GetNext             (Void);
        V                   GetPrevious         (Void);
        Bool                HasNext             (Void) const;
        Bool                HasPrevious         (Void) const;
        Bool                IsValid             (Void) const;
};

Description

This class is for managing the enumerator of this stack.

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.

Example

SFXStack<SInt08> stack;
SFXStack<SInt08>::Enumerator en;

// append an element
if (stack.InsertLast(2) == SFERR_NO_ERROR) {

    // append an element
    if (stack.InsertLast(5) == SFERR_NO_ERROR) {
        
        // get the enumerator that points to the first element
        en = stack.GetFirstEnumerator();
        
        // check whether the next element exists or not
        while(en.HasNext()) {

            TRACE("%d", en.GetNext());  // 2 5 
        }
    }
}

Reference

SFXStack::Iterator


SFXStack::Iterator
Class for managing the iterator of this stack.
[ 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

This class is for managing the iterator of this stack.

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.

Example

SFXStack<SInt08> stack;
SFXStack<SInt08>::Iterator it;

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

Reference

SFXStack::Enumerator