Forward compatibility: flex
[foam-extend-3.2.git] / src / foam / containers / LinkedLists / user / LIFOStack.H
blob112967613d0256b5ee0de5ce8ddb12c5a8fe6906
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation, either version 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 Class
25     Foam::LIFOStack
27 Description
28     A LIFO stack based on a singly-linked list.
29     Operations are push(), pop(), top(), bottom() and empty().
31 SourceFiles
32     LIFOStack.C
34 \*---------------------------------------------------------------------------*/
36 #ifndef LIFOStack_H
37 #define LIFOStack_H
39 #include "SLList.H"
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 namespace Foam
46 /*---------------------------------------------------------------------------*\
47                            Class LIFOStack Declaration
48 \*---------------------------------------------------------------------------*/
50 template<class T>
51 class LIFOStack
53     public SLList<T>
56 public:
58     // Constructors
60         //- Construct null
61         LIFOStack()
62         {}
64         //- Construct given initial T
65         LIFOStack(T a)
66         :
67             SLList<T>(a)
68         {}
70         //- Construct from Istream
71         LIFOStack(Istream& is)
72         :
73             SLList<T>(is)
74         {}
77     // Member Functions
79         // Access
81             //- Return a copy of the top element
82             T top() const
83             {
84                 return this->first();
85             }
87             //- Return a copy of the bottom element
88             T bottom() const
89             {
90                 return this->last();
91             }
94         // Edit
96             //- Push an element onto the stack
97             void push(const T& a)
98             {
99                 this->insert(a);
100             }
102             //- Pop the top element off the stack
103             T pop()
104             {
105                 return this->removeHead();
106             }
110 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
112 } // End namespace Foam
114 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
116 #endif
118 // ************************************************************************* //