AMROC Main     Blockstructured Adaptive Mesh Refinement in object-oriented C++


Main Page   Class Hierarchy   Compound List   File List  

Coords.h

Go to the documentation of this file.
00001 #ifndef _included_Coords_h
00002 #define _included_Coords_h
00003 
00009 #include "DAGHDefaults.h"
00010 
00011 #include "lparx_copyright.h"
00012 #include <iostream.h>
00013 #include <fstream.h>
00014 #include "streams_CompConf.h"
00015 #include <assert.h>
00016 
00017 #ifndef CoordsMaxDim
00018 #define CoordsMaxDim    (3)
00019 #endif
00020 
00021 #define CoordsNULL      ((Coords *)NULL)
00022 
00023 #ifndef NULL
00024 #define NULL 0
00025 #endif
00026 
00027 class CoordsIterator;
00028 
00029 
00037 class Coords
00038   {
00039    friend istream& operator >> (istream& s, Coords& c);
00040    friend ostream& operator << (ostream& s, const Coords& c);
00041    friend ifstream& operator >> (ifstream& s, Coords& c);
00042    friend ofstream& operator << (ofstream& s, const Coords& c);
00043 
00044    int c[CoordsMaxDim];
00045 
00046 public:
00047    int rank;
00048    static class Coords _empty_coords;
00049 
00050 public:
00051    typedef CoordsIterator Iterator;
00052 
00053    /* Constructors and Destructors */
00054    inline Coords(void) : rank(0) 
00055      { c[0] = 0; c[1] = 0; c[2] = 0; }
00056 
00057    //On the SP2 this allow implicit type conversion from everything 
00058    //this class
00059    //inline Coords(int const r) : rank(r) 
00060    //  { c[0] = 0; c[1] = 0; c[2] = 0; }
00061 
00062    inline Coords(int const r, int const val) : rank(r)
00063      { c[0] = val; c[1] = val; c[2] = val; }
00064 
00065    inline Coords(int const r, int const *val) : rank(r)
00066      { register int i; for (i=0; i<rank; i++) c[i] = val[i]; }
00067 
00068    inline Coords(Coords const &other) : rank(other.rank)
00069      { c[0] = other.c[0]; c[1] = other.c[1]; c[2] = other.c[2]; }
00070 
00071    /* Specific constructors for 2 & 3 D */
00072    inline Coords(int const r, int const i, int const j) : rank(r) 
00073      { assert(r == 2); c[0] = i; c[1] = j; }
00074    inline Coords(int const r, int const i, int const j, int const k) : rank(r) 
00075      { assert(r == 3); c[0] = i; c[1] = j; c[2] = k; }
00076 
00077    Coords &operator = (Coords const &rhs)
00078      { 
00079        rank = rhs.rank;
00080        c[0] = rhs.c[0]; c[1] = rhs.c[1]; c[2] = rhs.c[2]; 
00081        return *this;
00082      }
00083 
00084    Coords &operator = (const int &rhs)
00085      { c[0] = c[1] = c[2] = rhs; return *this; }
00086 
00087    inline ~Coords() {}
00088 
00089    /* Some simple operators on Coords -- const and non-const ones */
00090    inline int& operator () (int const i) { return(c[i]); }
00091    inline int operator () (int const i) const { return(c[i]); }
00092 
00093    inline int * operator () (void) { return(c); }
00094    inline int * operator () (void) const { return((int *)c); }
00095 
00096    inline operator int * () { return(c); }
00097    inline operator int * () const { return((int *)c); }
00098 
00099    /* For the clustering hdf calls */
00100    inline operator long int * () { return((long int *)c); }
00101    inline operator const long int * () const { return((long int *)c); }
00102 
00103    /* Define all of the operators between two Coords */
00104 #define Point_Point_Operator(ope,op)                            \
00105    Coords& operator ope (Coords const &rhs)                     \
00106      {                                                          \
00107       c[0] ope rhs.c[0];                                        \
00108       if (rank>1) c[1] ope rhs.c[1];                            \
00109       if (rank>2) c[2] ope rhs.c[2];                            \
00110       return(*this);                                            \
00111      }                                                          \
00112    Coords operator op (Coords const &rhs) const                 \
00113      {                                                          \
00114       Coords coords(*this);                                     \
00115       coords ope rhs;                                           \
00116       return(coords);                                           \
00117      }
00118    Point_Point_Operator(+=,+)
00119    Point_Point_Operator(-=,-)
00120    Point_Point_Operator(*=,*)
00121    Point_Point_Operator(/=,/)
00122    Point_Point_Operator(%=,%)
00123 #undef Point_Point_Operator
00124 
00125    /* Define all of the operators between a point and an integer */
00126 #define Point_Scalar_Operator(ope,op)                           \
00127    Coords& operator ope (int const rhs)                         \
00128      {                                                          \
00129       c[0] ope rhs;                                             \
00130       if (rank>1) c[1] ope rhs;                                 \
00131       if (rank>2) c[2] ope rhs;                                 \
00132       return(*this);                                            \
00133      }                                                          \
00134    Coords operator op (int const rhs) const                     \
00135      {                                                          \
00136       Coords coords(*this);                                     \
00137       coords ope rhs;                                           \
00138       return(coords);                                           \
00139      }
00140    Point_Scalar_Operator(+=,+)
00141    Point_Scalar_Operator(-=,-)
00142    Point_Scalar_Operator(*=,*)
00143    Point_Scalar_Operator(/=,/)
00144    Point_Scalar_Operator(%=,%)
00145 #undef Point_Scalar_Operator
00146 
00147    /* Define the negation operator for a point */
00148    inline Coords operator - () const
00149      { 
00150        Coords coords(rank,0);
00151        coords.c[0] = -c[0]; coords.c[1] = -c[1]; coords.c[2] = -c[2]; 
00152        return(coords);
00153      }
00154 
00155    /* Define the equality and inequality operators for Coords */
00156    inline int operator != (Coords const &rhs) const
00157      {
00158       return ( ((rank > 0) && (c[0] != rhs.c[0])) || 
00159                ((rank > 1) && (c[1] != rhs.c[1])) || 
00160                ((rank > 2) && (c[2] != rhs.c[2]))
00161              ) ;
00162      }
00163    inline int operator == (Coords const &rhs) const
00164      { return(!(*this != rhs)); }
00165 
00166    /* Define the greater-than & less-than operators for Coords */
00167    inline int operator > (Coords const &rhs) const
00168      {
00169       return (!(((rank > 0) && (c[0] <= rhs.c[0])) || 
00170                ((rank > 1) && (c[1] <= rhs.c[1])) || 
00171                ((rank > 2) && (c[2] <= rhs.c[2])))
00172              ) ;
00173      }
00174    inline int operator < (Coords const &rhs) const
00175      {
00176       return (!(((rank > 0) && (c[0] >= rhs.c[0])) || 
00177                ((rank > 1) && (c[1] >= rhs.c[1])) || 
00178                ((rank > 2) && (c[2] >= rhs.c[2])))
00179              ) ;
00180      }
00181 
00182     inline void setval(int const val)
00183       { c[0] = val; c[1] = val; c[2] = val; }
00184     inline void setval(Coords const rhs)
00185       { c[0] = rhs.c[0]; c[1] = rhs.c[1]; c[2] = rhs.c[2]; }
00186   
00187    /* Define elementwise minimum and maximum functions for Coords */
00188    inline void min(Coords const &rhs)
00189      {
00190        //assert (rank == rhs.rank);
00191        c[0] = (rhs.c[0] < c[0]) ? rhs.c[0] : c[0];
00192        c[1] = (rank > 1 && rhs.c[1] < c[1]) ? rhs.c[1] : c[1];
00193        c[2] = (rank > 2 && rhs.c[2] < c[2]) ? rhs.c[2] : c[2];
00194      }
00195 
00196    inline void max(Coords const &rhs)
00197      {
00198        //assert (rank == rhs.rank);
00199        c[0] = (rhs.c[0] > c[0]) ? rhs.c[0] : c[0];
00200        c[1] = (rank > 1 && rhs.c[1] > c[1]) ? rhs.c[1] : c[1];
00201        c[2] = (rank > 2 && rhs.c[2] > c[2]) ? rhs.c[2] : c[2];
00202      }
00203 
00204    inline Coords getmin(Coords const &rhs) const
00205      { Coords other(*this); other.min(rhs); return other; }
00206 
00207    inline Coords getmax(Coords const &rhs) const
00208      { Coords other(*this); other.max(rhs); return other; }
00209   };
00210 
00211 inline Coords Max(const Coords& a, const Coords &b)
00212        { return(a.getmax(b)); }
00213 inline Coords Min(const Coords& a, const Coords &b)
00214        { return(a.getmin(b)); }
00215 
00216 
00217 ostream& operator << (ostream& s, const Coords& c);
00218 istream& operator >> (istream& s, Coords& c);
00219 ifstream& operator>>(ifstream& s, Coords& c);
00220 ofstream& operator<<(ofstream& s, const Coords& c);
00221 
00222 #endif
00223 


Quickstart     Users Guide     Programmers Reference     Installation      Examples     Download



AMROC Main      Home      Contact
last update: 06/01/04