Make various instance stuff to take references to other instance objs
[lsnes.git] / src / core / command.cpp
blob227fc9e74926f05640f1154d47cecd20391e961c
1 #include "core/command.hpp"
2 #include "core/keymapper.hpp"
3 #include "library/command.hpp"
4 #include "library/keyboard-mapper.hpp"
5 #include "library/globalwrap.hpp"
6 #include "library/threads.hpp"
7 #include "core/misc.hpp"
8 #include "core/window.hpp"
10 #include <set>
11 #include <map>
13 command::set lsnes_cmds;
15 namespace
17 threads::rlock* global_lock;
18 threads::rlock& get_invbind_lock()
20 if(!global_lock) global_lock = new threads::rlock;
21 return *global_lock;
23 std::map<std::string, keyboard::invbind*> alias_binds;
26 alias_binds_manager::alias_binds_manager(keyboard::mapper& _mapper, command::group& _command)
27 : mapper(_mapper), command(_command)
31 alias_binds_manager::~alias_binds_manager()
33 for(auto i : alias_binds) delete i.second;
34 alias_binds.clear();
37 void alias_binds_manager::operator()()
39 threads::arlock h(get_invbind_lock());
40 auto a = command.get_aliases();
41 for(auto i : alias_binds) {
42 if(!a.count(i.first)) {
43 delete i.second;
44 alias_binds[i.first] = NULL;
47 for(auto i : a) {
48 if(i == "" || i[0] == '-')
49 continue;
50 if(!alias_binds.count(i) || alias_binds[i] == NULL)
51 alias_binds[i] = new keyboard::invbind(mapper, i, "Aliasā€£" + i);