Just adding the following incase someone else might be looking for it aswell:
(note, some of it might go unused or so, feel free to let me know! :))
in .h:
typedef std::map<std::string,double> lawVariables;
typedef std::map<std::string,double>::iterator lawVars;
struct ObjectCustomData {
std::string objectType;
bool global_lock;
std::map<std::string, lawVariables> lawData;
};
template <typename K, typename V, class C, class A>
std::ostream &operator<< (std::ostream &os, std::map<K,V,C,A> const& m)
{
os << "{ ";
typename std::map<K,V,C,A>::const_iterator p;
for (p = m.begin(); p != m.end(); ++p) {
os << p->first << ":" << p->second << ", ";
}
return os << "}";
}
Note: the template stuff is so you can simply cout an entire map-in-map.
void setCustomData();
void showCustomData();
bool checkLaw(std::string law);
bool checkVar(std::string law,std::string var);
double getLawVar(std::string law, std::string var);
template<class T,class A>
void showMap(const std::map<T, A>& v);
ObjectCustomData ocd;
note: The setCustomData will just fills the map-in-map with some random data for testing purpose, showCustomData just uses the template and custom operator to show the entire map.
checkLaw and checkVar make sure a certain value even exists and getLawVar returns the value of a certain val of a certain law. showMap shows the entire content of the map-in-map with a somewhat nicer output.
in the .cpp:
Ill skip the setCustomData, it's just a bunch of ocd.lawData[law][var] = 123.45;
void showCustomData() {
std::cout <<ocd.lawData<<std::endl;
}
bool checkLaw(std::string law){
if ((int)ocd.lawData[law].size() != 0) {
return true;
}
else {
return false;
}
}
bool checkVar(std::string law, std::string var){
lawVars lVars = ocd.lawData[law].find(var);
if(lVars != ocd.lawData[law].end()){
return true;
}
else {
return false;
}
}
double getLawVar(std::string law, std::string var){
if (checkLaw(law) && checkVar(law, var)){
return ocd.lawData[law].find(var)->second;
}
else {return 0.0;}
}
template<class T, class A>
void showMap(const std::map<T, A>& v) {
for (std::map<T, A>::const_iterator ci = v.begin(); ci != v.end(); ++ci) {
std::cout << ci->first <<" -> ";
lawVariables tmpLaw = ci->second;
lawVars lVars;
for (lVars = tmpLaw.begin(); lVars != tmpLaw.end(); lVars++){
std::cout << lVars->first << " : " << lVars->second <<"\t";
}
std::cout<<std::endl;
}
std::cout<<std::endl;
}
Hope this is atleast somewhat usefull for someone, feel free to comment on stuff I could/should do better.