/* Web Polygraph http://www.web-polygraph.org/
* (C) 2003-2006 The Measurement Factory
* Licensed under the Apache License, Version 2.0 */
#include "base/polygraph.h"
#include "xstd/h/iostream.h"
#include "xstd/h/iomanip.h"
#include "base/OLog.h"
#include "base/ILog.h"
#include "base/ObjId.h"
void ObjId::reset() {
theForeignUrl = String();
theWorld.clear();
theViserv = theType = theName = -1;
theTarget = -1;
theFlags = 0;
}
int ObjId::hash() const {
const int defaultHash = 1000000711;
if (theWorld && theName > 0) {
// theType may not be known yet; moreover it is dirived from hash()
if (const int res = abs(theWorld.hash() + theName))
return res;
} else
if (Should(theForeignUrl)) {
return theForeignUrl.hash();
}
return defaultHash;
}
bool ObjId::direct() const {
return !embedded();
}
bool ObjId::embedded() const {
Assert(theWorld);
return theWorld.mutant();
}
// /*first*/ cachable miss
bool ObjId::fill() const {
return basic() && /* !repeat() &&*/ cachable() && !hit();
}
ostream &ObjId::printFlags(ostream &os) const {
if (repeat())
os << "rpt,";
if (hot())
os << "hot,";
if (foreignSrc())
os << "foreignSrc,";
if (foreignUrl())
os << "foreignUrl,";
if (basic())
os << "basic,";
if (ims200())
os << "ims200,";
if (ims304())
os << "ims304,";
if (reload())
os << "reload,";
if (rediredReq())
os << "rediredReq,";
if (repToRedir())
os << "repToRedir,";
if (aborted())
os << "aborted,";
if (get())
os << "GET,";
else
if (head())
os << "HEAD,";
else
if (post())
os << "POST,";
else
if (put())
os << "PUT,";
else
Assert(false);
if (cachable())
os << "chb,";
if (hit())
os << "hit,";
if (gzipContent())
os << "gzip";
return os;
}
void ObjId::store(OLog &ol) const {
ol << theWorld << theViserv << theName << theType
<< theTarget;
ol.puti((int)theFlags);
}
void ObjId::load(ILog &il) {
il >> theWorld >> theViserv >> theName >> theType
>> theTarget;
theFlags = (unsigned)il.geti();
}
syntax highlighted by Code2HTML, v. 0.9.1