1: 
   2: 
   3: /*********************
   4: *                    *
   5: *  PROJECT INCLUDES  *
   6: *                    *
   7: *********************/
   8:   
   9:   
  10: #include "wwwi/random.h" 
  11: 
  12: 
  13: using std::out_of_range;
  14: using WWWI::GetSingleton;
  15: using WWWI::Random;
  16: using WWWI::RandomPtr;
  17: 
  18: 
  19: /******************
  20: *                 *
  21: *  METHOD EXPIRE  *
  22: *                 *
  23: ******************/
  24: 
  25: 
  26: template <class H> unsigned RRTList<H>::Expire(time_t i_tmNow, time_t &io_tmrNextExpire) {
  27:   typename RRTList<H>::iterator xrpi;
  28:   unsigned uReaped = 0;
  29:   LogHandle lh(LF_CEXPIRE,LY_DEBUG);
  30: 
  31:   xrpi = this->begin();
  32:   while(xrpi!=this->end()) {
  33:     if ((*xrpi)->IsExpired(i_tmNow)==true) {
  34:       lh << "expire reaping " << *(*xrpi) << endl;
  35:       SoftDelete(*xrpi);
  36:       xrpi = this->erase(xrpi);
  37:       uReaped++;
  38:     } else {
  39:       if ((*xrpi)->GetExpire()<io_tmrNextExpire) 
  40:         io_tmrNextExpire = (*xrpi)->GetExpire();
  41:       lh << LY_EXTRA_DEBUG << "expire leaving " << *(*xrpi) << endl; lh();
  42:       xrpi++;
  43:     }
  44:   }
  45:   return uReaped;
  46: }
  47: 
  48: 
  49: /***********************
  50: *                      *
  51: *  METHOD GETRANDOMRR  *
  52: *                      *
  53: ***********************/
  54: 
  55: 
  56: template <class H> typename RRTList<H>::iterator RRTList<H>::GetRandomRR() {
  57:   typename RRTList<H>::iterator rrpiOut;
  58:   RandomPtr randomPtr;
  59:   unsigned u;
  60:  
  61:   randomPtr = GetSingleton<Random>();
  62: 
  63:   if (this->size()==0) {
  64:     EX_OUT_OF_RANGE("RRTList<H>::GetRandomRR(): called on empty list");
  65:   }
  66:   randomPtr->Get(u);  
  67:   u %= this->size();
  68:   rrpiOut = this->begin();
  69:   while(u-->0) ++rrpiOut;
  70:   return rrpiOut;
  71: }
  72: 
  73: 
  74: /****************************
  75: *                           *
  76: *  METHOD HASRESOURCEMATCH  *
  77: *                           *
  78: ****************************/
  79: 
  80: 
  81: template <class H> template <class XRP>
  82: bool RRTList<H>::HasResourceMatch(const XRP ci_xrp) const {
  83:   typename RRTList<H>::const_iterator c_xrpi;
  84:   
  85:   for(c_xrpi=this->begin(); c_xrpi!=this->end(); ++c_xrpi) {
  86:     if (MatchType((*c_xrpi)->GetType(),ci_xrp->GetType())==true) {
  87:       if (MatchClass((*c_xrpi)->GetClass(),ci_xrp->GetClass())==true) {
  88:         if ((*c_xrpi)->GetRData()->Compare(*(ci_xrp->GetRData()))==true) {
  89:           return true;
  90:         }
  91:       }
  92:     }
  93:   }
  94:   return false;
  95: }
  96: 
  97: 
  98: /****************************
  99: *                           *
 100: *  METHOD HASQUESTIONMATCH  *
 101: *                           *
 102: ****************************/
 103: 
 104: 
 105: template <class H> inline
 106: bool RRTList<H>::HasQuestionMatch(QuestionConstPtr ci_qnp) const {
 107:   typename RRTList<H>::const_iterator c_xrpi;
 108: 
 109:   for(c_xrpi=this->begin(); c_xrpi!=this->end(); ++c_xrpi) {
 110:     if (MatchType((*c_xrpi)->GetType(),ci_qnp->GetType())==true) {
 111:       if (MatchClass((*c_xrpi)->GetClass(),ci_qnp->GetClass())==true) {
 112:         if (*(*c_xrpi)->GetName() == *ci_qnp->GetName()) {
 113:           return true;
 114:         }
 115:       }
 116:     }
 117:   }
 118:   return false;
 119: }
 120: 
 121: 
 122: /************************
 123: *                       *
 124: *  METHOD HASTYPECLASS  *
 125: *                       *
 126: ************************/
 127: 
 128: 
 129: template <class H> bool RRTList<H>::HasTypeClass(RRType i_ty, RRClass i_cl) const {
 130:   typename RRTList<H>::const_iterator c_xrpi;
 131: 
 132:   for(c_xrpi=this->begin(); c_xrpi!=this->end(); ++c_xrpi) {
 133:     if (MatchType((*c_xrpi)->GetType(),i_ty)==true) {
 134:       if (MatchClass((*c_xrpi)->GetClass(),i_cl)==true) return true;
 135:     }
 136:   }
 137:   return false;
 138: }
 139: 
 140: 
 141: /**************** 
 142: *               *
 143: *  METHOD WALK  *
 144: *               *
 145: ****************/
 146: 
 147: 
 148: template <class H> 
 149: void RRTList<H>::Walk(ostream &io_smr, int i_iDepth) const {
 150:   typename RRTList<H>::const_iterator xrpi;
 151:   int i;
 152:   for (xrpi=this->begin();xrpi!=this->end();++xrpi) {
 153:     for(i=0;i<i_iDepth;++i) io_smr << "  ";
 154:     io_smr << "  (" << *(*xrpi) << ")" << endl;
 155:   }
 156: }
 157: 
 158:         
 159: /**********************
 160: *                     *
 161: *  RRLIST DESTRUCTOR  *
 162: *                     *
 163: **********************/
 164:   
 165:   
 166: template <typename H>
 167: RRTList<H>::~RRTList() {
 168:   typename RRTList<H>::iterator xrpi;
 169:   for(xrpi=this->begin();xrpi!=this->end();++xrpi) {
 170:     SoftDelete(*xrpi);
 171:   }     
 172: }
 173: 
 174: 
 175: /*************************
 176: *                        *
 177: *  FUNCTIONS OPERATOR<<  *
 178: *                        *
 179: *************************/
 180: 
 181: 
 182: template <class T> ostream& operator<<(ostream& io_smr, const RRTList<T> &i_xlr) {
 183:   typename RRTList<T>::const_iterator xrpi;
 184:   if (&i_xlr==NULL) {
 185:     io_smr << "[NULL RRList]" << endl;
 186:     return io_smr;
 187:   }
 188: 
 189:   for(xrpi=i_xlr.begin();xrpi!=i_xlr.end();++xrpi) {
 190:     io_smr << *(*xrpi) << endl;
 191:   }
 192:   return io_smr;
 193: }
 194: 
 195: 
 196: template <class T> ostream& operator<<(ostream& io_smr, const RRTList<T> *i_xlp) {
 197:   io_smr << *i_xlp;
 198: }
 199: 
 200: 
 201: 
 202: