src/Field/GuardCellSizes.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /***************************************************************************
00003  *
00004  * The IPPL Framework
00005  * 
00006  *
00007  * Visit http://people.web.psi.ch/adelmann/ for more details
00008  *
00009  ***************************************************************************/
00010 
00011 #ifndef GUARD_CELL_SIZES_H
00012 #define GUARD_CELL_SIZES_H
00013 
00014 // include files
00015 #include "Index/NDIndex.h"
00016 
00017 #ifdef IPPL_USE_STANDARD_HEADERS
00018 #include <iostream>
00019 using namespace std;
00020 #else
00021 #include <iostream.h>
00022 #endif
00023 
00024 
00025 template<unsigned Dim>
00026 class GuardCellSizes
00027 {
00028 
00029 public:
00030 
00031   GuardCellSizes()
00032   {
00033     for (unsigned d=0; d<Dim; ++d)
00034       Left[d] = Right[d] = 0;
00035   }
00036   GuardCellSizes(unsigned s);
00037   GuardCellSizes(unsigned *s);
00038   GuardCellSizes(unsigned l, unsigned r);
00039   GuardCellSizes(unsigned *l, unsigned *r);
00040 
00041   GuardCellSizes<Dim>& operator=(const GuardCellSizes<Dim>& gc)
00042   {
00043     for (unsigned d=0; d<Dim; ++d) {
00044       Left[d]  = gc.Left[d];
00045       Right[d] = gc.Right[d];
00046     }
00047     return *this;
00048   }
00049 
00050   void set_Left(unsigned s);
00051   void set_Left(unsigned *s);
00052   void set_Left(unsigned d, unsigned *s);
00053 
00054   void set_Right(unsigned s);
00055   void set_Right(unsigned *s);
00056   void set_Right(unsigned d, unsigned *s);
00057 
00058   unsigned left(unsigned d) const { return Left[d]; }
00059   unsigned right(unsigned d) const { return Right[d]; }
00060 
00061   // Lexigraphic compare of two GuardCellSizes so we can
00062   // use them as a Key in a map.
00063   bool operator<(const GuardCellSizes<Dim>& r) const ;      
00064   bool operator==(const GuardCellSizes<Dim>& r) const;
00065 
00066 private:
00067 
00068   unsigned Left[Dim];
00069   unsigned Right[Dim];
00070 
00071 };
00072 
00073 template<unsigned Dim>
00074 inline NDIndex<Dim>
00075 AddGuardCells(const NDIndex<Dim>& idx, const GuardCellSizes<Dim>& g)
00076 {
00077   NDIndex<Dim> ret;
00078   for (int d=0; d<Dim; ++d)
00079     ret[d] = Index(idx[d].min() - g.left(d), idx[d].max() + g.right(d));
00080   return ret;
00081 }
00082 
00083 
00084 template<unsigned Dim>
00085 // Lexigraphic compare of two GuardCellSizes so we can
00086 // use them as a Key in a map.
00087 inline bool 
00088 GuardCellSizes<Dim>::operator<(const GuardCellSizes<Dim>& r) const 
00089 {
00090   for (unsigned d=0; d<Dim; ++d) {
00091     if ( left(d) != r.left(d) )
00092       return ( left(d) < r.left(d) );
00093     if ( right(d) != r.right(d) )
00094       return ( right(d) < r.right(d) );
00095   }
00096   // If we get here they're equal.
00097   return false;
00098 }
00099 
00100 template<unsigned Dim>
00101 inline bool 
00102 GuardCellSizes<Dim>::operator==(const GuardCellSizes<Dim>& r) const 
00103 {
00104   for (unsigned d=0; d<Dim; ++d) {
00105     if ( left(d) != r.left(d) )
00106       return false;
00107     if ( right(d) != r.right(d) )
00108       return false;
00109   }
00110   // If we get here they're equal.
00111   return true;
00112 }
00113 
00115 
00116 template<unsigned Dim>
00117 ostream& operator<<(ostream&,const GuardCellSizes<Dim>&);
00118 
00120 
00121 #include "Field/GuardCellSizes.cpp"
00122 
00123 #endif // GUARD_CELL_SIZES_H
00124 
00125 /***************************************************************************
00126  * $RCSfile: GuardCellSizes.h,v $   $Author: adelmann $
00127  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:26 $
00128  * IPPL_VERSION_ID: $Id: GuardCellSizes.h,v 1.1.1.1 2003/01/23 07:40:26 adelmann Exp $ 
00129  ***************************************************************************/

Generated on Mon Jan 16 13:23:44 2006 for IPPL by  doxygen 1.4.6