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 | 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::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  //- Construct null
62  FIFOStack()
63  {}
64 
65  //- Construct given initial T
66  FIFOStack(T a)
67  :
68  SLList<T>(a)
69  {}
70 
71  //- Construct from Istream
72  FIFOStack(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->last();
86  }
87 
88  //- Return a copy of the bottom element
89  T bottom() const
90  {
91  return this->first();
92  }
93 
94 
95  // Edit
96 
97  //- Push an element onto the stack
98  void push(const T& a)
99  {
100  this->append(a);
101  }
102 
103  //- Pop the bottom 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 FIFO stack based on a singly-linked list.
Definition: FIFOStack.H:51
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
T bottom() const
Return a copy of the bottom element.
Definition: FIFOStack.H:88
FIFOStack()
Construct null.
Definition: FIFOStack.H:61
T top() const
Return a copy of the top element.
Definition: FIFOStack.H:82
T removeHead()
Remove and return head.
Definition: LList.H:172
Non-intrusive singly-linked list.
Definition: SLList.H:47
T & last()
Return the last entry added.
Definition: LList.H:145
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
void append(const T &a)
Add at tail of list.
Definition: LList.H:166
void push(const T &a)
Push an element onto the stack.
Definition: FIFOStack.H:97
T pop()
Pop the bottom element off the stack.
Definition: FIFOStack.H:103
Namespace for OpenFOAM.