Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

SgNodeUtil.cpp

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 /** @file SgNodeUtil.cpp
00003     See SgNodeUtil.h */
00004 //----------------------------------------------------------------------------
00005 
00006 #include "SgSystem.h"
00007 #include "SgNodeUtil.h"
00008 
00009 #include <vector>
00010 #include "SgNode.h"
00011 #include "SgTimeRecord.h"
00012 
00013 using namespace std;
00014 
00015 //----------------------------------------------------------------------------
00016 
00017 int SgNodeUtil::GetMoveNumber(const SgNode* node)
00018 {
00019     int nuMoves = 0;
00020     while (node != 0)
00021     {
00022         if (node->HasProp(SG_PROP_MOVE))
00023             ++nuMoves;
00024         if (node->HasProp(SG_PROP_ADD_BLACK)
00025             || node->HasProp(SG_PROP_ADD_WHITE)
00026             || node->HasProp(SG_PROP_ADD_EMPTY))
00027             break;
00028         node = node->Father();
00029     }
00030     return nuMoves;
00031 }
00032 
00033 void SgNodeUtil::RemovePropInSubtree(SgNode& root, SgPropID id)
00034 {
00035     root.Props().RemoveProp(id);
00036     for (SgSonNodeIterator it(&root); it; ++it)
00037         RemovePropInSubtree(*(*it), id);
00038 }
00039 
00040 void SgNodeUtil::UpdateTime(SgTimeRecord& time, const SgNode* node)
00041 {
00042     vector<const SgNode*> nodes;
00043     while (node != 0)
00044     {
00045         nodes.push_back(node);
00046         node = node->Father();
00047     }
00048     for (vector<const SgNode*>::reverse_iterator it = nodes.rbegin();
00049          it != nodes.rend(); ++it)
00050     {
00051         const SgNode* node = *it;
00052         if (node->HasProp(SG_PROP_LOSE_TIME))
00053             time.SetLoseOnTime(true);
00054         if (node->HasProp(SG_PROP_OT_NU_MOVES))
00055             time.SetOTNumMoves(node->GetIntProp(SG_PROP_OT_NU_MOVES));
00056         if (node->HasProp(SG_PROP_OT_PERIOD))
00057             time.SetOTPeriod(node->GetRealProp(SG_PROP_OT_PERIOD));
00058         if (node->HasProp(SG_PROP_OVERHEAD))
00059             time.SetOverhead(node->GetRealProp(SG_PROP_OVERHEAD));
00060     }
00061 }
00062 
00063 //----------------------------------------------------------------------------


Sun Mar 13 2011 Doxygen 1.7.1