/* 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 "runtime/HttpCookies.h"


HttpCookies::HttpCookies(int limit): theRing(limit) {
}

HttpCookies::~HttpCookies() {
	while (count())
		delete theRing.dequeue();
}

void HttpCookies::keepLimit(int limit) {
	if (limit > theRing.capacity())
		theRing.resize(limit);
}

void HttpCookies::add(HttpCookie *cookie) {
	if (theRing.full()) {
		if (!Should(!theRing.empty()))
			return;
		delete theRing.dequeue();
	}
	theRing.enqueue(cookie);
}

int HttpCookies::count() const {
	return theRing.count();
}

const HttpCookie &HttpCookies::get(int idx) const {
	const HttpCookie *cookie = theRing.top(idx);
	Assert(cookie);
	return *cookie;
}


HttpCookie *HttpCookieParse(const char *content, int size) {
	return new HttpCookie(content, size);
}


syntax highlighted by Code2HTML, v. 0.9.1