/***************************************************************************
    FPGA Brook Source Code
    Copyright (C) by Frank Franjo Plavec 2006-2012

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 1, or (at your option)
    any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

    The full text of the GNU General Public License in the file named
    LICENSE.cTool.
*****************************************************************************/

#include "streaminfo.h"

// Default constructor
StreamInfo::StreamInfo () {
	this->stream = NULL;
	this->dims = 0;
	this->num_readers = 0;
	this->size = NULL;
	this->out = false;
	this->reduce = false;
}


StreamInfo::StreamInfo (Decl *stream, unsigned int dimensions, bool out, bool reduce) {
	this->stream = stream;
	this->dims = dimensions;
	this->num_readers = 0;
	this->size = new Expression*[dimensions];
	this->out = out;
	this->reduce = reduce;
}

StreamInfo::StreamInfo (Decl *stream, unsigned int dimensions, unsigned int readers, bool out, bool reduce) {
	this->stream = stream;
	this->dims = dimensions;
	this->num_readers = readers;
	this->size = new Expression*[dimensions];
	this->out = out;
	this->reduce = reduce;
}


// Copy-constructor
StreamInfo::StreamInfo (const StreamInfo &param) {
	stream = param.stream;
	dims = param.dims;
	num_readers = param.num_readers;
	size = new Expression*[param.dims];
	// Copy all the pointers
	for (unsigned int i=0; i<param.dims; i++)
		size[i] = param.size[i];
	out = param.out;
	reduce = param.reduce;
}

StreamInfo& StreamInfo::operator=(const StreamInfo &right) {
	if (this != &right) {
		delete [] size;
		stream = right.stream;
		dims = right.dims;
		num_readers = right.num_readers;
		size = new Expression*[right.dims];
		for (unsigned int i=0; i<right.dims; i++)
			size[i] = right.size[i];
		out = right.out;
		reduce = right.reduce;
	}
	return *this;
}
unsigned int StreamInfo::dimensions () {
	return dims;
}

unsigned int StreamInfo::readers () {
	return num_readers;
}

unsigned int StreamInfo::incrementReaders () {
	num_readers++;
	return num_readers;
}


bool StreamInfo::isOut () {
	return out;
}


bool StreamInfo::isReduce () {
	return reduce;
}

Expression* StreamInfo::getSize (unsigned int dimension) {
	if (dimension < dims)
		return size[dimension];
	else
		return NULL;
}

bool StreamInfo::setSize (unsigned int dimension, Expression *size) {
	if (dimension < dims) {
		this->size[dimension] = size;
		return true;
	} else {
		return false;
	}
}
StreamInfo::~StreamInfo () {
	if (size != NULL)
		delete [] size;
}

