FIFOStack.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-2018 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::FIFOStack
26 
27 Description
28  A FIFO stack based on a singly-linked list.
29 
30  Operations are push(), pop(), top(), bottom() and empty().
31 
32 SourceFiles
33  FIFOStack.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef FIFOStack_H
38 #define FIFOStack_H
39 
40 #include "SLList.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 /*---------------------------------------------------------------------------*\
48  Class FIFOStack Declaration
49 \*---------------------------------------------------------------------------*/
50 
51 template<class T>
52 class FIFOStack
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->last();
73  }
74 
75  //- Return a copy of the bottom element
76  T bottom() const
77  {
78  return this->first();
79  }
80 
81 
82  // Edit
83 
84  //- Push an element onto the stack
85  void push(const T& a)
86  {
87  this->append(a);
88  }
89 
90  //- Pop the bottom 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 // ************************************************************************* //
A FIFO stack based on a singly-linked list.
Definition: FIFOStack.H:51
Template class for non-intrusive linked lists.
Definition: LList.H:51
T & first()
Return the first entry added.
Definition: LList.H:136
T top() const
Return a copy of the top element.
Definition: FIFOStack.H:69
T removeHead()
Remove and return head.
Definition: LList.H:175
T & last()
Return the last entry added.
Definition: LList.H:148
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
void append(const T &a)
Add at tail of list.
Definition: LList.H:169
void push(const T &a)
Push an element onto the stack.
Definition: FIFOStack.H:84
T pop()
Pop the bottom element off the stack.
Definition: FIFOStack.H:90
Non-intrusive singly-linked list.
T bottom() const
Return a copy of the bottom element.
Definition: FIFOStack.H:75
Namespace for OpenFOAM.