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 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 LabelledItemI.H
40
41\*---------------------------------------------------------------------------*/
42
43#ifndef LabelledItem_H
44#define LabelledItem_H
45
46#include "label.H"
47
48// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49
50namespace Foam
51{
52
53// Forward Declarations
54template<class T> class LabelledItem;
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 {}
105
106 //- Construct from Istream
107 explicit LabelledItem(Istream& is)
108 {
109 is >> *this;
110 }
111
112
113 // Member Functions
114
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_;
125 }
126
127 //- Set the index
128 void setIndex(const label idx) noexcept
129 {
130 index_ = idx;
131 }
132
133
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
152
153 // IOstream Operators
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// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
165
166#include "LabelledItemI.H"
167
168// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
169
170#endif
171
172// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
A container with an integer index that can be attached to any item. The index may be useful for sorti...
Definition: LabelledItem.H:65
bool operator==(const LabelledItem< T > &rhs) const
Test for equality of components.
Definition: LabelledItem.H:136
LabelledItem(Istream &is)
Construct from Istream.
Definition: LabelledItem.H:106
bool operator!=(const LabelledItem< T > &rhs) const
Test for inequality of components.
Definition: LabelledItem.H:146
LabelledItem(const T &item)
Copy construct item, with index = -1.
Definition: LabelledItem.H:85
LabelledItem(T &&item)
Move construct item, with index = -1.
Definition: LabelledItem.H:92
LabelledItem()
Default construct item, with index = -1.
Definition: LabelledItem.H:78
void setIndex(const label idx) noexcept
Set the index.
Definition: LabelledItem.H:127
label & index() noexcept
Non-const access to the index.
Definition: LabelledItem.H:121
label index() const noexcept
Return the index.
Definition: LabelledItem.H:115
LabelledItem(const T &item, label idx)
Construct from components.
Definition: LabelledItem.H:99
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
const volScalarField & T
Namespace for OpenFOAM.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Istream & operator>>(Istream &, directionInfo &)
const direction noexcept
Definition: Scalar.H:223