File:  [parser3project] / parser3 / src / include / pa_stack.h
Revision 1.14: download - view: text, annotated - select for diffs - revision graph
Mon Mar 18 15:29:46 2002 UTC (24 years, 3 months ago) by paf
Branches: MAIN
CVS tags: release_3_0_0004, release_3_0_0003, release_3_0_0002, release_1_0_0001, HEAD
introducing ^try

/** @file
	Parser: stack class decl.

	Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com)
	Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)

	$Id: pa_stack.h,v 1.14 2002/03/18 15:29:46 paf Exp $
*/

#ifndef PA_STACK_H
#define PA_STACK_H

#include "pa_config_includes.h"
#include "pa_array.h"

/// simple stack based on Array
class Stack : public Array {
public:

	Stack(Pool& apool) : Array(apool), ftop(0) {
	}

	void push(Item *item) {
		if(ftop<size()) // cell is already allocated?
			put(ftop, item); // use it
		else
			*this+=item; // append it
		ftop++;
	}
	Item *pop() {
		return get(--ftop);
	}

	int top_index() { return ftop-1; }
	void top_index(int top_index) { ftop=top_index+1; }
	Item *top_value() { return get(top_index()); }

private:

	// deepest used index
	int ftop;

};

#endif

E-mail: