LIFOStack.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 Class
25  Foam::LIFOStack
26 
27 Description
28  A LIFO stack based on a singly-linked list.
29 
30  Operations are push(), pop(), top(), bottom() and empty().
31 
32 SourceFiles
33  LIFOStack.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef LIFOStack_H
38 #define LIFOStack_H
39 
40 #include "SLList.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 /*---------------------------------------------------------------------------*\
48  Class LIFOStack Declaration
49 \*---------------------------------------------------------------------------*/
50 
51 template<class T>
52 class LIFOStack
53 :
54  public SLList<T>
55 {
56 
57 public:
58 
59  // Constructors
60 
61  //- Construct null
62  LIFOStack()
63  {}
64 
65  //- Construct given initial T
66  LIFOStack(T a)
67  :
68  SLList<T>(a)
69  {}
70 
71  //- Construct from Istream
72  LIFOStack(Istream& is)
73  :
74  SLList<T>(is)
75  {}
76 
77 
78  // Member Functions
79 
80  // Access
81 
82  //- Return a copy of the top element
83  T top() const
84  {
85  return this->first();
86  }
87 
88  //- Return a copy of the bottom element
89  T bottom() const
90  {
91  return this->last();
92  }
93 
94 
95  // Edit
96 
97  //- Push an element onto the stack
98  void push(const T& a)
99  {
100  this->insert(a);
101  }
102 
103  //- Pop the top element off the stack
104  T pop()
105  {
106  return this->removeHead();
107  }
108 };
109 
110 
111 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
112 
113 } // End namespace Foam
114 
115 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
116 
117 #endif
118 
119 // ************************************************************************* //
A LIFO stack based on a singly-linked list.
Definition: LIFOStack.H:51
LIFOStack()
Construct null.
Definition: LIFOStack.H:61
T & first()
Return the first entry added.
Definition: LList.H:133
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
void push(const T &a)
Push an element onto the stack.
Definition: LIFOStack.H:97
T removeHead()
Remove and return head.
Definition: LList.H:172
T pop()
Pop the top element off the stack.
Definition: LIFOStack.H:103
Non-intrusive singly-linked list.
Definition: SLList.H:47
void insert(const T &a)
Add at head of list.
Definition: LList.H:160
T & last()
Return the last entry added.
Definition: LList.H:145
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
T top() const
Return a copy of the top element.
Definition: LIFOStack.H:82
T bottom() const
Return a copy of the bottom element.
Definition: LIFOStack.H:88
Namespace for OpenFOAM.