//----------------------------------------------------------------------------
//
// File:        tms9918a.cpp
// Date:        28-Sep-2011
// Programmer:  Marc Rousseau
//
// Description:
//
// Copyright (c) 2011 Marc Rousseau, All Rights Reserved.
//
// 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.
//
// Revision History:
//
//----------------------------------------------------------------------------

#include <stdio.h>
#include "common.hpp"
#include "logger.hpp"
#include "stateobject.hpp"

DBG_REGISTER( __FILE__ );

cStateObject::cStateObject( ) :
	cBaseObject( "cStateObject" )
{
}

//----------------------------------------------------------------------------
// iBaseObject Methods
//----------------------------------------------------------------------------

const void *cStateObject::GetInterface( const std::string &iName ) const
{
	FUNCTION_ENTRY( this, "cStateObject::GetInterface", false );

	if( iName == "iStateObject" )
	{
		return static_cast< const iStateObject * >( this );
	}

	return cBaseObject::GetInterface( iName );
}

bool cStateObject::SaveState( FILE *file, const std::vector<std::pair<void*,size_t> > &data )
{
	FUNCTION_ENTRY( nullptr, "cStateObject::SaveState", true );

	for( auto item : data )
	{
		if( fwrite( item.first, item.second, 1, file ) != 1 )
		{
			DBG_ERROR( "Error saving image to file" );
			return false;
		}
	}

	return true;
}

bool cStateObject::LoadState( FILE *file, const std::vector<std::pair<void*,size_t> > &data )
{
	FUNCTION_ENTRY( nullptr, "cStateObject::LoadState", true );

	for( auto item : data )
	{
		if( fread( item.first, item.second, 1, file ) != 1 )
		{
			DBG_ERROR( "Error loading image from file" );
			return false;
		}
	}

	return true;
}
