proj home

Files   Classes   Functions   Hierarchy  

mazematrixmapD2< T, W > Class Template Reference

Build a map relative to a cell. More...

#include <mazematrixmapD2.h>

Inheritance diagram for mazematrixmapD2< T, W >:
Collaboration diagram for mazematrixmapD2< T, W >:

List of all members.

Public Types

typedef map< T, point2< W > > mapping
typedef mapping::iterator mappingiterator

Public Member Functions

void relativeto (T i)
 Create a new map from ith cell as zero (0,0).
void eval ()
 Build the map, called after reset(i);.
void changeSet (W dx_, W dy_)
 Set the change relative to positive x and positive y axes.
 mazematrixmapD2 (mazematrixD2< T > &mz_, W dx_, W dy_)
 Constructor.
void reset ()
 Reset the iterator.
T currentIndex ()
 Access the current index.
cellD2< T > & currentCell ()
 Access the current cell.
point2< W > & currentPosition ()
 Access the current position.
boolc operator! ()
 Is this iterator valid?
void operator++ ()
 Increment iterator.
boolc add (T id)
 The id must already be in the map ipt.

Public Attributes

mapping ipt
 Index to point mapping.
mappingiterator iter
 Actual iterator used.
T zeroindex
 Origin cell.
mazematrixD2< T > & mz
 Data structure which a map relative to a cell is created.
dx
 Change in x.
dy
 Change in y.


Detailed Description

template<typename T, typename W>
class mazematrixmapD2< T, W >

Build a map relative to a cell.

This is an iterator, where the cells neighbours are interpreted from top in a clockwise direction. The change is added and subtracted when a link is transversed.

Two types of iteration - map iteration and movement.

Definition at line 22 of file mazematrixmapD2.h.


Member Typedef Documentation

template<typename T, typename W>
typedef map< T, point2<W> > mazematrixmapD2< T, W >::mapping

Definition at line 26 of file mazematrixmapD2.h.

template<typename T, typename W>
typedef mapping::iterator mazematrixmapD2< T, W >::mappingiterator

Definition at line 27 of file mazematrixmapD2.h.


Constructor & Destructor Documentation

template<typename T, typename W>
mazematrixmapD2< T, W >::mazematrixmapD2 ( mazematrixD2< T > &  mz_,
dx_,
dy_ 
) [inline]

Constructor.

Definition at line 55 of file mazematrixmapD2.h.

00056     : zeroindex(0), mz(mz_)
00057     { changeSet(dx_,dy_); }


Member Function Documentation

template<typename T, typename W >
boolc mazematrixmapD2< T, W >::add ( T  id  )  [inline]

The id must already be in the map ipt.

Definition at line 143 of file mazematrixmapD2.h.

References mazematrixmapD2< T, W >::dx, mazematrixmapD2< T, W >::dy, mazematrixmapD2< T, W >::ipt, mazematrixmapD2< T, W >::iter, mazematrixmapD2< T, W >::mz, cellD2< T >::ni, point2< T >::x, and point2< T >::y.

00144 {
00145   assert(id!=0);
00146   assert(id<mz.vi.size());
00147 
00148   if (id==0)
00149     return false;
00150   if (id >= mz.vi.size())
00151     return false;
00152 
00153   iter = ipt.find(id); 
00154 
00155   assert(iter!=ipt.end());
00156   if (iter==ipt.end())
00157     return false;
00158   
00159   point2<W> k((*iter).second);
00160 
00161   // Assume uniqueness of cells. 
00162 
00163   mappingiterator i2;
00164   cellD2<T> & x(mz.vi[id]);
00165 
00166   if (x.ni[0]!=0)
00167   {
00168     i2=ipt.find(x.ni[0]);
00169     if (i2==ipt.end())
00170     {
00171       ipt.insert( make_pair(x.ni[0],point2<W>(k.x,k.y+dy)) );
00172     }
00173   }
00174 
00175   if (x.ni[2]!=0)
00176   {
00177     i2=ipt.find(x.ni[2]);
00178     if (i2==ipt.end())
00179     {
00180       ipt.insert( make_pair(x.ni[2],point2<W>(k.x,k.y-dy)) );
00181     }
00182   }
00183 
00184   if (x.ni[1]!=0)
00185   {
00186     i2=ipt.find(x.ni[1]);
00187     if (i2==ipt.end())
00188     {
00189       ipt.insert( make_pair(x.ni[1],point2<W>(k.x+dx,k.y)) );
00190     }
00191   }
00192 
00193   if (x.ni[3]!=0)
00194   {
00195     i2=ipt.find(x.ni[3]);
00196     if (i2==ipt.end())
00197     {
00198       ipt.insert( make_pair(x.ni[3],point2<W>(k.x-dx,k.y)) );
00199     }
00200   }
00201 
00202   return true;
00203 }

template<typename T, typename W>
void mazematrixmapD2< T, W >::changeSet ( dx_,
dy_ 
) [inline]

Set the change relative to positive x and positive y axes.

Definition at line 51 of file mazematrixmapD2.h.

Referenced by mazematrixmapD2< uint, int >::mazematrixmapD2().

00052     { dx=dx_; dy=dy_; }

template<typename T, typename W>
cellD2<T>& mazematrixmapD2< T, W >::currentCell (  )  [inline]

