<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><meta name="robots" content="noindex"> <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>stack.h Source File</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body bgcolor="#ffffff"> <!-- Generated by Doxygen 1.2.5 on Mon Oct 14 14:16:38 2002 --> <center> <a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="pages.html">Related Pages</a> </center> <hr><h1>stack.h</h1><div class="fragment"><pre>00001 <font class="comment">//</font> 00002 <font class="comment">// stack.h</font> 00003 <font class="comment">//</font> 00004 <font class="comment">// Copyright (C) 1996 Limit Point Systems, Inc.</font> 00005 <font class="comment">//</font> 00006 <font class="comment">// Author: Curtis Janssen <cljanss@limitpt.com></font> 00007 <font class="comment">// Maintainer: LPS</font> 00008 <font class="comment">//</font> 00009 <font class="comment">// This file is part of the SC Toolkit.</font> 00010 <font class="comment">//</font> 00011 <font class="comment">// The SC Toolkit is free software; you can redistribute it and/or modify</font> 00012 <font class="comment">// it under the terms of the GNU Library General Public License as published by</font> 00013 <font class="comment">// the Free Software Foundation; either version 2, or (at your option)</font> 00014 <font class="comment">// any later version.</font> 00015 <font class="comment">//</font> 00016 <font class="comment">// The SC Toolkit is distributed in the hope that it will be useful,</font> 00017 <font class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</font> 00018 <font class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</font> 00019 <font class="comment">// GNU Library General Public License for more details.</font> 00020 <font class="comment">//</font> 00021 <font class="comment">// You should have received a copy of the GNU Library General Public License</font> 00022 <font class="comment">// along with the SC Toolkit; see the file COPYING.LIB. If not, write to</font> 00023 <font class="comment">// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.</font> 00024 <font class="comment">//</font> 00025 <font class="comment">// The U.S. Government is granted a limited license as per AL 91-7.</font> 00026 <font class="comment">//</font> 00027 00028 <font class="preprocessor">#ifndef _util_render_stack_h</font> 00029 <font class="preprocessor"></font><font class="preprocessor">#define _util_render_stack_h</font> 00030 <font class="preprocessor"></font> 00031 <font class="preprocessor">#include <iostream></font> 00032 00033 <font class="keyword">namespace </font>sc { 00034 00035 <font class="preprocessor">#define STACK_MAX_STACK_SIZE 20</font> 00036 <font class="preprocessor"></font>template <class T> 00037 <font class="keyword">class </font>Stack { 00038 <font class="keyword">private</font>: 00039 T objects[STACK_MAX_STACK_SIZE]; 00040 <font class="keywordtype">int</font> nobjects; 00041 <font class="keyword">public</font>: 00042 Stack(): nobjects(0) {} 00043 <font class="keywordtype">void</font> push(<font class="keyword">const</font> T&a)<font class="keyword"> </font>{ 00044 <font class="keywordflow">if</font> (nobjects >= STACK_MAX_STACK_SIZE) { 00045 ExEnv::errn() << <font class="stringliteral">"Stack: overflow"</font> << std::endl; 00046 abort(); 00047 } 00048 objects[nobjects++] = a; 00049 } 00050 T pop()<font class="keyword"> </font>{ 00051 <font class="keywordflow">if</font> (!nobjects) { 00052 ExEnv::errn() << <font class="stringliteral">"Stack: underflow"</font> << std::endl; 00053 abort(); 00054 } 00055 nobjects -= 1; 00056 <font class="keywordflow">return</font> objects[nobjects]; 00057 } 00058 T top()<font class="keyword"> const </font>{ 00059 <font class="keywordflow">if</font> (!nobjects) { 00060 ExEnv::errn() << <font class="stringliteral">"Stack: underflow"</font> << std::endl; 00061 abort(); 00062 } 00063 <font class="keywordflow">return</font> objects[nobjects - 1]; 00064 } 00065 <font class="keywordtype">int</font> n()<font class="keyword"> const </font>{ <font class="keywordflow">return</font> nobjects; } 00066 T operator[](<font class="keywordtype">int</font> i)<font class="keyword"> </font>{ <font class="keywordflow">return</font> objects[i]; } 00067 <font class="keywordtype">void</font> print(std::ostream& os = ExEnv::out0()) { 00068 os << <font class="stringliteral">"Stack (depth = "</font> << nobjects << <font class="stringliteral">"):"</font> << std::endl; 00069 <font class="keywordflow">for</font> (<font class="keywordtype">int</font> i=0; i<nobjects; i++) { 00070 os << <font class="stringliteral">" object "</font> << i << <font class="stringliteral">":"</font> << std::endl; 00071 objects[i]->print(os); 00072 } 00073 } 00074 }; 00075 00076 } 00077 00078 <font class="preprocessor">#endif</font> 00079 <font class="preprocessor"></font> 00080 <font class="comment">// Local Variables:</font> 00081 <font class="comment">// mode: c++</font> 00082 <font class="comment">// c-file-style: "CLJ"</font> 00083 <font class="comment">// End:</font> </div></pre><hr> <address> <small> Generated at Mon Oct 14 14:16:38 2002 for <a href="http://aros.ca.sandia.gov/~cljanss/mpqc">MPQC</a> 2.1.2 using the documentation package <a href="http://www.stack.nl/~dimitri/doxygen/index.html">Doxygen</a> 1.2.5. </small> </address> </body> </html>