The open source repository for the action RPG game in development by Sig Productions titled 'Adventures in Lestoria'! https://forums.lestoria.net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
AdventuresInLestoria/Crawler/safemap.h

37 lines
858 B

#pragma once
#include "olcPixelGameEngine.h"
//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<typename T,typename O>
class safemap{
std::map<T,O>map;
bool initialized=false;
public:
O&operator[](T key){
if(initialized&&map.count(key)==0){
std::cout<<"WARNING! Trying to get non-existent key "<<key<<"!"<<std::endl;
throw;
}
return map[key];
}
size_t count(T key){
return map.count(key);
}
void SetInitialized(){
initialized=true;
}
size_t size(){
return map.size();
}
//Clears the entire map and unlocks the map so items can be added to it again.
void Reset(){
initialized=false;
map.clear();
}
auto begin()const{
return map.begin();
}
auto end()const{
return map.end();
}
};