.gitignore: ignore object files
[bcusdk.git] / common / stack.h
blob6f4a6b8e61259f91837fa817f8bfa748f91f4330
1 /*
2 EIBD eib bus access and management daemon
3 Copyright (C) 2005-2008 Martin Koegler <mkoegler@auto.tuwien.ac.at>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #ifndef STACK_H
21 #define STACK_H
23 #include "array.h"
25 /** implement a generic LIFO stack*/
26 template < class T > class Stack
28 protected:
29 /** elements in the stack*/
30 Array < T > data;
32 public:
34 /** initialize stack */
35 Stack ()
39 /** copy constructer */
40 Stack (const Stack < T > &c)
42 data = c.data;
45 /** destructor */
46 virtual ~ Stack ()
50 /** assignment operator */
51 const Stack < T > &operator = (const Stack < T > &c)
53 data = c.data;
54 return c;
57 /** adds a element to the queue end */
58 void push (const T & el)
60 data.resize (data () + 1);
61 data[data () - 1] = el;
64 /** remove the element from the queue head and returns it */
65 T pop ()
67 T a = data[data () - 1];
68 data.resize (data () - 1);
69 return a;
72 /** returns the element from the queue head */
73 const T & top () const
75 return data[data () - 1];
78 /** return true, if the queue is empty */
79 int isempty () const
81 return data () == 0;
86 #endif