LibCDS
stack.h File Reference

The LIFO stack. More...

Go to the source code of this file.

Data Structures

struct  Stack
 The implementation for stack. More...
 

Typedefs

typedef struct _StackData StackData
 StackData is the data type for the container private information. More...
 

Functions

int32_t StackInit (Stack **ppObj)
 The constructor for Stack. More...
 
void StackDeinit (Stack **ppObj)
 The destructor for Stack. More...
 
int32_t StackPush (Stack *self, Item item)
 Insert an item to the top of the stack. More...
 
int32_t StackPop (Stack *self)
 Delete item from top of the stack. More...
 
int32_t StackTop (Stack *self, Item *pItem)
 Retrieve item from top of the stack. More...
 
int32_t StackSize (Stack *self)
 Return the number of stored items. More...
 
int32_t StackSetDestroy (Stack *self, void(*pFunc)(Item))
 Set the custom item resource clean method. More...
 

Detailed Description

The LIFO stack.

Definition in file stack.h.

Typedef Documentation

typedef struct _StackData StackData

StackData is the data type for the container private information.

Definition at line 11 of file stack.h.

Function Documentation

int32_t StackInit ( Stack **  ppObj)

The constructor for Stack.

Parameters
ppObjThe double pointer to the to be constructed stack
Return values
SUCC
ERR_NOMEMInsufficient memory for stack construction
void StackDeinit ( Stack **  ppObj)

The destructor for Stack.

If the custom resource clean method is set, it also runs the clean method for all the items.

Parameters
ppObjThe double pointer to the to be destructed stack
int32_t StackPush ( Stack self,
Item  item 
)

Insert an item to the top of the stack.

This function inserts an item to the top of the stack with the corresponding stack size extension.

Parameters
selfThe pointer to Stack structure
itemThe designated item
Return values
SUCC
ERR_NOINITUninitialized container
ERR_NOMEMInsufficient memory for stack extension
int32_t StackPop ( Stack self)

Delete item from top of the stack.

This function deletes item from the top of the stack. If the custom resource clean method is set, it also runs the clean method for the deleted item.

Parameters
selfThe pointer to Stack structure
Return values
SUCC
ERR_NOINITUninitialized container
ERR_IDXEmpty stack
int32_t StackTop ( Stack self,
Item *  pItem 
)

Retrieve item from top of the stack.

This function retrieves item from the top of the stack. If the stack is not empty, the item is returned by the second parameter. Otherwise, the error code is returned and the second parameter is updated with NULL.

Parameters
selfThe pointer to Stack structure
pItemThe pointer to the returned item
Return values
SUCC
ERR_NOINITUninitialized container
ERR_IDXEmpty stack
ERR_GETInvalid parameter to store returned item
int32_t StackSize ( Stack self)

Return the number of stored items.

Parameters
selfThe pointer to Stack structure
Returns
The number of items
Return values
ERR_NOINITUninitialized container
int32_t StackSetDestroy ( Stack self,
void(*)(Item)  pFunc 
)

Set the custom item resource clean method.

Parameters
selfThe pointer to Stack structure
pFuncThe function pointer to the custom method
Return values
SUCC
ERR_NOINITUninitialized container