|
|
| version 1.22, 2004/02/11 15:33:14 | version 1.24, 2005/08/09 08:14:50 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: stack class decl. | Parser: stack class decl. |
| Copyright (c) 2001-2004 ArtLebedev Group (http://www.artlebedev.com) | Copyright (c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com) |
| Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) | Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) |
| */ | */ |
| Line 20 public: | Line 20 public: |
| Stack(): ftop(0) {} | Stack(): ftop(0) {} |
| void push(T item) { | void push(T item) { |
| if(ftop<count()) // cell is already allocated? | if(ftop<this->count()) // cell is already allocated? |
| put(ftop, item); // use it | put(ftop, item); // use it |
| else | else |
| *this+=item; // append it | *this+=item; // append it |
| Line 28 public: | Line 28 public: |
| } | } |
| T pop() { | T pop() { |
| return get(--ftop); | return this->get(--ftop); |
| } | } |
| bool is_empty() { return ftop==0; } | bool is_empty() { return ftop==0; } |
| Line 36 public: | Line 36 public: |
| void set_top_index(size_t atop) { ftop=atop; } | void set_top_index(size_t atop) { ftop=atop; } |
| T top_value() { | T top_value() { |
| assert(!is_empty()); | assert(!is_empty()); |
| return get(ftop-1); | return this->get(ftop-1); |
| } | } |
| /// call this prior to collecting garbage [in unused part of stack there may be pointers(unused)] | /// call this prior to collecting garbage [in unused part of stack there may be pointers(unused)] |
| void wipe_unused() { | void wipe_unused() { |
| if(size_t above_top_size=fused-ftop) | if(size_t above_top_size=this->fused-ftop) |
| memset(&felements[ftop], 0, above_top_size*sizeof(T)); | memset(&this->felements[ftop], 0, above_top_size*sizeof(T)); |
| } | } |
| protected: | protected: |