Fix include style
[bcusdk.git] / common / stack.h
blob2fa2973ff1a877089a5284b3d35832978a40eaa3
1 /*
2 EIBD eib bus access and management daemon
3 Copyright (C) 2005-2010 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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