BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / OpenFOAM / meshes / primitiveShapes / objectHit / PointIndexHit.H
blobeafc21d87158ab4a1dc807165121c865648283d5
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.
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.
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.
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/>.
24 Class
25     Foam::PointIndexHit
27 Description
28     This class describes the interaction of (usually) a face and a point.
29     It carries the info of a successful hit and (if successful),
30     returns the interaction point.
32     like pointHit but carries face (or cell, edge etc.) index
34 SourceFiles
36 \*---------------------------------------------------------------------------*/
38 #ifndef PointIndexHit_H
39 #define PointIndexHit_H
41 #include "bool.H"
42 #include "point.H"
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 namespace Foam
49 /*---------------------------------------------------------------------------*\
50                            Class PointIndexHit Declaration
51 \*---------------------------------------------------------------------------*/
53 template<class Point>
54 class PointIndexHit
56     // Private data
58         //- Hit success
59         bool hit_;
61         //- Point of hit; invalid for misses
62         Point hitPoint_;
64         //- label of face hit
65         label index_;
68 public:
70     // Constructors
72         //- Construct from components
73         PointIndexHit(const bool success, const Point& p, const label index)
74         :
75             hit_(success),
76             hitPoint_(p),
77             index_(index)
78         {}
80         //- Construct from point. Hit and distance set later
81         PointIndexHit(const Point& p)
82         :
83             hit_(false),
84             hitPoint_(p),
85             index_(-1)
86         {}
88         //- Construct null
89         PointIndexHit()
90         :
91             hit_(false),
92             hitPoint_(vector::zero),
93             index_(-1)
94         {}
96         //- Construct from Istream
97         PointIndexHit(Istream& is)
98         {
99             is >> *this;
100         }
103     // Member Functions
105         //- Is there a hit
106         bool hit() const
107         {
108             return hit_;
109         }
111         //- Return index
112         label index() const
113         {
114             return index_;
115         }
117         //- Return hit point
118         const Point& hitPoint() const
119         {
120             if (!hit_)
121             {
122                 FatalErrorIn("PointIndexHit::hitPoint() const")
123                     << "requested a hit point for a miss"
124                     << abort(FatalError);
125             }
127             return hitPoint_;
128         }
130         //- Return miss point
131         const Point& missPoint() const
132         {
133             if (hit_)
134             {
135                 FatalErrorIn("PointIndexHit::missPoint() const")
136                     << "requested a miss point for a hit"
137                     << abort(FatalError);
138             }
140             return hitPoint_;
141         }
143         //- Return point with no checking
144         const Point& rawPoint() const
145         {
146             return hitPoint_;
147         }
149         Point& rawPoint()
150         {
151             return hitPoint_;
152         }
154         void setHit()
155         {
156             hit_ = true;
157         }
159         void setMiss()
160         {
161             hit_ = false;
162         }
164         void setPoint(const Point& p)
165         {
166             hitPoint_ = p;
167         }
169         void setIndex(const label index)
170         {
171             index_ = index;
172         }
174         bool operator==(const PointIndexHit& rhs) const
175         {
176             return
177                 hit_ == rhs.hit()
178              && hitPoint_ == rhs.rawPoint()
179              && index_ == rhs.index();
180         }
182         bool operator!=(const PointIndexHit& rhs) const
183         {
184             return !operator==(rhs);
185         }
187         void write(Ostream& os)
188         {
189             if (hit())
190             {
191                 os << "hit:" << hitPoint() << " index:" << index();
192             }
193             else
194             {
195                 os << "miss:" << missPoint() << " index:" << index();
196             }
197         }
199         friend Ostream& operator<< (Ostream& os, const PointIndexHit& pHit)
200         {
201             if (os.format() == IOstream::ASCII)
202             {
203                 os  << pHit.hit_ << token::SPACE << pHit.hitPoint_
204                     << token::SPACE << pHit.index_;
205             }
206             else
207             {
208                 os.write
209                 (
210                     reinterpret_cast<const char*>(&pHit),
211                     sizeof(PointIndexHit)
212                 );
213             }
215             // Check state of Ostream
216             os.check("Ostream& operator<<(Ostream&, const PointIndexHit&)");
218             return os;
219         }
221         friend Istream& operator>>(Istream& is, PointIndexHit& pHit)
222         {
223             if (is.format() == IOstream::ASCII)
224             {
225                 return is >> pHit.hit_ >> pHit.hitPoint_ >> pHit.index_;
226             }
227             else
228             {
229                 is.read
230                 (
231                     reinterpret_cast<char*>(&pHit),
232                     sizeof(PointIndexHit)
233                 );
234             }
236             // Check state of Istream
237             is.check("Istream& operator>>(Istream&, PointIndexHit&)");
239             return is;
240         }
245 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
247 } // End namespace Foam
249 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
251 #endif
253 // ************************************************************************* //