00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef GUARD_CELL_SIZES_H
00012 #define GUARD_CELL_SIZES_H
00013
00014
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
00062
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
00086
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
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
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
00127
00128
00129