00001 /* 00002 ** (c) 1996-2000 The Regents of the University of California (through 00003 ** E.O. Lawrence Berkeley National Laboratory), subject to approval by 00004 ** the U.S. Department of Energy. Your use of this software is under 00005 ** license -- the license agreement is attached and included in the 00006 ** directory as license.txt or you may contact Berkeley Lab's Technology 00007 ** Transfer Department at TTD@lbl.gov. NOTICE OF U.S. GOVERNMENT RIGHTS. 00008 ** The Software was developed under funding from the U.S. Government 00009 ** which consequently retains certain rights as follows: the 00010 ** U.S. Government has been granted for itself and others acting on its 00011 ** behalf a paid-up, nonexclusive, irrevocable, worldwide license in the 00012 ** Software to reproduce, prepare derivative works, and perform publicly 00013 ** and display publicly. Beginning five (5) years after the date 00014 ** permission to assert copyright is obtained from the U.S. Department of 00015 ** Energy, and subject to any subsequent five (5) year renewals, the 00016 ** U.S. Government is granted for itself and others acting on its behalf 00017 ** a paid-up, nonexclusive, irrevocable, worldwide license in the 00018 ** Software to reproduce, prepare derivative works, distribute copies to 00019 ** the public, perform publicly and display publicly, and to permit 00020 ** others to do so. 00021 */ 00022 00023 #ifndef BL_ORIENTATION_H 00024 #define BL_ORIENTATION_H 00025 // 00026 // $Id: Orientation.H,v 1.15 2001/07/31 22:43:19 lijewski Exp $ 00027 // 00028 #include <iosfwd> 00029 00030 #include <BLassert.H> 00031 #include <SPACE.H> 00032 00033 class OrientationIter; 00034 00035 // 00036 // : 00038 00048 class Orientation 00049 { 00050 public: 00051 00052 friend class OrientationIter; 00053 // 00055 // 00056 enum Side { low = 0, high = 1 }; 00057 // 00059 // 00060 Orientation (); 00061 // 00063 // 00064 Orientation (int dir, 00065 Side side); 00066 // 00068 // 00069 Orientation (const Orientation& rhs); 00070 // 00072 // 00073 Orientation& operator= (const Orientation& rhs); 00074 // 00076 // 00077 bool operator== (const Orientation& o) const; 00078 // 00080 // 00081 bool operator!= (const Orientation& o) const; 00082 // 00084 // 00085 bool operator< (const Orientation& o) const; 00086 // 00088 // 00089 bool operator<= (const Orientation& o) const; 00090 // 00092 // 00093 bool operator> (const Orientation& o) const; 00094 // 00096 // 00097 bool operator>= (const Orientation& o) const; 00098 00103 operator int () const; 00104 // 00106 // 00107 Orientation flip () const; 00108 // 00110 // 00111 int coordDir () const; 00112 // 00114 // 00115 Side faceDir () const; 00116 // 00118 // 00119 bool isLow () const; 00120 // 00122 // 00123 bool isHigh () const; 00124 // 00126 // 00127 friend std::istream& operator>> (std::istream& os, Orientation& o); 00128 00129 protected: 00130 // 00131 // Used internally. 00132 // 00133 Orientation (int val); 00134 00135 private: 00136 00137 int val; 00138 }; 00139 00140 // 00142 // 00143 std::ostream& operator<< (std::ostream& os, const Orientation& o); 00144 00145 // 00146 // 00148 // 00149 00150 class OrientationIter 00151 { 00152 00153 public: 00154 // 00156 // 00157 OrientationIter (); 00158 // 00160 // 00161 OrientationIter (const Orientation& _face); 00162 // 00164 // 00165 OrientationIter (const OrientationIter& it); 00166 // 00168 // 00169 OrientationIter& operator= (const OrientationIter& it); 00170 // 00172 // 00173 void rewind (); 00174 // 00176 // 00177 Orientation operator() () const; 00178 // 00180 // 00181 operator void* (); 00182 // 00184 // 00185 OrientationIter& operator-- (); 00186 // 00188 // 00189 OrientationIter& operator++ (); 00190 // 00192 // 00193 OrientationIter operator-- (int); 00194 // 00196 // 00197 OrientationIter operator++ (int); 00198 // 00200 // 00201 bool operator== (const OrientationIter& oi) const; 00202 // 00204 // 00205 bool operator!= (const OrientationIter& oi) const; 00206 00207 protected: 00208 int face; 00209 // 00210 // Construct an iterator on the face. 00211 // 00212 OrientationIter (int _face); 00213 // 00214 // Is the iterator valid? 00215 // 00216 bool ok () const; 00217 }; 00218 00219 inline 00220 Orientation::Orientation (int _val) 00221 : 00222 val(_val) 00223 {} 00224 00225 inline 00226 Orientation::Orientation () 00227 : 00228 val(-1) 00229 {} 00230 00231 inline 00232 Orientation::Orientation (int _dir, 00233 Side _side) 00234 : 00235 val(BL_SPACEDIM*_side + _dir) 00236 { 00237 BL_ASSERT(0 <= _dir && _dir < BL_SPACEDIM); 00238 } 00239 00240 inline 00241 Orientation::Orientation (const Orientation& o) 00242 : 00243 val(o.val) 00244 {} 00245 00246 inline 00247 Orientation& 00248 Orientation::operator= (const Orientation& o) 00249 { 00250 val = o.val; 00251 return *this; 00252 } 00253 00254 inline 00255 bool 00256 Orientation::operator== (const Orientation& o) const 00257 { 00258 return val == o.val; 00259 } 00260 00261 inline 00262 bool 00263 Orientation::operator!= (const Orientation& o) const 00264 { 00265 return val != o.val; 00266 } 00267 00268 inline 00269 bool 00270 Orientation::operator< (const Orientation& o) const 00271 { 00272 return val < o.val; 00273 } 00274 00275 inline 00276 bool 00277 Orientation::operator<= (const Orientation& o) const 00278 { 00279 return val <= o.val; 00280 } 00281 00282 inline 00283 bool 00284 Orientation::operator> (const Orientation& o) const 00285 { 00286 return val > o.val; 00287 } 00288 00289 inline 00290 bool 00291 Orientation::operator>= (const Orientation& o) const 00292 { 00293 return val >= o.val; 00294 } 00295 00296 inline 00297 Orientation::operator int () const 00298 { 00299 return val; 00300 } 00301 00302 inline 00303 int 00304 Orientation::coordDir () const 00305 { 00306 return val%BL_SPACEDIM; 00307 } 00308 00309 inline 00310 Orientation::Side 00311 Orientation::faceDir () const 00312 { 00313 return Side(val/BL_SPACEDIM); 00314 } 00315 00316 inline 00317 bool 00318 Orientation::isLow () const 00319 { 00320 return val < BL_SPACEDIM; 00321 } 00322 00323 inline 00324 bool 00325 Orientation::isHigh () const 00326 { 00327 return val >= BL_SPACEDIM; 00328 } 00329 00330 inline 00331 Orientation 00332 Orientation::flip () const 00333 { 00334 return Orientation(val < BL_SPACEDIM ? val+BL_SPACEDIM : val-BL_SPACEDIM); 00335 } 00336 00337 inline 00338 OrientationIter::OrientationIter (int _face) 00339 : 00340 face(_face) 00341 {} 00342 00343 inline 00344 OrientationIter::OrientationIter () 00345 : 00346 face(0) 00347 {} 00348 00349 inline 00350 OrientationIter::OrientationIter (const Orientation& _face) 00351 : 00352 face(_face) 00353 {} 00354 00355 inline 00356 bool 00357 OrientationIter::ok () const 00358 { 00359 return 0 <= face && face < 2*BL_SPACEDIM; 00360 } 00361 00362 inline 00363 OrientationIter::OrientationIter (const OrientationIter& it) 00364 { 00365 BL_ASSERT(it.ok()); 00366 face = it.face; 00367 } 00368 00369 inline 00370 OrientationIter& 00371 OrientationIter::operator= (const OrientationIter& it) 00372 { 00373 BL_ASSERT(it.ok()); 00374 face = it.face; 00375 return *this; 00376 } 00377 00378 inline 00379 void 00380 OrientationIter::rewind () 00381 { 00382 face = 0; 00383 } 00384 00385 inline 00386 Orientation 00387 OrientationIter::operator() () const 00388 { 00389 BL_ASSERT(ok()); 00390 return Orientation(face); 00391 } 00392 00393 inline 00394 OrientationIter::operator void* () 00395 { 00396 return 0 <= face && face < 2*BL_SPACEDIM ? this : 0; 00397 } 00398 00399 inline 00400 OrientationIter& 00401 OrientationIter::operator-- () 00402 { 00403 BL_ASSERT(ok()); 00404 --face; 00405 return *this; 00406 } 00407 00408 inline 00409 OrientationIter& 00410 OrientationIter::operator++ () 00411 { 00412 BL_ASSERT(ok()); 00413 ++face; 00414 return *this; 00415 } 00416 00417 inline 00418 OrientationIter 00419 OrientationIter::operator-- (int) 00420 { 00421 BL_ASSERT(ok()); 00422 return OrientationIter(face--); 00423 } 00424 00425 inline 00426 OrientationIter 00427 OrientationIter::operator++ (int) 00428 { 00429 BL_ASSERT(ok()); 00430 return OrientationIter(face++); 00431 } 00432 00433 inline 00434 bool 00435 OrientationIter::operator== (const OrientationIter& oi) const 00436 { 00437 BL_ASSERT(ok() && oi.ok()); 00438 return face == oi.face; 00439 } 00440 00441 inline 00442 bool 00443 OrientationIter::operator!= (const OrientationIter& oi) const 00444 { 00445 BL_ASSERT(ok() && oi.ok()); 00446 return face != oi.face; 00447 } 00448 00449 #endif /*BL_ORIENTATION_H*/