/*
 * $Id: iomanager.h 4270 2016-11-06 11:02:47Z antonin.misek-skoda-auto.cz $
 *
 * Description  : One line description of file.
 * Author       : Vaclav Kyba <mail/Jabber: vaseo1@gmail.com>  <ICQ: 98576293>
 *
 * Purpose      :
 *     Long description of what the file is for.
 */


#ifndef __IOMANAGER__H__
#define __IOMANAGER__H__

#include "serverbase.h"
#include "iomodule.h"


namespace VRUT
{
	///Server managing import/export modules
	class IOManager : public ServerBase<IOModule>
	{
	protected:
		//cache for extensions
		std::vector<wxString> extensionsCache;
		///Search for available module with support for given extension
		///\return Loaded module if found, NULL otherwise
		IOModule * findModule(const wxString & extension);
		///check if the given extension is in extensions list
		bool extensionIsInList(const wxString &ext, const wxString &extList);
		///Query module for file format support
		///\param[in] modulehandleID Module handle ID
		///\param[in] ext Format file extension
		///\return \c module pointer if file format is supported
		IOModule * moduleSupportsExt(MODULE_HANDLE_ID modulehandleID, const wxString &ext);

	public:
		///Class constructor
		IOManager();
		///Class destructor
		virtual ~IOManager();

		///Try to load scene from file using module
		SCENE_ID ImportScene(const wxString & fname, SCENE_ID sceneID=SCENE_ID_NONE, NODE_ID parentID=NODE_ID_NONE);

		///Try to save scene to file using module
		void ExportScene(smart_pointer_v2<Scene> &scene, const NODE_ID rootID, const wxString &fname);

		///Return list of supported extensions (currently only extensionsCache is used)
		wxString GetFileSelector(bool addDefaultWildcard = true);

		//Run module but only when it not already exists (it is the difference from other managers)
		virtual MODULE_ID RunModule(const wxString & moduleName, bool reportError);
	};
}

#endif
