1
0
Fork 0
mql5/Include/MasterOfPuppetsLib/Actions.mqh
MasterOfPuppets b522a21c10 new files added
2026-03-03 01:41:15 +03:00

70 Zeilen
2,2 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\SortedMap.mqh>
#property copyright "Copyright 2026, MasterOfPuppets"
#property link "https://forge.mql5.io/masterofpuppets/mql5"
//+------------------------------------------------------------------+
//| Actions class |
//+------------------------------------------------------------------+
template<typename TActionEnum>
class Actions
{
private:
CHashMap<long, int> m_actions;
int m_actionKeys[];
string m_actionNames[];
public:
void AddAction(const ActionKey actionKey, const TActionEnum action)
{
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] = EnumToString(action);
}
void Clear()
{
m_actions.Clear();
ArrayFree(m_actionKeys);
ArrayFree(m_actionNames);
}
int GetAction(const long actionKey)
{
int action;
m_actions.TryGetValue(actionKey, action);
return action;
}
void GetActionKeys(int &actionKeys[])
{
ArrayCopy(actionKeys, m_actionKeys);
}
void GetActionNames(string &actionNames[])
{
ArrayCopy(actionNames, m_actionNames);
}
string Usage()
{
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
//+------------------------------------------------------------------+