/*****************************************************************************************************
* sharplite: ado.net style (native)c++ wrapper for sqlite database                                   *
* copyright (c) 2006 ademirtug                                                                       *
*                                                                                                    *
* 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 2 of the   *
* License, 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 library; if not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
*                                                                                                    *
******************************************************************************************************/


#include <RowCollection.h>
#include <Sharption.h>

void RowCollection::Attach(ColumnCollection* columns)
{
	cols = columns;
}

void RowCollection::Add(Row* row)
{
	if( row->owned )
		;

	if( !(cols == row->cols) )
		throw Sharption("The row is not suitable for this table");

	row->owned = true;
	row->order = rows.size();
	rows.push_back(row);
}

unsigned int RowCollection::Count()
{
	return rows.size();
}

Row& RowCollection::operator[](unsigned int index)
{
	if( index > rows.size() )
		throw Sharption("Index out of range");
	return *rows[index];
}

RowCollection::~RowCollection()
{
	if( rows.size() )
		for(unsigned int i = 0; i < rows.size(); ++i)
			delete rows[i];
}
