mql5/Include/MasterOfPuppetsLib/Actions.mqh
MasterOfPuppets 16c0b70dfc use const
2026-03-06 12:04:18 +03:00

80 lines
2.5 KiB
MQL5

//+------------------------------------------------------------------+
//| Actions.mqh |
//| Copyright 2026, MasterOfPuppets |
//| https://forge.mql5.io/masterofpuppets/mql5 |
//+------------------------------------------------------------------+
#ifndef MASTER_OF_PUPPETS_LIB_ACTIONS_MQH
#define MASTER_OF_PUPPETS_LIB_ACTIONS_MQH
#include <Generic\HashMap.mqh>
#property copyright "Copyright 2026, MasterOfPuppets"
#property link "https://forge.mql5.io/masterofpuppets/mql5"
//+------------------------------------------------------------------+
//| Actions class |
//+------------------------------------------------------------------+
template<typename TAction>
class Actions
{
private:
CHashMap<long, int> m_actions;
int m_actionKeys[];
string m_actionNames[];
CHashMap<int, string> m_actionNamesMap;
public:
void AddAction(const ActionKey actionKey, const TAction action, const string actionName)
{
m_actions.Add(actionKey, action);
ArrayResize(m_actionKeys, m_actionKeys.Size() + 1);
m_actionKeys[m_actionKeys.Size() - 1] = actionKey;
ArrayResize(m_actionNames, m_actionNames.Size() + 1);
m_actionNames[m_actionNames.Size() - 1] = actionName;
m_actionNamesMap.Add(action, actionName);
}
void Clear()
{
m_actions.Clear();
ArrayFree(m_actionKeys);
ArrayFree(m_actionNames);
m_actionNamesMap.Clear();
}
const int GetAction(const long actionKey)
{
int action;
m_actions.TryGetValue(actionKey, action);
return action;
}
const string GetActionName(const TAction action)
{
string actionName;
m_actionNamesMap.TryGetValue(action, actionName);
return actionName;
}
void GetActionKeys(int &actionKeys[]) const
{
ArrayCopy(actionKeys, m_actionKeys);
}
void GetActionNames(string &actionNames[]) const
{
ArrayCopy(actionNames, m_actionNames);
}
const string Usage() const
{
string usage;
for(uint i = 0; i < m_actionKeys.Size(); i++)
{
usage += StringFormat("[%c] %s\n", m_actionKeys[i], m_actionNames[i]);
}
return usage;
}
};
#endif
//+------------------------------------------------------------------+