LIFOStack.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2020 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  //- Inherit constructors from SLList
62  using SLList<T>::SLList;
63 
64 
65  // Member Functions
66 
67  // Access
68 
69  //- Return a copy of the top element
70  T top() const
71  {
72  return this->first();
73  }
74 
75  //- Return a copy of the bottom element
76  T bottom() const
77  {
78  return this->last();
79  }
80 
81 
82  // Edit
83 
84  //- Push an element onto the stack
85  void push(const T& a)
86  {
87  this->insert(a);
88  }
89 
90  //- Pop the top element off the stack
91  T pop()
92  {
93  return this->removeHead();
94  }
95 };
96 
97 
98 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
99 
100 } // End namespace Foam
101 
102 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
103 
104 #endif
105 
106 // ************************************************************************* //
Non-intrusive singly-linked list.
A LIFO stack based on a singly-linked list.
Definition: LIFOStack.H:54
T top() const
Return a copy of the top element.
Definition: LIFOStack.H:69
T bottom() const
Return a copy of the bottom element.
Definition: LIFOStack.H:75
void push(const T &a)
Push an element onto the stack.
Definition: LIFOStack.H:84
T pop()
Pop the top element off the stack.
Definition: LIFOStack.H:90
Template class for non-intrusive linked lists.
Definition: LList.H:76
void insert(const T &a)
Add at head of list.
Definition: LList.H:166
T & first()
Return the first entry added.
Definition: LList.H:139
T & last()
Return the last entry added.
Definition: LList.H:151
T removeHead()
Remove and return head.
Definition: LList.H:178
Namespace for OpenFOAM.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)