#pragma once
#include <memory>
#include <functional>

namespace DXFW
{
class IModule
{
	public:
		virtual void Exe() = 0;
};

class PartTimeModule : public IModule
{
	private:
		std::list< std::shared_ptr<IModule> > modules;
		std::function<bool()> judge;
	public:
		PartTimeModule(IModule *module , std::function<bool()> judge) :
			judge(judge)
		{
			this->Add( module );
		}

		void Exe( )
		{
			if( !judge() ) return;
				
			for( auto &it : modules )
			{
				it->Exe();
			}
		};

		void Add( IModule *module )
		{
			this->modules.push_back( std::shared_ptr<IModule>(module) );
		}
};

class FuncModule : public IModule
{
	private:
		std::function<void()> func;
	public:
		FuncModule( std::function<void()> func):
			func(func)
		{}

		void Exe()
		{
			func();
		}
};

}