#include "wwwi/random.h"
using std::out_of_range;
using WWWI::GetSingleton;
using WWWI::Random;
using WWWI::RandomPtr;
template <class H> unsigned RRTList<H>::Expire(time_t i_tmNow, time_t &io_tmrNextExpire) {
typename RRTList<H>::iterator xrpi;
unsigned uReaped = 0;
LogHandle lh(LF_CEXPIRE,LY_DEBUG);
xrpi = this->begin();
while(xrpi!=this->end()) {
if ((*xrpi)->IsExpired(i_tmNow)==true) {
lh << "expire reaping " << *(*xrpi) << endl;
SoftDelete(*xrpi);
xrpi = this->erase(xrpi);
uReaped++;
} else {
if ((*xrpi)->GetExpire()<io_tmrNextExpire)
io_tmrNextExpire = (*xrpi)->GetExpire();
lh << LY_EXTRA_DEBUG << "expire leaving " << *(*xrpi) << endl; lh();
xrpi++;
}
}
return uReaped;
}
template <class H> typename RRTList<H>::iterator RRTList<H>::GetRandomRR() {
typename RRTList<H>::iterator rrpiOut;
RandomPtr randomPtr;
unsigned u;
randomPtr = GetSingleton<Random>();
if (this->size()==0) {
EX_OUT_OF_RANGE("RRTList<H>::GetRandomRR(): called on empty list");
}
randomPtr->Get(u);
u %= this->size();
rrpiOut = this->begin();
while(u-->0) ++rrpiOut;
return rrpiOut;
}
template <class H> template <class XRP>
bool RRTList<H>::HasResourceMatch(const XRP ci_xrp) const {
typename RRTList<H>::const_iterator c_xrpi;
for(c_xrpi=this->begin(); c_xrpi!=this->end(); ++c_xrpi) {
if (MatchType((*c_xrpi)->GetType(),ci_xrp->GetType())==true) {
if (MatchClass((*c_xrpi)->GetClass(),ci_xrp->GetClass())==true) {
if ((*c_xrpi)->GetRData()->Compare(*(ci_xrp->GetRData()))==true) {
return true;
}
}
}
}
return false;
}
template <class H> inline
bool RRTList<H>::HasQuestionMatch(QuestionConstPtr ci_qnp) const {
typename RRTList<H>::const_iterator c_xrpi;
for(c_xrpi=this->begin(); c_xrpi!=this->end(); ++c_xrpi) {
if (MatchType((*c_xrpi)->GetType(),ci_qnp->GetType())==true) {
if (MatchClass((*c_xrpi)->GetClass(),ci_qnp->GetClass())==true) {
if (*(*c_xrpi)->GetName() == *ci_qnp->GetName()) {
return true;
}
}
}
}
return false;
}
template <class H> bool RRTList<H>::HasTypeClass(RRType i_ty, RRClass i_cl) const {
typename RRTList<H>::const_iterator c_xrpi;
for(c_xrpi=this->begin(); c_xrpi!=this->end(); ++c_xrpi) {
if (MatchType((*c_xrpi)->GetType(),i_ty)==true) {
if (MatchClass((*c_xrpi)->GetClass(),i_cl)==true) return true;
}
}
return false;
}
template <class H>
void RRTList<H>::Walk(ostream &io_smr, int i_iDepth) const {
typename RRTList<H>::const_iterator xrpi;
int i;
for (xrpi=this->begin();xrpi!=this->end();++xrpi) {
for(i=0;i<i_iDepth;++i) io_smr << " ";
io_smr << " (" << *(*xrpi) << ")" << endl;
}
}
template <typename H>
RRTList<H>::~RRTList() {
typename RRTList<H>::iterator xrpi;
for(xrpi=this->begin();xrpi!=this->end();++xrpi) {
SoftDelete(*xrpi);
}
}
template <class T> ostream& operator<<(ostream& io_smr, const RRTList<T> &i_xlr) {
typename RRTList<T>::const_iterator xrpi;
if (&i_xlr==NULL) {
io_smr << "[NULL RRList]" << endl;
return io_smr;
}
for(xrpi=i_xlr.begin();xrpi!=i_xlr.end();++xrpi) {
io_smr << *(*xrpi) << endl;
}
return io_smr;
}
template <class T> ostream& operator<<(ostream& io_smr, const RRTList<T> *i_xlp) {
io_smr << *i_xlp;
}