objectHit.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) 2017-2020 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::objectHit
29
30Description
31 This class describes a combination of target object index and success flag.
32 Behaves somewhat like std::optional
33
34\*---------------------------------------------------------------------------*/
35
36#ifndef objectHit_H
37#define objectHit_H
38
39#include "bool.H"
40#include "label.H"
41
42// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43
44namespace Foam
45{
46
47/*---------------------------------------------------------------------------*\
48 Class objectHit Declaration
49\*---------------------------------------------------------------------------*/
51class objectHit
52{
53 // Private Data
54
55 //- Hit success
56 bool hit_;
57
58 //- The hit object index
59 label index_;
60
61
62public:
63
64 // Constructors
65
66 //- Default construct. Nothing hit and object = -1
67 constexpr objectHit() noexcept
68 :
69 hit_(false),
70 index_(-1)
71 {}
72
73 //- Construct from components
74 objectHit(const bool success, const label index) noexcept
75 :
76 hit_(success),
77 index_(index)
78 {}
79
80 //- Construct from Istream
81 explicit objectHit(Istream& is)
82 :
83 hit_(readBool(is)),
84 index_(readLabel(is))
85 {}
86
87
88 // Member Functions
89
90 // Access
91
92 //- Is there a hit?
93 bool hit() const noexcept
94 {
95 return hit_;
96 }
97
98 //- Return the hit object index
99 label index() const noexcept
100 {
101 return index_;
102 }
103
104 //- Identical to index()
105 label hitObject() const noexcept
106 {
107 return index_;
108 }
109
110
111 // Edit
112
113 //- Reset to default construct state
114 void reset() noexcept
115 {
116 hit_ = false;
117 index_ = -1;
118 }
119
120 //- Set the hit status \em on
121 void setHit() noexcept
122 {
123 hit_ = true;
124 }
125
126 //- Set the hit status \em off
127 void setMiss() noexcept
128 {
129 hit_ = false;
130 }
131
132
133 // Ostream Operator
135 inline friend Ostream& operator<<(Ostream& os, const objectHit& obj)
136 {
137 return os << obj.hit() << token::SPACE << obj.hitObject();
138 }
139};
140
141
142// Global Operators
144inline bool operator==(const objectHit& a, const objectHit& b)
145{
146 return a.hit() == b.hit() && a.hitObject() == b.hitObject();
147}
148
150inline bool operator!=(const objectHit& a, const objectHit& b)
151{
152 return !(a == b);
153}
154
155
156// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
157
158} // End namespace Foam
159
160// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
161
162#endif
163
164// ************************************************************************* //
bool success
System bool.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
This class describes a combination of target object index and success flag. Behaves somewhat like std...
Definition: objectHit.H:51
void setHit() noexcept
Set the hit status on.
Definition: objectHit.H:120
void reset() noexcept
Reset to default construct state.
Definition: objectHit.H:113
label index() const noexcept
Return the hit object index.
Definition: objectHit.H:98
label hitObject() const noexcept
Identical to index()
Definition: objectHit.H:104
void setMiss() noexcept
Set the hit status off.
Definition: objectHit.H:126
bool hit() const noexcept
Is there a hit?
Definition: objectHit.H:92
objectHit(const bool success, const label index) noexcept
Construct from components.
Definition: objectHit.H:73
objectHit(Istream &is)
Construct from Istream.
Definition: objectHit.H:80
friend Ostream & operator<<(Ostream &os, const objectHit &obj)
Definition: objectHit.H:134
constexpr objectHit() noexcept
Default construct. Nothing hit and object = -1.
Definition: objectHit.H:66
@ SPACE
Space [isspace].
Definition: token.H:125
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
bool operator!=(const eddy &a, const eddy &b)
Definition: eddy.H:239
label readLabel(const char *buf)
Parse entire buffer as a label, skipping leading/trailing whitespace.
Definition: label.H:66
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
const direction noexcept
Definition: Scalar.H:223
bool readBool(Istream &is)
Read bool from stream using Foam::Switch(Istream&)
Definition: bool.C:69
volScalarField & b
Definition: createFields.H:27