mql5/Include/MasterOfPuppetsLib/Actions.mqh

80 lines
2.5 KiB
MQL5
Raw Permalink Normal View History

2026-03-03 01:24:43 +03:00
//+------------------------------------------------------------------+
//| Actions.mqh |
//| Copyright 2026, MasterOfPuppets |
//| https://forge.mql5.io/masterofpuppets/mql5 |
//+------------------------------------------------------------------+
2026-03-03 01:41:15 +03:00
#ifndef MASTER_OF_PUPPETS_LIB_ACTIONS_MQH
#define MASTER_OF_PUPPETS_LIB_ACTIONS_MQH
2026-03-03 01:24:43 +03:00
2026-03-05 21:25:56 +03:00
#include <Generic\HashMap.mqh>
2026-03-03 01:24:43 +03:00
#property copyright "Copyright 2026, MasterOfPuppets"
#property link "https://forge.mql5.io/masterofpuppets/mql5"
//+------------------------------------------------------------------+
//| Actions class |
//+------------------------------------------------------------------+
2026-03-05 02:13:29 +03:00
template<typename TAction>
2026-03-03 01:24:43 +03:00
class Actions
{
private:
2026-03-05 23:35:38 +03:00
CHashMap<long, int> m_actions;
int m_actionKeys[];
string m_actionNames[];
CHashMap<int, string> m_actionNamesMap;
2026-03-03 01:24:43 +03:00
public:
2026-03-06 12:04:18 +03:00
void AddAction(const ActionKey actionKey, const TAction action, const string actionName)
2026-03-03 01:24:43 +03:00
{
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);
2026-03-05 23:35:38 +03:00
m_actionNames[m_actionNames.Size() - 1] = actionName;
m_actionNamesMap.Add(action, actionName);
2026-03-03 01:24:43 +03:00
}
void Clear()
{
m_actions.Clear();
ArrayFree(m_actionKeys);
ArrayFree(m_actionNames);
2026-03-06 12:04:18 +03:00
m_actionNamesMap.Clear();
2026-03-03 01:24:43 +03:00
}
2026-03-06 12:04:18 +03:00
const int GetAction(const long actionKey)
2026-03-03 01:24:43 +03:00
{
int action;
m_actions.TryGetValue(actionKey, action);
return action;
}
2026-03-06 12:04:18 +03:00
const string GetActionName(const TAction action)
2026-03-05 23:35:38 +03:00
{
string actionName;
m_actionNamesMap.TryGetValue(action, actionName);
return actionName;
}
2026-03-06 11:42:57 +03:00
void GetActionKeys(int &actionKeys[]) const
2026-03-03 01:24:43 +03:00
{
ArrayCopy(actionKeys, m_actionKeys);
}
2026-03-06 12:04:18 +03:00
void GetActionNames(string &actionNames[]) const
2026-03-03 01:24:43 +03:00
{
ArrayCopy(actionNames, m_actionNames);
}
2026-03-06 12:04:18 +03:00
const string Usage() const
2026-03-03 01:24:43 +03:00
{
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
//+------------------------------------------------------------------+