Access the current cell.

Definition at line 67 of file mazematrixmapD2.h.

Referenced by mazematrixmapD2< T, W >::eval().

00068     { return mz.vi[(*iter).first]; }

template<typename T, typename W>
T mazematrixmapD2< T, W >::currentIndex (  )  [inline]

Access the current index.

Definition at line 64 of file mazematrixmapD2.h.

Referenced by maze001::constructgraphics(), and mazedisp01::draw().

00065     { return (*iter).first; }

template<typename T, typename W>
point2<W>& mazematrixmapD2< T, W >::currentPosition (  )  [inline]

Access the current position.

Definition at line 70 of file mazematrixmapD2.h.

Referenced by maze001::constructgraphics(), and mazedisp01::draw().

00071     { return (*iter).second; }

template<typename T , typename W >
void mazematrixmapD2< T, W >::eval (  )  [inline]

Build the map, called after reset(i);.

Definition at line 102 of file mazematrixmapD2.h.

References mazematrixmapD2< T, W >::currentCell(), cellD2< T >::id, mazematrixmapD2< T, W >::ipt, mazematrixmapD2< T, W >::iter, and mazematrixmapD2< T, W >::mz.

Referenced by mazedisp01::draw(), and maze001::maze001().

00103 {
00104   iter = ipt.begin();
00105   cellD2<T>& x(currentCell());
00106 
00107   deque<T> process;
00108   process.push_back(x.id);
00109 /*
00110   for (uint k=0; k<4; ++k)
00111   {
00112     if (x.ni[k]!=0)
00113       process.push_back(x.ni[k]);
00114   }
00115 */
00116 
00117   T id;
00118   for ( ; ! process.empty(); )
00119   {
00120     id = process.front();
00121 //cout << SHOW(id) << endl;
00122     process.pop_front();
00123 
00124     assert(id < mz.vi.size());
00125 
00126     cellD2<T>& x2(mz.vi[id]);
00127 
00128     for (uint k=0; k<4; ++k)
00129     {
00130       if (x2.ni[k]!=0)
00131       {
00132         if (ipt.find(x2.ni[k])==ipt.end())
00133           process.push_back(x2.ni[k]);
00134       }
00135     }
00136 
00137     add(id);
00138   }
00139   
00140 }

template<typename T, typename W>
boolc mazematrixmapD2< T, W >::operator! (  )  [inline]

Is this iterator valid?

Definition at line 74 of file mazematrixmapD2.h.

00075     { return iter != ipt.end(); } 

template<typename T, typename W>
void mazematrixmapD2< T, W >::operator++ (  )  [inline]

Increment iterator.

Definition at line 77 of file mazematrixmapD2.h.

00078     { ++iter; }

template<typename T, typename W >
void mazematrixmapD2< T, W >::relativeto ( T  i  )  [inline]

Create a new map from ith cell as zero (0,0).

Definition at line 91 of file mazematrixmapD2.h.

References mazematrixmapD2< T, W >::ipt, mazematrixmapD2< T, W >::mz, and mazematrixmapD2< T, W >::zeroindex.

Referenced by mazedisp01::draw(), and maze001::maze001().

00092 {
00093   ipt.clear();
00094   assert(i<mz.vi.size());
00095   cellD2<T> & x = mz.vi[i];
00096   ipt.insert( make_pair(x.id,point2<W>(0,0)) ); 
00097 
00098   zeroindex=i;
00099 }

template<typename T, typename W>
void mazematrixmapD2< T, W >::reset (  )  [inline]

Reset the iterator.

Definition at line 60 of file mazematrixmapD2.h.

Referenced by maze001::constructgraphics(), and mazedisp01::draw().

00061     { iter=ipt.begin(); }


Member Data Documentation

template<typename T, typename W>
W mazematrixmapD2< T, W >::dx

Change in x.

Definition at line 40 of file mazematrixmapD2.h.

Referenced by mazematrixmapD2< T, W >::add(), and mazematrixmapD2< uint, int >::changeSet().

template<typename T, typename W>
W mazematrixmapD2< T, W >::dy

Change in y.

Definition at line 42 of file mazematrixmapD2.h.

Referenced by mazematrixmapD2< T, W >::add(), and mazematrixmapD2< uint, int >::changeSet().

template<typename T, typename W>
mapping mazematrixmapD2< T, W >::ipt

template<typename T, typename W>
mappingiterator mazematrixmapD2< T, W >::iter

template<typename T, typename W>
mazematrixD2<T>& mazematrixmapD2< T, W >::mz

Data structure which a map relative to a cell is created.

Definition at line 37 of file mazematrixmapD2.h.

Referenced by mazematrixmapD2< T, W >::add(), mazematrixmapD2< uint, int >::currentCell(), mazematrixmapD2< T, W >::eval(), and mazematrixmapD2< T, W >::relativeto().

template<typename T, typename W>
T mazematrixmapD2< T, W >::zeroindex

Origin cell.

Definition at line 34 of file mazematrixmapD2.h.

Referenced by mazematrixmapD2< T, W >::relativeto().


The documentation for this class was generated from the following file:

Generated on Fri Mar 4 00:50:05 2011 for Chelton Evans Source by  doxygen 1.5.8