A OOP class for implementing stacks -massively upgraded
Posted: Tue Oct 30, 2007 10:27 pm
Update : 22nd November 2007.
Have added a new method, namely; Peek().
This allows you to examine an element from a stack without affecting the stack at all; that is no kind of 'pop' action is performed.
Note that the index supplied to this method is zero-based and thus must be a value within the range 0 to NumberOfElementsPushed()-1 etc.
The user manual has been updated.
Download
Bug fix : 8th November 2007.
A bug with popping structures containing string fields has been fixed.
Download
Upgraded : 1st November 2007.
Hi,
I have restructured the class so that we now have two stack classes inheriting (
) from a single base class. The first class gives a basic stack (as previous) in which stack objects can be created dynamically and 32-bit values pushed and popped at will.
A second class (sharing the same method names to give some kind of polymorphism!) allows you to push and pop any kind of structure, even those containing string fields. No need to worry about memory leaks as all strings are carefully freed etc.
It is important to understand exactly how these more complex stack objects function :
The download includes a couple of examples + a very short user guide. Don't worry if you're not up to scratch with OOP terminology as this little library is very simple to use.
Download
Hi,
I'm rewriting some old utility routines of mine, but this time in the form of simple OOP classes as this is the way I seem to be heading lately. And why not indeed? Basic OOP is a breeze in Purebasic!
This first utility allows the developer to easily create stack objects with all the usual functionality etc.
Create a stack object with something like :
Push a value with :
and so on.
REMAINDER OF POST REMOVED.
Have added a new method, namely; Peek().
This allows you to examine an element from a stack without affecting the stack at all; that is no kind of 'pop' action is performed.
Note that the index supplied to this method is zero-based and thus must be a value within the range 0 to NumberOfElementsPushed()-1 etc.
The user manual has been updated.
Download
Bug fix : 8th November 2007.
A bug with popping structures containing string fields has been fixed.

Download
Upgraded : 1st November 2007.
Hi,
I have restructured the class so that we now have two stack classes inheriting (

A second class (sharing the same method names to give some kind of polymorphism!) allows you to push and pop any kind of structure, even those containing string fields. No need to worry about memory leaks as all strings are carefully freed etc.
It is important to understand exactly how these more complex stack objects function :
When the developer pushes a structured variable, the entire structure is copied (including string fields) and placed on the underlying stack. This means that, having pushed such a variable onto a structured stack, the developer is then free to modify the original variable, safe in the knowledge that the original fields are preserved on the stack.
The only proviso is that all string fields must be placed before all other fields.
The download includes a couple of examples + a very short user guide. Don't worry if you're not up to scratch with OOP terminology as this little library is very simple to use.

Download
Hi,
I'm rewriting some old utility routines of mine, but this time in the form of simple OOP classes as this is the way I seem to be heading lately. And why not indeed? Basic OOP is a breeze in Purebasic!

This first utility allows the developer to easily create stack objects with all the usual functionality etc.
Create a stack object with something like :
Code: Select all
MyStackObject.StackObject
MyStackObject = NewStack(100) ;For a stack of size 100 etc.
Code: Select all
MyStackObject\Push(25) ;Pushes the value 25 for example.
REMAINDER OF POST REMOVED.