/****************************************************************************************************

		MCFileType.h
		Copyright: (c) 2001 Eovia Corp. All rights reserved.

		MOVED FROM MCCore\Include

		Author:	Arnaud
		Date:	10/1/2003

****************************************************************************************************/

#ifndef __MCFileType__
#define __MCFileType__

#if CP_PRAGMA_ONCE
#pragma once
#endif


#include "MCArray.h"
#include "MCBasicTypes.h"
#include "MCClassArray.h"
#include "MCFileTypeFamily.h"
#include "MCString.h"
#include "IMCFile.h"


class TMCFile;
class TMCResourceStream;

#define kAnyFile '****'
#define kNullFileType IDTYPE(0,0,0,0)


/// \addtogroup MCCore
/// \{

/// TMCFileType stores some information about a particular kind of files that the application knows (like "Html files").
/// That info consists of an ID, name, and a list of extensions and platform (macos9) types.
///
/// \note When savind a file, the application uses the first extension of the list.
///
/// \see IShFileFormatUtilities has some convenient methods related to file types.
///
class TMCFileType : public TMCObject
{
public:
	TMCFileType();
	TMCFileType(const MCFileTypeID& typeID, MCTypeFamilyID	familyTypeID);

	//Get and Set the id for MCFileType									
	MCFileTypeID		GetID				() const					{ return fID; }
	void				SetID				(const MCFileTypeID& id)	{ fID= id; }

	//Get and sets the name	of the type
	void				GetName				(TMCString& name) const		{ name= fName; }
	const TMCString&	GetName				(void) const				{ return fName; }
	void				SetName				(const TMCString& name)		{ fName= name; }// 31 characters max

	
	/// Adds a type to the file type
	///
	void				AddType				(const TMCFileID& inType);

	/// Adds an extension to the file type
	///
	void				AddExtension		(const TMCString& inExtension);

	/// Tells us if a given extension is contained in the the TMCFileType
	///
	boolean				ContainsExt			(const TMCString& extension) const;

	/// Tells us if a given TMCFileID is contained in the the TMCFileType
	///
	boolean				ContainsType		(const TMCFileID& type) const;

	/// Tells us if a given extension or TMCFileID is contained in the the TMCFileType
	///
	boolean				Contains			(const TMCString& extension, const TMCFileID& type) const;

	/// Gets the filetype family of a filetype
	///
	MCTypeFamilyID		GetFileTypeFamilyID	() const					{ return fFileTypeFamilyID; }
	
	/// Sets the filetype family of a filetype
	///
	void				SetFileTypeFamilyID	(MCTypeFamilyID fileTypeFamilyID) {fFileTypeFamilyID = fileTypeFamilyID;}

	int32				GetExtensionsCount	() const					{ return fExtensions.GetElemCount(); }
	const TMCString&	GetExtension		(int32 index) const			{ return fExtensions[index]; }

	int32				GetTypesCount		() const					{ return fTypes.GetElemCount(); }
	const TMCFileID&	GetType				(int32 index) const			{ return fTypes[index]; }

protected:  
	MCFileTypeID	fID;							///< The identifier of the file type (unique for the application)
	TMCString31		fName;							///< The name of the file type (eg "QuickTime Movie").
	MCTypeFamilyID	fFileTypeFamilyID;				///< eg 2dfiles, 3d files, movies...

	TMCClassArray<TMCDynamicString> fExtensions;	///< The list of extensions generally used by such files (eg .html, .htm)
	TMCArray<TMCFileID>				fTypes;			///< The platform specific (macos9) types of such files (eg 'TEXT')
};

/// \}

//TMCFileType IO (you shouldn't need that in extensions)
TMCResourceStream& operator >> (TMCResourceStream& stream, TMCFileType&				fileType);
TMCResourceStream& operator << (TMCResourceStream& stream, const TMCFileType&		fileType);


/// \addtogroup MCCore
/// \{

/// TMCFileTypeList is simply an array of TMCFileType(s) with a few convenient methods. <BR>
/// To load a file type list from resources use IShFileFormatUtilities::LoadResourceFTYP. <BR>
/// To manipulate the global file type list kept by the application use IShFileFormatUtilities::AddFileTypes, 
/// IShFileFormatUtilities::GetFileTypesByFamilyID or IShFileFormatUtilities::GetFileTypeByID.
///
class TMCFileTypeList : public TMCObject
{ 
public:
	TMCFileTypeList();

	//the familyID is not stored in the resource (so far)
	void ReadFromResource(TMCResourceStream& ss, MCTypeFamilyID familyID);

	inline int32				GetElemCount() const					{ return fList.GetElemCount(); }
	inline const TMCFileType&	GetElem(int32 index) const				{ return fList[index]; }
	inline TMCFileType&			GetElem(int32 index)					{ return fList[index]; }
	void						AddElem(const TMCFileType& fileType);
	void						ArrayFree()								{ fList.ArrayFree(); }

	/// Get the MCFileType using an id
	///
	const TMCFileType*	FindMCFileTypeByID	(const MCFileTypeID& ref) const;

	/// Gets the MCFileType of a file
	///
	const TMCFileType*	FindMCFileType		(const TMCFile& file) const;

	/// Get the TMCFileType  that corresponds to an extension or type.
	///
	const TMCFileType*	FindMCFileType		(const TMCString& extension, const TMCFileID& type) const;

	/// Gets the MCFileTypeID of a file
	///
	MCFileTypeID		FindMCFileTypeID	(const TMCFile& file) const;

	boolean				IsSingleFileFamily	() const;
protected:
	TMCClassArray<TMCFileType>	fList;
};

/// \}


//TMCFileTypeList write (you shouldn't need that in extensions)
TMCResourceStream& operator << (TMCResourceStream& stream, const TMCFileTypeList& typeList);

#endif
