Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / OpenFOAM / containers / LinkedLists / user / LIFOStack.H
blob082c984c033e0d759d6e675ecd45b053a46170d6
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-2010 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by
13     the Free Software Foundation, either version 3 of the License, or
14     (at your option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM.  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.
30     Operations are push(), pop(), top(), bottom() and empty().
32 SourceFiles
33     LIFOStack.C
35 \*---------------------------------------------------------------------------*/
37 #ifndef LIFOStack_H
38 #define LIFOStack_H
40 #include "SLList.H"
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 namespace Foam
47 /*---------------------------------------------------------------------------*\
48                            Class LIFOStack Declaration
49 \*---------------------------------------------------------------------------*/
51 template<class T>
52 class LIFOStack
54     public SLList<T>
57 public:
59     // Constructors
61         //- Construct null
62         LIFOStack()
63         {}
65         //- Construct given initial T
66         LIFOStack(T a)
67         :
68             SLList<T>(a)
69         {}
71         //- Construct from Istream
72         LIFOStack(Istream& is)
73         :
74             SLList<T>(is)
75         {}
78     // Member Functions
80         // Access
82             //- Return a copy of the top element
83             T top() const
84             {
85                 return this->first();
86             }
88             //- Return a copy of the bottom element
89             T bottom() const
90             {
91                 return this->last();
92             }
95         // Edit
97             //- Push an element onto the stack
98             void push(const T& a)
99             {
100                 this->insert(a);
101             }
103             //- Pop the top element off the stack
104             T pop()
105             {
106                 return this->removeHead();
107             }
111 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
113 } // End namespace Foam
115 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
117 #endif
119 // ************************************************************************* //