Loading...
Searching...
No Matches
LabelledItem.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 OpenFOAM Foundation
9 Copyright (C) 2021-2022 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::LabelledItem
29
30Description
31 A container with an integer index that can be attached to any item.
32 The index may be useful for sorting or storing additional information.
33
34SeeAlso
35 Foam::objectHit
36 Foam::PointIndexHit
37
38SourceFiles
39
40\*---------------------------------------------------------------------------*/
41
42#ifndef Foam_LabelledItem_H
43#define Foam_LabelledItem_H
44
45#include "label.H"
46#include "IOstreams.H"
47
48// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49
50namespace Foam
52
53// Forward Declarations
54template<class T> class LabelledItem;
55template<class T> Istream& operator>>(Istream&, LabelledItem<T>&);
56template<class T> Ostream& operator<<(Ostream&, const LabelledItem<T>&);
57
58/*---------------------------------------------------------------------------*\
59 Class LabelledItem Declaration
60\*---------------------------------------------------------------------------*/
61
62template<class T>
63class LabelledItem
64:
65 public T
66{
67 // Private Data
68
69 //- The object index
70 label index_;
71
72
73public:
74
75
76 // Constructors
77
78 //- Default construct item, with index = -1
80 :
81 T(),
82 index_(-1)
83 {}
84
85 //- Copy construct item, with index = -1
86 explicit LabelledItem(const T& item)
87 :
88 T(item),
89 index_(-1)
90 {}
91
92 //- Move construct item, with index = -1
93 explicit LabelledItem(T&& item)
94 :
95 T(std::move(item)),
96 index_(-1)
97 {}
98
99 //- Construct from components
100 LabelledItem(const T& item, label idx)
101 :
102 T(item),
103 index_(idx)
104 {}
106 //- Construct from Istream
107 explicit LabelledItem(Istream& is)
108 {
109 is >> *this;
110 }
111
112
113 // Member Functions
115 //- Return the index
116 label index() const noexcept
117 {
118 return index_;
119 }
120
121 //- Non-const access to the index
122 label& index() noexcept
123 {
124 return index_;
126
127 //- Set the index
128 void setIndex(const label idx) noexcept
129 {
130 index_ = idx;
131 }
132
134 // Member Operators
135
136 //- Test for equality of components
137 bool operator==(const LabelledItem<T>& rhs) const
138 {
139 return
140 (
141 index_ == rhs.index_
142 && static_cast<const T&>(*this) == static_cast<const T&>(rhs)
143 );
144 }
145
146 //- Test for inequality of components
147 bool operator!=(const LabelledItem<T>& rhs) const
148 {
149 return !(*this == rhs);
150 }
151
153 // IOstream Operators
154
155 friend Istream& operator>> <T>(Istream&, LabelledItem<T>&);
156 friend Ostream& operator<< <T>(Ostream&, const LabelledItem<T>&);
157};
158
159
160// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
161
162} // End namespace Foam
163
164// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
165
166template<class T>
167inline Foam::Istream& Foam::operator>>
168(
169 Istream& is,
170 LabelledItem<T>& item
171)
173 is.readBegin("LabelledItem");
174 is >> static_cast<T&>(item) >> item.index();
175 is.readEnd("LabelledItem");
176
177 is.check(FUNCTION_NAME);
178 return is;
179}
180
181
182template<class T>
183inline Foam::Ostream& Foam::operator<<
184(
185 Ostream& os,
186 const LabelledItem<T>& item
187)
188{
189 // Output like Tuple2
191 << static_cast<const T&>(item) << token::SPACE
192 << item.index()
194
195 return os;
196}
197
198
199// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
200
201#endif
202
203// ************************************************************************* //
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
A container with an integer index that can be attached to any item. The index may be useful for sorti...
bool operator==(const LabelledItem< T > &rhs) const
Test for equality of components.
LabelledItem(Istream &is)
Construct from Istream.
bool operator!=(const LabelledItem< T > &rhs) const
Test for inequality of components.
LabelledItem(const T &item)
Copy construct item, with index = -1.
LabelledItem(T &&item)
Move construct item, with index = -1.
LabelledItem()
Default construct item, with index = -1.
void setIndex(const label idx) noexcept
Set the index.
label & index() noexcept
Non-const access to the index.
label index() const noexcept
Return the index.
LabelledItem(const T &item, label idx)
Construct from components.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
@ BEGIN_LIST
Begin list [isseparator].
Definition token.H:174
@ END_LIST
End list [isseparator].
Definition token.H:175
@ SPACE
Space [isspace].
Definition token.H:144
const volScalarField & T
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
Namespace for OpenFOAM.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
Istream & operator>>(Istream &, directionInfo &)
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
const direction noexcept
Definition scalarImpl.H:265
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)