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


Sun Mar 13 2011 Doxygen 1.7.1