proj home

Files   Classes   Functions   Hierarchy  

pnlink.h

Go to the documentation of this file.
00001 #ifndef PNLINK_H
00002 #define PNLINK_H
00003 
00004 #include <typedefs.h>
00005 
00021 template< typename Indx >
00022 class pnlink
00023 {
00024 public:
00025 
00026   typedef Indx const Indxc;
00027 
00029   Indx plink;
00030 
00032   Indx nlink;
00033 
00035   pnlink<Indx> * next;
00036 
00038   pnlink(Indxc plink_, Indxc nlink_)
00039     : plink(plink_), nlink(nlink_), next(this) {}
00041   pnlink(Indxc plink_, Indxc nlink_, pnlink<Indx> * next_)
00042     : plink(plink_), nlink(nlink_), next(next_) {}
00043 
00045   pnlink(Indxc p0, Indxc p1, Indxc n0, Indxc n1);
00047   pnlink(Indxc p0, Indxc p1, Indxc p2, Indxc n0, Indxc n1, Indxc n2);
00049   pnlink(Indxc p0, Indxc p1, Indxc p2, Indxc p3, 
00050          Indxc n0, Indxc n1, Indxc n2, Indxc n3);
00052   pnlink(Indxc p0, Indxc p1, Indxc p2, Indxc p3, Indxc p4, 
00053          Indxc n0, Indxc n1, Indxc n2, Indxc n3, Indxc n4);
00055   pnlink(Indxc p0, Indxc p1, Indxc p2, Indxc p3, Indxc p4, Indxc p5,
00056          Indxc n0, Indxc n1, Indxc n2, Indxc n3, Indxc n4, Indxc n5);
00058   pnlink(Indxc p0, Indxc p1, Indxc p2, Indxc p3, Indxc p4, Indxc p5, Indxc p6,
00059          Indxc n0, Indxc n1, Indxc n2, Indxc n3, Indxc n4, Indxc n5, Indxc n6);
00061   pnlink(Indxc p0, Indxc p1, Indxc p2, Indxc p3, Indxc p4, Indxc p5, Indxc p6, Indxc p7,
00062          Indxc n0, Indxc n1, Indxc n2, Indxc n3, Indxc n4, Indxc n5, Indxc n6, Indxc n7);
00063 
00065   pnlink()
00066     : plink(0), nlink(0), next(0) {}
00067 
00069   pnlink<Indx> * piInverse( Indx gpt ) const;
00071   pnlink<Indx> * niInverse( Indx neib );
00072 
00074   void insert( pnlink<Indx> & next_)
00075     { next_.next = next; next = & next_; }
00077   void addafterself(Indxc p0, Indxc n0)
00078     { next = new pnlink(p0,n0,this->next); }
00079 
00081   boolc add(Indxc ptindx, Indxc p0);
00082 
00084   boolc isnull() const
00085     { return plink==0; }
00086 };
00087 
00088 
00106 template< typename Indx >
00107 class pnlinkiter
00108 {
00109 public:
00110 
00111   typedef pnlink<Indx> link;
00112 
00114   link * start;
00116   link * current;
00117 
00119   pnlinkiter(  link * _start )
00120     : start(_start) {}
00121 
00123   void reset() 
00124     { assert(start!=0); current=start; }
00126   void operator ++ () 
00127     { assert(current!=0); current = current->next; }
00129   boolc operator ! () const
00130     { return current != start; }
00131 
00133   link * operator () () const 
00134     { return current; }
00136   link * operator -> () const
00137     { return current; }
00138 };
00139 
00140 
00141 
00142 
00143 
00147 template< typename Indx >
00148 class pnlinkiterconst
00149 {
00150 public:
00151 
00152   typedef pnlink<Indx> const link;
00153 
00155   link * start;
00157   link * current;
00158 
00160   pnlinkiterconst(  link * _start )
00161     : start(_start) {}
00162 
00164   void reset() 
00165     { assert(start!=0); current=start; }
00167   void operator ++ () 
00168     { assert(current!=0); current = current->next; }
00170   boolc operator ! () const
00171     { return current != start; }
00172 
00174   link * operator () () const 
00175     { return current; }
00177   link * operator -> () const
00178     { return current; }
00179 };
00180 
00181 
00182 //---------------------------------------------------------
00183 // Implementation
00184 
00185 template< typename Indx >
00186 boolc pnlink<Indx>::add(Indxc ptindx, Indxc p0)
00187 {
00188   pnlink<Indx> * pl = piInverse(ptindx);
00189   if (pl==0)
00190     return false;
00191 
00192   Indx n0 = pl->nlink;
00193   pl->addafterself(p0,n0);
00194 
00195   return true;
00196 }
00197 
00198 template< typename Indx >
00199 pnlink<Indx> * pnlink<Indx>::piInverse( Indx gpt ) const
00200 {
00201   pnlinkiter<Indx> iter(this);
00202   for ( iter.reset(); !iter; ++iter )
00203   {
00204     if (iter->plink==gpt)
00205       return iter();
00206   }
00207 
00208   return 0;
00209 }
00210 
00211 template< typename Indx >
00212 pnlink<Indx> * pnlink<Indx>::niInverse( Indx neib ) 
00213 {
00214   pnlinkiter<Indx> iter(this);
00215   for ( iter.reset(); !iter; ++iter )
00216   {
00217     if (iter->nlink==neib)
00218       return iter();
00219   }
00220 
00221   return 0;
00222 }
00223 
00224 template< typename Indx >
00225 pnlink<Indx>::pnlink
00226 (
00227   Indxc p0, Indxc p1, Indxc n0, Indxc n1
00228 )
00229 {
00230   plink = p0;
00231   nlink = n0;
00232   next = this;
00233   addafterself(p1,n1);
00234 }
00235 
00236 template< typename Indx >
00237 pnlink<Indx>::pnlink
00238 (
00239   Indxc p0, Indxc p1, Indxc p2, Indxc n0, Indxc n1, Indxc n2
00240 )
00241 {
00242   plink = p0;
00243   nlink = n0;
00244   next = this;
00245   addafterself(p2,n2);
00246   addafterself(p1,n1);
00247 }
00248 
00249 template< typename Indx >
00250 pnlink<Indx>::pnlink
00251 (
00252   Indxc p0, Indxc p1, Indxc p2, Indxc p3, Indxc n0, Indxc n1, Indxc n2, 
00253   Indxc n3
00254 )
00255 {
00256   plink = p0;
00257   nlink = n0;
00258   next = this;
00259   addafterself(p3,n3);
00260   addafterself(p2,n2);
00261   addafterself(p1,n1);
00262 }
00263 
00264 template< typename Indx >
00265 pnlink<Indx>::pnlink
00266 (
00267   Indxc p0, Indxc p1, Indxc p2, Indxc p3, Indxc p4, Indxc n0, Indxc n1, 
00268   Indxc n2, Indxc n3, Indxc n4
00269 )
00270 {
00271   plink = p0;
00272   nlink = n0;
00273   next = this;
00274   addafterself(p4,n4);
00275   addafterself(p3,n3);
00276   addafterself(p2,n2);
00277   addafterself(p1,n1);
00278 }
00279 
00280 template< typename Indx >
00281 pnlink<Indx>::pnlink
00282 (
00283   Indxc p0, Indxc p1, Indxc p2, Indxc p3, Indxc p4, Indxc p5, Indxc n0, 
00284   Indxc n1, Indxc n2, Indxc n3, Indxc n4, Indxc n5
00285 )
00286 {
00287   plink = p0;
00288   nlink = n0;
00289   next = this;
00290   addafterself(p5,n5);
00291   addafterself(p4,n4);
00292   addafterself(p3,n3);
00293   addafterself(p2,n2);
00294   addafterself(p1,n1);
00295 }
00296 
00297 template< typename Indx >
00298 pnlink<Indx>::pnlink
00299 (
00300   Indxc p0, Indxc p1, Indxc p2, Indxc p3, Indxc p4, Indxc p5, Indxc p6, 
00301   Indxc n0, Indxc n1, Indxc n2, Indxc n3, Indxc n4, Indxc n5, Indxc n6
00302 )
00303 {
00304   plink = p0;
00305   nlink = n0;
00306   next = this;
00307   addafterself(p6,n6);
00308   addafterself(p5,n5);
00309   addafterself(p4,n4);
00310   addafterself(p3,n3);
00311   addafterself(p2,n2);
00312   addafterself(p1,n1);
00313 }
00314 
00315 template< typename Indx >
00316 pnlink<Indx>::pnlink
00317 (
00318   Indxc p0, Indxc p1, Indxc p2, Indxc p3, Indxc p4, Indxc p5, Indxc p6, Indxc p7,
00319   Indxc n0, Indxc n1, Indxc n2, Indxc n3, Indxc n4, Indxc n5, Indxc n6, Indxc n7
00320 )
00321 {
00322   plink = p0;
00323   nlink = n0;
00324   next = this;
00325   addafterself(p7,n7);
00326   addafterself(p6,n6);
00327   addafterself(p5,n5);
00328   addafterself(p4,n4);
00329   addafterself(p3,n3);
00330   addafterself(p2,n2);
00331   addafterself(p1,n1);
00332 }
00333 
00334 
00335 
00336 #endif
00337 
00338 

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