Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

SgIncrementalStack.cpp

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 /** @file SgIncrementalStack.cpp
00003     See SgIncrementalStack.h
00004 */
00005 //----------------------------------------------------------------------------
00006 
00007 #include "SgSystem.h"
00008 #include "SgIncrementalStack.h"
00009 
00010 #include "SgBWSet.h"
00011 #include "SgPointSet.h"
00012 
00013 //----------------------------------------------------------------------------
00014 
00015 void SgIncrementalStack::PushPts(int type, SgEmptyBlackWhite col,
00016                           const SgPointSet& pts)
00017 // Events relevant for maintaining the state in an ExecuteMove or UndoMove
00018 //   are stored in and retrieved from a stack. Each event consists of
00019 //   1. an event type
00020 //   2. the number of points for the event on the stack
00021 //   3. a color (SG_EMPTY, SG_BLACK or SG_WHITE, meaning depends on event
00022 //               type)
00023 //   4. a list of points (as many as given in 2.)
00024 // Events are pushed in reverse order, and popped in the right order
00025 // (e.g. number of items before list of items)
00026 {
00027     int nu = 0;
00028     for (SgSetIterator it(pts); it; ++it)
00029     {
00030         PushPoint(*it);
00031         ++nu;
00032     }
00033     PushInt(col);
00034     PushInt(nu);
00035     PushInt(type);
00036 }
00037 
00038 void SgIncrementalStack::PushPt(int type, SgEmptyBlackWhite col, SgPoint pt)
00039 // same as PushPts for a single point AR: could be optimized for space by
00040 // using different type tags for single and multiple point
00041 {
00042     PushPoint(pt);
00043     PushInt(col);
00044     PushInt(1);// nu pts
00045     PushInt(type);
00046 }
00047 
00048 void SgIncrementalStack::PushPtrEvent(int type, void* ptr)
00049 {
00050     PushPtr(ptr);
00051     PushInt(type);
00052 }
00053 
00054 void SgIncrementalStack::StartMoveInfo()
00055 {
00056     PushInt(SG_NEXTMOVE);
00057 }
00058 
00059 void SgIncrementalStack::Clear()
00060 {
00061     m_stack.Clear();
00062 }
00063 
00064 void SgIncrementalStack::SubtractPoints(SgPointSet* set)
00065 {
00066     int nu = PopInt();
00067     SgEmptyBlackWhite col = PopInt();
00068     SG_UNUSED(col);
00069     for (int i = 1; i <= nu; ++i)
00070     {
00071         SgPoint p = PopPoint();
00072         set->Exclude(p);
00073     }
00074 }
00075 
00076 void SgIncrementalStack::AddPoints(SgPointSet* set)
00077 {
00078     int nu = PopInt();
00079     SgEmptyBlackWhite col = PopInt();
00080     SG_UNUSED(col);
00081     for (int i = 1; i <= nu; ++i)
00082     {
00083         SgPoint p = PopPoint();
00084         set->Include(p);
00085     }
00086 }
00087 
00088 void SgIncrementalStack::SubtractPoints(SgBWSet* set)
00089 {
00090     int nu = PopInt();
00091     SgBlackWhite col = PopInt();
00092     SgPointSet& s = (*set)[col];
00093     for (int i = 1; i <= nu; ++i)
00094     {
00095         SgPoint p = PopPoint();
00096         s.Exclude(p);
00097     }
00098 }
00099 
00100 void SgIncrementalStack::AddPoints(SgBWSet* set)
00101 {
00102     int nu = PopInt();
00103     SgBlackWhite col = PopInt();
00104     SgPointSet& s = (*set)[col];
00105     for (int i = 1; i <= nu; ++i)
00106     {
00107         SgPoint p = PopPoint();
00108         s.Include(p);
00109     }
00110 }
00111 
00112 void SgIncrementalStack::SubtractAndAddPoints(SgBWSet* subtractset,
00113             SgBWSet* addset)
00114 {
00115     int nu = PopInt();
00116     SgBlackWhite col = PopInt();
00117     SgPointSet& s1 = (*subtractset)[col];
00118     SgPointSet& s2 = (*addset)[col];
00119     for (int i = 1; i <= nu; ++i)
00120     {
00121         SgPoint p = PopPoint();
00122         s1.Exclude(p);
00123         s2.Include(p);
00124     }
00125 }
00126 
00127 void SgIncrementalStack::SubtractAndAddPoints(SgPointSet* subtractset,
00128                                        SgBWSet* addset)
00129 {
00130     int nu = PopInt();
00131     SgBlackWhite col = PopInt();
00132     SgPointSet& s1 = (*subtractset);
00133     SgPointSet& s2 = (*addset)[col];
00134     for (int i = 1; i <= nu; ++i)
00135     {
00136         SgPoint p = PopPoint();
00137         s1.Exclude(p);
00138         s2.Include(p);
00139     }
00140 }
00141 
00142 void SgIncrementalStack::SubtractAndAddPoints(SgBWSet* subtractset,
00143                                        SgPointSet* addset)
00144 {
00145     int nu = PopInt();
00146     SgBlackWhite col = PopInt();
00147     SgPointSet& s1 = (*subtractset)[col];
00148     SgPointSet& s2 = (*addset);
00149     for (int i = 1; i <= nu; ++i)
00150     {
00151         SgPoint p = PopPoint();
00152         s1.Exclude(p);
00153         s2.Include(p);
00154     }
00155 }
00156 
00157 //----------------------------------------------------------------------------


17 Jun 2010 Doxygen 1.4.7