/*
 * (c) 2005 Research Group Dr. Fuhrmann, University of Karlsruhe, Germany
 * All rights reserved.
 *
 * Author:
 *         Stefan Denk <denk@ira.uka.de>
 *         Kendy Kutzner <kutzner@ira.uka.de>
 *
 * $Id: aggr_dest.cc,v 1.4 2006/01/05 10:31:44 denk Exp $
 *
 */

#include <sstream>
using namespace std;
#include "aggr_dest.h"

/**
 * Compare two aggregation destinations.
 * First property to compare is time.
 * If time is equal, destinations are compared according to channel
 */
bool
aggr_dest::operator<(const aggr_dest &other) const {
	if (_minute!=other._minute)
		return _minute < other._minute;
	return _channel < other._channel;
}

/**
 * Construct an aggregation destination from starting time and channel.
 * In this case the channel is a VDR-internal cChannel object
 */
aggr_dest::aggr_dest(time_t start, const cChannel * channel)
	: _minute(start)
	, _channel(channel) {
}

string
aggr_dest::tostring() const{
	stringstream s;
	s << _minute;
	s << " ";
	s << _channel.name(); // this may contain further spaces
	return s.str();
}

bool
aggr_dest::fromstring(string * s){
	_minute = 0;
	_channel.clear();
	// std::string::const_iterator pos;
	int pos;
	pos = s->find(' ');
	if (pos == -1)
	{
		return false;
	}
	_minute = atoi(s->substr(0, pos).c_str());
	s->erase(0, pos+1);
	_channel.set(*s); ///XXX This will also accept unknown channels; these are later rejected when cChan * is built -> NULL pointer
	return true;
}

