FIFOStack.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2017 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::FIFOStack
29 
30 Description
31  A FIFO stack based on a singly-linked list.
32 
33  Stack operations are push(), pop(), top(), bottom().
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 public:
57 
58  // Constructors
59 
60  //- Inherit constructors from SLList
61  using SLList<T>::SLList;
62 
63 
64  // Member Functions
65 
66  //- Return a copy of the top element
67  T top() const
68  {
69  return this->last();
70  }
71 
72  //- Return a copy of the bottom element
73  T bottom() const
74  {
75  return this->first();
76  }
77 
78  //- Push an element onto the back of the stack
79  void push(const T& element)
80  {
81  this->append(element);
82  }
83 
84  //- Move an element onto the back of the stack
85  void push(T&& element)
86  {
87  this->append(std::move(element));
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 // ************************************************************************* //
Foam::LList::append
void append(const T &item)
Add copy at tail of list.
Definition: LList.H:237
Foam::LList::first
reference first()
The first entry in the list.
Definition: LList.H:199
Foam::FIFOStack::push
void push(const T &element)
Push an element onto the back of the stack.
Definition: FIFOStack.H:78
Foam::LList
Template class for non-intrusive linked lists.
Definition: LList.H:54
Foam::FIFOStack::top
T top() const
Return a copy of the top element.
Definition: FIFOStack.H:66
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::FIFOStack::push
void push(T &&element)
Move an element onto the back of the stack.
Definition: FIFOStack.H:84
Foam::FIFOStack::pop
T pop()
Pop the bottom element off the stack.
Definition: FIFOStack.H:90
SLList.H
Non-intrusive singly-linked list.
Foam::FIFOStack::bottom
T bottom() const
Return a copy of the bottom element.
Definition: FIFOStack.H:72
Foam::LList::last
reference last()
The last entry in the list.
Definition: LList.H:211
Foam::FIFOStack
A FIFO stack based on a singly-linked list.
Definition: FIFOStack.H:51
Foam::LList::removeHead
T removeHead()
Remove and return head.
Definition: LList.H:250