#ifndef _MODMANAGE_H_
#define _MODMANAGE_H_

#include "../ptr.h"
#include "../tobject.h"

#include "../tk/gui/gui.h"

#include "imodule.h"
#include "varinst.h"
#include "messageclass.h"
#include "moduletype.h"

#include <vector>
#include <string>


/**
 * \brief Head class of modular system.
 *
 * Hold module types (algorithm types), provides methods to access them; also contains methods to send messages.
 * 
 * \date 01-29-2006
 *
 * \author Ondrej Svejdar
 *
 * \todo 
 *
 * \bug 
 *
 */
class ModuleManager:public TObject
{
public:
	typedef vector<Ptr<ModuleType> > t_module_types;
private:
	t_module_types moduleTypes;
	Ptr<TkGui> gui;
public:
	/**
     * \brief Hold reference to self. 
	 *
	 * Currently, there is only one modular manager. Can change in future.
	 */
	static Ptr<ModuleManager> manager;

	typedef t_module_types::const_iterator const_iterator;
	
	/**
	 * \return const_iterator to begining of module type's list
	 */
	const_iterator begin() const;

	/**
	 * \return const_iterator to ending of module type's list
	 */
	const_iterator end() const;

	static const char* type;
	const char* getType() const;

	/**
	 * \brief return reference to gui
	 * \return reference to gui
	 */
	Ptr<TkGui>& getGui()
	{
		return gui;
	}

	/**
	 * \brief ctor
	 * \param types[] module types to array, last element MUST be NULL
	 * \param gui reference to gui
	 */
	ModuleManager(ModuleType* types[],Ptr<TkGui>& gui);
	~ModuleManager();

	/**
	 * \brief return module of given instance name or empty instance
	 * \param instanceName name of instance
	 * \return reference to module instance
	 */
	Ptr<IModule>& getModule(const string& instanceName);

	/**
	 * \brief return module type of given name
	 * \param type name of module type
	 * \return reference to module type
	 */
	Ptr<ModuleType>& getModuleType(const string& type);
	
	/**
	 * \brief send message to all module instances (broadcast)
	 * \param mesg message
	 */
	void sendToAll(TObject* mesg);
};

#endif/*_MODMANAGE_H_*/
