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-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::FIFOStack
29
30Description
31 A FIFO stack based on a singly-linked list.
32
33 Stack operations are push(), pop(), top(), bottom().
34
35\*---------------------------------------------------------------------------*/
36
37#ifndef Foam_FIFOStack_H
38#define Foam_FIFOStack_H
39
40#include "SLList.H"
41
42// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43
44namespace Foam
45{
46
47/*---------------------------------------------------------------------------*\
48 Class FIFOStack Declaration
49\*---------------------------------------------------------------------------*/
50
51template<class T>
52class FIFOStack
53:
54 public SLList<T>
55{
56public:
57
58 // Constructors
59
60 //- Inherit constructors from SLList
61 using SLList<T>::SLList;
62
63
64 // Member Functions
65
66 //- Const reference to the top element
67 const T& top() const
68 {
69 return this->last();
70 }
71
72 //- Const reference to the bottom element
73 const 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& elem)
80 {
81 this->append(elem);
82 }
83
84 //- Move an element onto the back of the stack
85 void push(T&& elem)
86 {
87 this->append(std::move(elem));
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// ************************************************************************* //
Non-intrusive singly-linked list.
A FIFO stack based on a singly-linked list.
Definition: FIFOStack.H:54
void push(const T &elem)
Push an element onto the back of the stack.
Definition: FIFOStack.H:78
const T & bottom() const
Const reference to the bottom element.
Definition: FIFOStack.H:72
const T & top() const
Const reference to the top element.
Definition: FIFOStack.H:66
T pop()
Pop the bottom element off the stack.
Definition: FIFOStack.H:90
void push(T &&elem)
Move an element onto the back of the stack.
Definition: FIFOStack.H:84
Template class for non-intrusive linked lists.
Definition: LList.H:79
T removeHead()
Remove and return first entry.
Definition: LList.H:265
reference last()
The last entry in the list.
Definition: LList.H:220
void append(const T &elem)
Add copy at back of list.
Definition: LList.H:245
reference first()
The first entry in the list.
Definition: LList.H:208
const volScalarField & T
Namespace for OpenFOAM.
LList< SLListBase, T > SLList
Definition: SLListFwd.H:47