// CFunctions.cpp: functions to make class available to c calling routines
//
//////////////////////////////////////////////////////////////////////
 /*      
 *          Copyright (C) 2000 RasSimTech Ltd. 
 *
 *  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 program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
 */


#include "DataTransfer.h"
#include "vector"

static std::vector<CDataTransfer*> vpdataTransferClass;	// persistent array to instantiate class

extern "C"
{
	int iInitTransfer(int iID,int iSize);	// returns index of new instance or -1 if error occurs
	void DeleteTransferAll();
	void TransferSetData(int iInstance,int iIndex,double dValue);
	double dTransferGetData(int iInstance,int iIndex);
	void TransferReadData(int iInstance);
	void TransferWriteData(int iInstance);
}


int iInitTransfer(int iID,int iSize)
{
	CDataTransfer* pdataTemp =  new CDataTransfer(iSize,iID);
	vpdataTransferClass.push_back(pdataTemp);
	return(vpdataTransferClass.size()-1);	// return the index of the new transfer class
}

void DeleteTransferAll()
{
	for(std::vector<CDataTransfer*>::iterator itData=vpdataTransferClass.begin();itData!=vpdataTransferClass.end();itData++)
	{
		if((*itData)!=NULL)
		{
			delete *itData;
		}
	}
	vpdataTransferClass.clear();
}

void TransferSetData(int iInstance, int iIndex,double dValue)
{
	if(iInstance < vpdataTransferClass.size())
	{
		vpdataTransferClass[iInstance]->SetData(iIndex,dValue);
	}
}

double dTransferGetData(int iInstance,int iIndex)
{
	if(iInstance < vpdataTransferClass.size())
	{
		return(vpdataTransferClass[iInstance]->dGetData(iIndex));
	}
	else
	{
		return(-1);
	}
}

void TransferReadData(int iInstance)
{
	if(iInstance < vpdataTransferClass.size())
	{
		vpdataTransferClass[iInstance]->ReadData();
	}
}

void TransferWriteData(int iInstance)
{
	if(iInstance < vpdataTransferClass.size())
	{
		vpdataTransferClass[iInstance]->WriteData();
	}
}
