proj home

Files   Classes   Functions   Hierarchy  

cellD2.h

Go to the documentation of this file.
00001 #ifndef CELLD2_H
00002 #define CELLD2_H
00003 
00004 #include <iostream>
00005 #include <sstream>
00006 using namespace std;
00007 
00008 #include <typedefs.h>
00009 
00017 template< typename T >
00018 class cellD2
00019 {
00020 public:
00021 
00023   T id;
00024 
00026   T ni[4];
00027 
00029   cellD2();
00030 
00032   uintc degree() const;
00033   
00035   uintc niInv(T x) const;
00036 
00038   boolc unvisited() const
00039     { return degree()==0; }
00040 
00042   operator stringc () const;
00043 
00045   void serializeInverse(stringc & s);
00046 
00048   istream & serializeInverse(istream & istr);
00049 
00050 };
00051 
00052 
00053 //----------------------------------------------------------
00054 // Implementation
00055 
00056 template< typename T >
00057 cellD2<T>::cellD2()
00058 {
00059   id=0;
00060   ni[0]=0;
00061   ni[1]=0;
00062   ni[2]=0;
00063   ni[3]=0;
00064 }
00065 
00066 template< typename T >
00067 uintc cellD2<T>::niInv(T x) const
00068 {
00069   if (ni[0]==x)
00070     return 0;
00071   if (ni[1]==x)
00072     return 1;
00073   if (ni[2]==x)
00074     return 2;
00075   if (ni[3]==x)
00076     return 3;
00077 
00078   return 4;
00079 }
00080 
00081 template< typename T >
00082 uintc cellD2<T>::degree() const
00083 {
00084   uint count=0;
00085   if (ni[0])
00086     ++count;
00087   if (ni[1])
00088     ++count;
00089   if (ni[2])
00090     ++count;
00091   if (ni[3])
00092     ++count;
00093 
00094   return count;
00095 }
00096 
00097 
00098 template< typename T >
00099 cellD2<T>::operator stringc () const
00100 {
00101   string s;
00102   stringstream ss;
00103   ss << id;
00104   ss << " ";
00105   ss << ni[0];
00106   ss << " ";
00107   ss << ni[1];
00108   ss << " ";
00109   ss << ni[2];
00110   ss << " ";
00111   ss << ni[3];
00112 
00113   return ss.str();
00114 }
00115 
00116 template< typename T >
00117 void cellD2<T>::serializeInverse(stringc & s)
00118 {
00119   stringstream ss(s);
00120   ss >> id >> ni[0] >> ni[1] >> ni[2] >> ni[3];
00121 }
00122 
00123 template< typename T >
00124 istream & cellD2<T>::serializeInverse(istream & istr)
00125 { 
00126   return istr >> id >> ni[0] >> ni[1] >> ni[2] >> ni[3];
00127 }
00128 
00129 
00130 
00131 #endif
00132 

Generated on Fri Mar 4 00:49:28 2011 for Chelton Evans Source by  doxygen 1.5.8