// Copyright (C) 2004-2009 Christoph Kubisch & Eike Decker
// This file is part of the "Luxinia Engine".
// For conditions of distribution and use, see copyright notice in luxiniapublicsdk.txt

#include "exmodelout.h"

#include <fstream>

//////////////////////////////////////////////////////////////////////////
// OutPuts

#include "outformats/f3d.h"
#include "outformats/ma.h"

static EXModelOutput*	l_modeloutputs[] = {
	&g_EXOutF3D,
};

static EXAnimOutput*	l_animoutputs[] = {
	&g_EXOutMA,
};

booln	EXModel_toOutBuffer(EXModelPTR imodel, EXModelOutType type, EXOutBufferPTR outbuffer)
{
	if (type < 0 || type >= EXMODEL_OUTS) return FALSE;

	return l_modeloutputs[type]->Export(imodel,outbuffer->oss);
}

booln	EXAnim_toOutBuffer(EXAnimPTR ianim, EXAnimOutType type, EXOutBufferPTR outbuffer)
{
	if (type < 0 || type >= EXANIM_OUTS) return FALSE;

	return l_animoutputs[type]->Export(ianim,outbuffer->oss);
}

booln	EXModel_toFile(EXModelPTR imodel, EXModelOutType type, const char *filename)
{
	if (type < 0 || type >= EXMODEL_OUTS) return FALSE;
	std::ofstream outfile(filename,std::ofstream::binary);
	if (outfile.fail())
		return FALSE;

	booln res = l_modeloutputs[type]->Export(imodel,outfile);

	outfile.close();
	return res;
}

booln	EXAnim_toFile(EXAnimPTR ianim, EXAnimOutType type, const char *filename){
	if (type < 0 || type >= EXANIM_OUTS) return FALSE;
	std::ofstream outfile(filename,std::ofstream::binary);
	if (outfile.fail())
		return FALSE;
	
	booln res = l_animoutputs[type]->Export(ianim,outfile);

	outfile.close();
	return res;
}


//////////////////////////////////////////////////////////////////////////
// EXOutBuffer

EXOutBufferPTR	EXOutBuffer_new()
{
	return new EXOutBuffer();
}

void			EXOutBuffer_delete(EXOutBufferPTR buffer)
{
	delete buffer;
}

size_t			EXOutBuffer_getSize(EXOutBufferPTR buffer){
	return buffer->oss.str().size();
}
const char*		EXOutBuffer_getContent(EXOutBufferPTR buffer){
	return buffer->oss.str().data();
}

std::string		EXOutBuffer_getContentString(EXOutBufferPTR buffer){
	return buffer->oss.str();
}

