cell.h

Go to the documentation of this file.
00001 #ifndef __cell_h
00002 #define __cell_h
00003 
00004 #include  "fixarray.h"
00005 #include  <string>
00006 #include  "gascoigne.h"
00007 
00008 /*-----------------------------------------------------------*/
00009 
00010 // N = no of nodes
00011 // E = no of edges/faces
00012 
00013 /*-----------------------------------------------------------*/
00014 
00015 namespace Gascoigne
00016 {
00017 template<int N, int E>
00018 class Cell :  public fixarray<N,int>   /* das sind die vertex-no. */
00019 {
00020  protected:
00021 
00022   /* Data */
00023 
00024   int              qlevel, qfather;
00025   IntVector         qchilds;
00026   fixarray<E,int>  qedges;            /* edge numbers */
00027 
00028  public:
00029 
00030   /* Constructors */
00031 
00032   Cell() : 
00033     fixarray<N,int>(), 
00034     qlevel(0), 
00035     qfather(-1) 
00036     { 
00037       qedges=-1; 
00038     }
00039 
00040   Cell(const Cell& c) : 
00041     fixarray<N,int>(c) , 
00042     qlevel(c.level()), 
00043     qfather(c.father()), 
00044     qchilds(c.childs()), 
00045     qedges(c.edges()) {}
00046 
00047   Cell(int l, int f) : 
00048     fixarray<N,int>(-17), 
00049     qlevel(l), 
00050     qfather(f) {}
00051 
00052   /* Operators */
00053 
00054   Cell<N,E>& operator=(const Cell<N,E>& c)
00055     {
00056       vertex() = c.vertex();
00057       qlevel   = c.level(); 
00058       qfather  = c.father(); 
00059       qchilds.memory(c.nchilds());
00060       qchilds  = c.childs();
00061       qedges   = c.edges();
00062       return *this;
00063     }
00064   bool operator==(const Cell<N,E>& c) const
00065     {
00066       if (vertex()==c.vertex()) return 1;
00067       return 0;
00068     }
00069 
00070   /* Zugriff */
00071 
00072   int   level  ()     const { return qlevel;}          
00073   int&  level  ()           { return qlevel;}          
00074   int   father ()     const { return qfather;}          
00075   int&  father ()           { return qfather;}          
00076   bool  sleep  ()     const { return qchilds.size()!=0;}          
00077   int   nchilds()     const { return qchilds.size();}          
00078   int   nvertexs()    const { return N;}          
00079   int   child (int i) const { return qchilds[i];}          
00080   int&  child (int i)       { return qchilds[i];}          
00081   int   vertex(int i) const { return (*this)[i];}          
00082   int&  vertex(int i)       { return (*this)[i];}          
00083   int   edge  (int i) const { return qedges[i];}          
00084   int&  edge  (int i)       { return qedges[i];}          
00085 
00086   const IntVector&  childs()       const { return qchilds;}          
00087         IntVector&  childs()             { return qchilds;}          
00088   const fixarray<N,int>& vertex() const { return (*this);}
00089         fixarray<N,int>& vertex()       { return (*this);}
00090   const fixarray<E,int>& edges()  const { return qedges;}
00091         fixarray<E,int>& edges()        { return qedges;}
00092 
00093   /* Functions */
00094 
00095   template<int M>
00096   void vertex_loc2glob(fixarray<M,int>& ig, 
00097                  const fixarray<M,int>& il) const
00098     {
00099       typename fixarray<M,int>::iterator        gp=ig.begin();
00100       typename fixarray<M,int>::const_iterator  lp=il.begin();
00101       while(lp!=il.end())  *gp++ = (*this)[*lp++];
00102     }
00103 
00104   int global2local(int gi) const;
00105   
00106   void BinWrite(std::ostream &s) const
00107   {
00108     vertex().BinWrite(s);
00109     int sizeInt = sizeof(int);
00110     s.write(reinterpret_cast<const char*>(&qlevel),sizeInt);
00111     s.write(reinterpret_cast<const char*>(&qfather),sizeInt);
00112     int nc = nchilds();
00113     s.write(reinterpret_cast<const char*>(&nc),sizeInt);
00114     for (int i=0; i<nchilds(); i++)
00115     {
00116       s.write(reinterpret_cast<const char*>(&qchilds[i]),sizeInt);
00117     }
00118     edges().BinWrite(s);
00119   }
00120 
00121   void BinRead(std::istream &s)
00122   {
00123     vertex().BinRead(s);
00124     int sizeInt = sizeof(int);
00125     s.read(reinterpret_cast<char*>(&qlevel),sizeInt);
00126     s.read(reinterpret_cast<char*>(&qfather),sizeInt);
00127     int nc;
00128     s.read(reinterpret_cast<char*>(&nc),sizeInt);
00129     childs().resize(nc);
00130     for (int i=0; i<nchilds(); i++)
00131     {
00132       s.read(reinterpret_cast<char*>(&qchilds[i]),sizeInt);
00133     }
00134     edges().BinRead(s);
00135   }
00136 
00137   friend std::ostream& operator<<(std::ostream &s, const Cell& A)
00138     {
00139       s << A.vertex()  << " ";
00140       s << A.level()   << " ";
00141       s << A.father()  << " @ ";
00142       s << A.nchilds() << " " << A.childs();
00143       s << " : " << A.edges();
00144       s << std::endl;
00145       
00146       return s;
00147     }
00148   
00149   friend std::istream& operator>>(std::istream& s, Cell& A) 
00150     {
00151       std::string symbol;
00152       int  n;
00153       s >> A.vertex();
00154       s >> A.level() ;
00155       s >> A.father();
00156       s >> symbol;
00157       if (symbol!="@")
00158         {
00159           std::cout << "ERROR: Cell::operator>>" << std::endl;
00160           exit(1);
00161         }
00162       s >> n;
00163       A.childs().resize(n);
00164       s >> A.childs();
00165       s >> symbol;
00166       if (symbol!=":")
00167         {
00168           std::cout << "ERROR: Cell::operator>>" << std::endl;
00169           exit(1);
00170         }
00171       s >> A.edges();
00172       return s;
00173     }
00174 };
00175 
00176 template<int N, int E>
00177 inline int Cell<N,E>::global2local(int gi) const
00178 {
00179   for (int i=0; i<N; i++)
00180     {
00181       if (vertex(i)==gi) return i;
00182     }
00183   return -1;
00184 }
00185 }
00186 
00187 /*---------------------------------------------------*/
00188 
00189 #endif

Generated on Thu Sep 14 10:34:37 2006 for Gascoigne by  doxygen 1.4.7