1 #ifndef _instance_map__hpp__included__
2 #define _instance_map__hpp__included__
6 class emulator_instance
;
8 template<typename T
> class instance_map
12 * Destroy a instance map.
16 for(auto i
: instances
)
21 * Does this instance exist?
23 bool exists(emulator_instance
& inst
)
25 return instances
.count(&inst
);
28 * Lookup a instance. Returns NULL if none.
30 T
* lookup(emulator_instance
& inst
)
32 if(!instances
.count(&inst
))
34 return instances
[&inst
];
37 * Create a new instance.
39 template<typename
... U
> T
* create(emulator_instance
& inst
, U
... args
)
43 out
= new T(inst
, args
...);
44 instances
[&inst
] = out
;
54 void destroy(emulator_instance
& inst
)
56 if(instances
.count(&inst
)) {
57 delete instances
[&inst
];
58 instances
.erase(&inst
);
64 void remove(emulator_instance
& inst
)
66 if(instances
.count(&inst
)) {
67 instances
.erase(&inst
);
71 std::map
<emulator_instance
*, T
*> instances
;