//A class that has an initialization lock so that when the lock is activated, any further gets that are missing items in it will report themselves for easier debugging detection.
template<typenameT,typenameO>
classsafemap{
std::map<T,O>map;
boolinitialized=false;
public:
O&operator[](Tkey){
if(initialized&&map.count(key)==0){
std::cout<<"WARNING! Trying to get non-existent key "<<key<<"!"<<std::endl;
std::cout<<"WARNING! A previously set value has been overwritten! Key: "<<key<<std::endl;
throw;
}
returnval;
}else{
returnmap[key];
}
}
O&at(Tkey){
returnmap.at(key);
}
size_tcount(Tkey){
returnmap.count(key);
}
voidSetInitialized(){
initialized=true;
}
size_tsize(){
returnmap.size();
}
//Clears the entire map and unlocks the map so items can be added to it again.
voidReset(){
initialized=false;
map.clear();
}
autobegin()const{
returnmap.begin();
}
autoend()const{
returnmap.end();
}
};
//A class that has an initialization lock so that when the lock is activated, any further gets that are missing items in it will report themselves for easier debugging detection.
//This unordered map should return items inserted in order. Therefore internally, it's hosted as a vector. As such, if an item is added to this map it's possible the refernce becomes stale when another item is added due to a vector expanding. BEWARE!