/** @file assetstreamfilehandler.h
*	Asset stream implementation of IFileHandler
*	@author Chris Burns (cburns@ea.com)
*
*	UX
*	(c) 2011 Electronic Arts Inc.
*/

#ifndef EABASETYPESASSETSTREAM_ASSETSTREAMFILEHANDLER_H_
#define EABASETYPESASSETSTREAM_ASSETSTREAMFILEHANDLER_H_

#include "EASTLICA/vector.h"

#include "EABaseTypes/string.h"

#include "EABaseTypesPlus/ifilehandler.h"
#include "EABaseTypesPlus/vrefcountedica.h"

namespace AssetStream
{
	class RawAsset;
}

namespace EA
{
	namespace Types
	{
		class Factory;

		/*! @class	AssetStreamFileHandler assetstreamfilehandler.h	"ux_base/assetstreamfilehandler.h"
		*	@brief	AssetStream implementation of IFileHandler. Loads RawAssets wrapped up as IFileResources.
		*/
		class AssetStreamFileHandler : public VRefCountedICA<IFileHandler>
		{
		public:

			AssetStreamFileHandler(EA::Allocator::ICoreAllocator *allocator, const char* root);

			virtual bool Exists(EA::Allocator::ICoreAllocator* allocator, const char* fileName);

			virtual EA::Types::IFileResourceReturn Load(EA::Allocator::ICoreAllocator* allocator, const char* fileName);
		
			virtual void Load(EA::Types::IFileHandlerCallbackIn callback, EA::Allocator::ICoreAllocator *allocator, const char* fileName);

			virtual void Update();

		private:
			//no copy and no assignment
			AssetStreamFileHandler(const AssetStreamFileHandler& assetStreamFileHandler);
			AssetStreamFileHandler& operator=(const AssetStreamFileHandler& rhs);

			struct AssetData
			{
				EA::Types::IFileHandlerCallbackRef			mCallback;
				EA::Allocator::ICoreAllocator*	mAllocator;
				AssetStream::RawAsset*			mAsset;
//FIFASTART - dstreat - May 9, 2014 - Implement Constructors and Destructors to handle refs properly
				AssetData();
				AssetData(const AssetData& other);
				~AssetData();

				AssetData& operator= (const AssetData& other);
//FIFAEND
			};

			typedef EASTLICA::Vector<AssetData> AssetVector;

			AssetVector		mAssets;
			EA::RawString	mRoot;
		};
	}
}

#endif /* EABASETYPESASSETSTREAM_ASSETSTREAMFILEHANDLER_H_ */
