File:  [parser3project] / parser3 / src / include / pa_stack.h
Revision 1.17.2.6: download - view: text, annotated - select for diffs - revision graph
Tue Mar 4 15:59:18 2003 UTC (23 years, 4 months ago) by paf
Diff to: branchpoint 1.17: preferred, unified
number of gcc compiler bugs fixed

/** @file
	Parser: stack class decl.

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

#ifndef PA_STACK_H
#define PA_STACK_H

static const char* IDENT_STACK_H="$Date: 2003/03/04 15:59:18 $";

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

/// simple stack based on Array
template<typename T> class Stack: public Array<T> {
public:

	Stack(): ftop(0) {}

	void push(T item) {
		if(ftop<count()) // cell is already allocated?
			put(ftop, item); // use it
		else
			*this+=item; // append it
		ftop++;
	}

	/// @test to think: freeing unused stack item right now, may no do that? 
	/// [delay that till next push?]
	T pop() {
		T result=get(--ftop);
		put(ftop, empty); 
		return result;
	}

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

private:

	// deepest used index
	int ftop;
	T empty;
};

#endif

E-mail: