// URLContainer.cpp: implementation of the URLContainer class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "URLContainer.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

URLContainer::URLContainer()
{

}

URLContainer::~URLContainer()
{

}

URLContainer::URLContainer(istream &is)
{
	URL next;
	while (is >> next){
		urls.push_back(next);
	}
}

void URLContainer::printFirstN(ostream &os, const int n)
{
	for (int i=0; i < n; i++)
		os << urls[i] << endl;

}

int URLContainer::size()
{
	return urls.size();
}

void URLContainer::printNth(ostream &os, const int n)
{
	os << urls[n] << endl;
}

void URLContainer::sortByURL()
{
	sort(urls.begin(), urls.end());
}

bool sortTitleCriteria(const URL & a, const URL & b)
{
	return a.title < b.title;
}

void URLContainer::sortByTitle()
{
	sort(urls.begin(), urls.end(), sortTitleCriteria);
	//The line below should work, according to the standard, but 
	// it does not compile in VC++ 6.0
//	sort(urls.begin(), urls.end(), mem_fun_ref(&URL::operator<));
};