#include "polica.h"
double Polica::ukupnaDebljina() const {
	double debljina = 0;
	for (int i = 0; i < dela.getBrPod(); i++)
		debljina += dela[i]->getDebljina();
	return debljina;
}

Polica& Polica::operator += (Delo* d) {
	if (ukupnaDebljina() + d->getDebljina() > duz)
		throw GDuzina();
	dela += d;
	return *this;
}

PromNiz<Delo *, 1> Polica::delaAutora(const char* autor) {
	PromNiz<Delo *, 1> p(1);
	for (int i = 0; i < dela.getBrPod(); i++) {
		if (strcmp(autor, dela[i]->getAutor()) == 0)
			p += dela[i];
	}
	return p;
}

Delo* Polica::operator () (const int& i) {
	for (int j = 0; j < dela.getBrPod(); j++) {
		if (i == dela[j]->getId())
			return dela(j);
	}
	throw GNemaDela();
}

void Polica::prazni() {
	while (dela.getBrPod())
		dela(0);
}

ostream& operator << (ostream& it, Polica& p) {
	it << "______________________________________";
	it << "______________________________________\n";
	it << "POLICA BR. " << p.rBr;
	it << "     DUZINA: " << p.duz;
	it << "     BRDELA:" << p.dela.getBrPod();
	it << "     DEBLJINA: " << p.ukupnaDebljina() << endl;
	it << "VRS ID  AUTOR\t\t\t NASLOV\t\t\t  DEB\tDUZ" << endl;
	it << p.dela;
	return it;
}
