#include <iostream>
#include <map>
#include <functional>
using namespace std;

enum MessageType { MSG_NONE = -1, MSG_TYPE_START_PROCESS, MSG_TYPE_END_PROCESS };

typedef std::map<MessageType, std::function<void()>> MessageFuncMap;

void startProcess()
{
	cout << "start process" << endl;
}

void endProcess()
{
	cout << "end process" << endl;
}

void defaultOutput(MessageType msgType)
{
	cout << "unknown message type: " << (int)msgType << endl;
}

void callFunc(MessageFuncMap msgFunc, MessageType msgType, std::function<void(MessageType)> defaultFunc = nullptr)
{
	auto it = msgFunc.find(msgType);
	if (it != msgFunc.end())
		(it->second)();
	else
	  if (defaultFunc != nullptr)
	    defaultFunc(msgType);
}

void callMessageFunc(MessageFuncMap msgFunc, MessageType msgType)
{
	callFunc(msgFunc, msgType, defaultOutput);
}

int main() {
MessageFuncMap msgFunc;

msgFunc[MSG_TYPE_START_PROCESS] = startProcess;
msgFunc[MSG_TYPE_END_PROCESS] = endProcess;

callMessageFunc(msgFunc, MSG_TYPE_START_PROCESS);
callMessageFunc(msgFunc, MSG_TYPE_END_PROCESS);
callMessageFunc(msgFunc, MSG_NONE);

	return 0;
}
