FreeFOAM The Cross-Platform CFD Toolkit
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 | Copyright (C) 1991-2010 OpenCFD Ltd.
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::objectHit
26 
27 Description
28  This class describes a combination of target object index and success flag.
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #ifndef objectHit_H
33 #define objectHit_H
34 
35 #include <OpenFOAM/bool.H>
36 #include <OpenFOAM/label.H>
37 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
40 namespace Foam
41 {
42 
43 // Forward declaration of friend functions and operators
44 
45 class objectHit;
46 inline bool operator==(const objectHit& a, const objectHit& b);
47 inline bool operator!=(const objectHit& a, const objectHit& b);
48 inline Ostream& operator<<(Ostream& os, const objectHit& b);
49 
50 
51 /*---------------------------------------------------------------------------*\
52  Class objectHit Declaration
53 \*---------------------------------------------------------------------------*/
54 
55 class objectHit
56 {
57  // Private data
58 
59  //- Hit success
60  bool hit_;
61 
62  //- Object of hit
63  label hitObject_;
64 
65 
66 public:
67 
68  // Constructors
69 
70  //- Construct null
72  :
73  hit_(false),
74  hitObject_(-1)
75  {}
76 
77  //- Construct from components
78  objectHit(const bool success, const label& obj)
79  :
80  hit_(success),
81  hitObject_(obj)
82  {}
83 
84  //- Construct from Istream
86  :
87  hit_(readBool(is)),
88  hitObject_(readLabel(is))
89  {}
90 
91 
92  // Member Functions
93 
94  //- Is there a hit
95  bool hit() const
96  {
97  return hit_;
98  }
99 
100  //- Return hit object
101  label hitObject() const
102  {
103  return hitObject_;
104  }
105 
106 
107  // Friend Operators
108 
109  friend bool operator==(const objectHit& a, const objectHit& b)
110  {
111  return ((a.hit_ == b.hit_) && (a.hitObject_ == b.hitObject_));
112  }
113 
114  friend bool operator!=(const objectHit& a, const objectHit& b)
115  {
116  return (!(a == b));
117  }
118 
119 
120  // Ostream operator
121 
122  friend Ostream& operator<<(Ostream& os, const objectHit& b)
123  {
124  return os << b.hit() << token::SPACE << b.hitObject();
125  }
126 };
127 
128 
129 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
130 
131 } // End namespace Foam
132 
133 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
134 
135 #endif
136 
137 // ************************ vim: set sw=4 sts=4 et: ************************ //