Merge pull request #188 from alliedmodders/tr-stack
Port adt_stack to transitional syntax.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* vim: set ts=4 :
|
||||
* vim: set ts=4 sw=4 tw=99 noet :
|
||||
* =============================================================================
|
||||
* SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
|
||||
* SourceMod (C)2004-2014 AlliedModders LLC. All rights reserved.
|
||||
* =============================================================================
|
||||
*
|
||||
* This file is part of the SourceMod/SourcePawn SDK.
|
||||
@@ -35,6 +35,82 @@
|
||||
#endif
|
||||
#define _adt_stack_included
|
||||
|
||||
methodmap ArrayStack < Handle
|
||||
{
|
||||
// Creates a stack structure. A stack is a LIFO (last in, first out)
|
||||
// vector (array) of items. It has O(1) insertion and O(1) removal.
|
||||
//
|
||||
// Stacks have two operations: Push (adding an item) and Pop (removes
|
||||
// items in reverse-push order).
|
||||
//
|
||||
// The contents of the stack are uniform; i.e. storing a string and then
|
||||
// retrieving it as an integer is NOT the same as StringToInt()!
|
||||
//
|
||||
// The "blocksize" determines how many cells each slot has; it cannot
|
||||
// be changed after creation.
|
||||
//
|
||||
// @param blocksize The number of cells each entry in the stack can
|
||||
// hold. For example, 32 cells is equivalent to:
|
||||
// new Array[X][32]
|
||||
public native ArrayStack(int blocksize=1);
|
||||
|
||||
// Pushes a value onto the end of the stack, adding a new index.
|
||||
//
|
||||
// This may safely be used even if the stack has a blocksize
|
||||
// greater than 1.
|
||||
//
|
||||
// @param value Value to push.
|
||||
public native void Push(any value);
|
||||
|
||||
// Pushes a copy of a string onto the end of a stack, truncating it if it
|
||||
// is too big.
|
||||
//
|
||||
// @param value String to push.
|
||||
public native void PushString(const char[] value);
|
||||
|
||||
// Pushes a copy of an array of cells onto the end of a stack. The cells
|
||||
// are pushed as a block (i.e. the entire array takes up one stack slot),
|
||||
// rather than pushing each cell individually.
|
||||
//
|
||||
// @param stack Stack Handle.
|
||||
// @param values Block of values to copy.
|
||||
// @param size If not set, the number of elements copied from the array
|
||||
// will be equal to the blocksize. If set higher than the
|
||||
// blocksize, the operation will be truncated.
|
||||
public native void PushArray(const any[] values, int size=-1);
|
||||
|
||||
// Pops a cell value from a stack.
|
||||
//
|
||||
// @param block Optionally specify which block to read from
|
||||
// (useful if the blocksize > 0).
|
||||
// @param asChar Optionally read as a byte instead of a cell.
|
||||
// @return True on success, false if the stack is empty.
|
||||
// @error The stack is empty.
|
||||
public native any Pop(int block=0, bool asChar=false);
|
||||
|
||||
// Pops a string value from a stack.
|
||||
//
|
||||
// @param buffer Buffer to store string.
|
||||
// @param maxlength Maximum size of the buffer.
|
||||
// @oaram written Number of characters written to buffer, not including
|
||||
// the null terminator.
|
||||
// @error The stack is empty.
|
||||
public native void PopString(char[] buffer, int maxlength, int &written = 0);
|
||||
|
||||
// Pops an array of cells from a stack.
|
||||
//
|
||||
// @param buffer Buffer to store the array in.
|
||||
// @param size If not set, assumes the buffer size is equal to the
|
||||
// blocksize. Otherwise, the size passed is used.
|
||||
// @error The stack is empty.
|
||||
public native void PopArray(any[] buffer, int size=-1);
|
||||
|
||||
// Returns true if the stack is empty, false otherwise.
|
||||
property bool Empty {
|
||||
public native get();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a stack structure. A stack is a LIFO (last in, first out)
|
||||
* vector (array) of items. It has O(1) insertion and O(1) removal.
|
||||
@@ -53,7 +129,7 @@
|
||||
* new Array[X][32]
|
||||
* @return New stack Handle.
|
||||
*/
|
||||
native Handle:CreateStack(blocksize=1);
|
||||
native ArrayStack CreateStack(int blocksize=1);
|
||||
|
||||
/**
|
||||
* Pushes a value onto the end of the stack, adding a new index.
|
||||
@@ -63,24 +139,22 @@ native Handle:CreateStack(blocksize=1);
|
||||
*
|
||||
* @param stack Stack Handle.
|
||||
* @param value Value to push.
|
||||
* @noreturn
|
||||
* @error Invalid Handle or out of memory.
|
||||
*/
|
||||
native PushStackCell(Handle:stack, any:value);
|
||||
native void PushStackCell(Handle stack, any value);
|
||||
|
||||
/**
|
||||
* Pushes a string onto the end of a stack, truncating it if it is
|
||||
* Pushes a copy of a string onto the end of a stack, truncating it if it is
|
||||
* too big.
|
||||
*
|
||||
* @param stack Stack Handle.
|
||||
* @param value String to push.
|
||||
* @noreturn
|
||||
* @error Invalid Handle or out of memory.
|
||||
*/
|
||||
native PushStackString(Handle:stack, const String:value[]);
|
||||
native void PushStackString(Handle stack, const char[] value);
|
||||
|
||||
/**
|
||||
* Pushes an array of cells onto the end of a stack. The cells
|
||||
* Pushes a copy of an array of cells onto the end of a stack. The cells
|
||||
* are pushed as a block (i.e. the entire array takes up one stack slot),
|
||||
* rather than pushing each cell individually.
|
||||
*
|
||||
@@ -89,10 +163,9 @@ native PushStackString(Handle:stack, const String:value[]);
|
||||
* @param size If not set, the number of elements copied from the array
|
||||
* will be equal to the blocksize. If set higher than the
|
||||
* blocksize, the operation will be truncated.
|
||||
* @noreturn
|
||||
* @error Invalid Handle or out of memory.
|
||||
*/
|
||||
native PushStackArray(Handle:stack, const any:values[], size=-1);
|
||||
native void PushStackArray(Handle stack, const any[] values, int size=-1);
|
||||
|
||||
/**
|
||||
* Pops a cell value from a stack.
|
||||
@@ -105,7 +178,7 @@ native PushStackArray(Handle:stack, const any:values[], size=-1);
|
||||
* @return True on success, false if the stack is empty.
|
||||
* @error Invalid Handle.
|
||||
*/
|
||||
native bool:PopStackCell(Handle:stack, &any:value, block=0, bool:asChar=false);
|
||||
native bool PopStackCell(Handle stack, any &value, int block=0, bool asChar=false);
|
||||
|
||||
/**
|
||||
* Pops a string value from a stack.
|
||||
@@ -116,7 +189,7 @@ native bool:PopStackCell(Handle:stack, &any:value, block=0, bool:asChar=false);
|
||||
* @return True on success, false if the stack is empty.
|
||||
* @error Invalid Handle.
|
||||
*/
|
||||
native bool:PopStackString(Handle:stack, String:buffer[], maxlength, &written=0);
|
||||
native bool PopStackString(Handle stack, char[] buffer, int maxlength, int &written=0);
|
||||
|
||||
/**
|
||||
* Pops an array of cells from a stack.
|
||||
@@ -128,7 +201,7 @@ native bool:PopStackString(Handle:stack, String:buffer[], maxlength, &written=0)
|
||||
* @return True on success, false if the stack is empty.
|
||||
* @error Invalid Handle.
|
||||
*/
|
||||
native bool:PopStackArray(Handle:stack, any:buffer[], size=-1);
|
||||
native bool PopStackArray(Handle stack, any[] buffer, int size=-1);
|
||||
|
||||
/**
|
||||
* Checks if a stack is empty.
|
||||
@@ -137,7 +210,7 @@ native bool:PopStackArray(Handle:stack, any:buffer[], size=-1);
|
||||
* @return True if empty, false if not empty.
|
||||
* @error Invalid Handle.
|
||||
*/
|
||||
native bool:IsStackEmpty(Handle:stack);
|
||||
native bool IsStackEmpty(Handle stack);
|
||||
|
||||
/**
|
||||
* Pops a value off a stack, ignoring it completely.
|
||||
@@ -146,9 +219,8 @@ native bool:IsStackEmpty(Handle:stack);
|
||||
* @return True if something was popped, false otherwise.
|
||||
* @error Invalid Handle.
|
||||
*/
|
||||
stock PopStack(Handle:stack)
|
||||
stock bool PopStack(Handle stack)
|
||||
{
|
||||
new value;
|
||||
|
||||
return PopStackCell(stack, value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user