2013-03-15 09:17:30 +00:00
|
|
|
#include "fallback.hpp"
|
2015-04-14 13:55:56 +00:00
|
|
|
|
2017-06-11 07:23:19 +00:00
|
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
|
|
|
|
|
2016-01-06 11:46:06 +00:00
|
|
|
namespace Fallback
|
2013-03-15 09:17:30 +00:00
|
|
|
{
|
2017-05-06 21:05:13 +00:00
|
|
|
bool stob(std::string const& s) {
|
|
|
|
return s != "0";
|
|
|
|
}
|
|
|
|
|
2016-01-06 11:46:06 +00:00
|
|
|
Map::Map(const std::map<std::string,std::string>& fallback):mFallbackMap(fallback)
|
2013-03-15 09:26:04 +00:00
|
|
|
{}
|
|
|
|
|
2016-01-06 11:46:06 +00:00
|
|
|
std::string Map::getFallbackString(const std::string& fall) const
|
2013-03-15 09:17:30 +00:00
|
|
|
{
|
|
|
|
std::map<std::string,std::string>::const_iterator it;
|
|
|
|
if((it = mFallbackMap.find(fall)) == mFallbackMap.end())
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
return it->second;
|
|
|
|
}
|
2017-06-11 07:32:30 +00:00
|
|
|
|
2016-01-06 11:46:06 +00:00
|
|
|
float Map::getFallbackFloat(const std::string& fall) const
|
2013-03-15 09:17:30 +00:00
|
|
|
{
|
|
|
|
std::string fallback=getFallbackString(fall);
|
2018-03-13 20:59:01 +00:00
|
|
|
if (fallback.empty())
|
2013-03-15 09:17:30 +00:00
|
|
|
return 0;
|
2017-06-11 07:32:30 +00:00
|
|
|
else
|
|
|
|
return boost::lexical_cast<float>(fallback);
|
2013-03-15 09:17:30 +00:00
|
|
|
}
|
2017-06-11 07:32:30 +00:00
|
|
|
|
2016-01-06 11:46:06 +00:00
|
|
|
int Map::getFallbackInt(const std::string& fall) const
|
2015-02-09 18:28:29 +00:00
|
|
|
{
|
|
|
|
std::string fallback=getFallbackString(fall);
|
2018-03-13 20:59:01 +00:00
|
|
|
if (fallback.empty())
|
2015-02-09 18:28:29 +00:00
|
|
|
return 0;
|
|
|
|
else
|
2017-05-06 21:05:13 +00:00
|
|
|
return std::stoi(fallback);
|
2015-02-09 18:28:29 +00:00
|
|
|
}
|
|
|
|
|
2016-01-06 11:46:06 +00:00
|
|
|
bool Map::getFallbackBool(const std::string& fall) const
|
2013-03-15 09:17:30 +00:00
|
|
|
{
|
|
|
|
std::string fallback=getFallbackString(fall);
|
2018-03-13 20:59:01 +00:00
|
|
|
if (fallback.empty())
|
2013-03-15 09:17:30 +00:00
|
|
|
return false;
|
|
|
|
else
|
2017-05-06 21:05:13 +00:00
|
|
|
return stob(fallback);
|
2013-03-15 09:17:30 +00:00
|
|
|
}
|
2017-06-11 07:32:30 +00:00
|
|
|
|
2016-01-06 11:46:06 +00:00
|
|
|
osg::Vec4f Map::getFallbackColour(const std::string& fall) const
|
2013-03-15 09:17:30 +00:00
|
|
|
{
|
|
|
|
std::string sum=getFallbackString(fall);
|
2018-03-13 20:59:01 +00:00
|
|
|
if (sum.empty())
|
2018-03-12 16:05:57 +00:00
|
|
|
return osg::Vec4f(0.5f,0.5f,0.5f,1.f);
|
2013-03-15 09:17:30 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
std::string ret[3];
|
|
|
|
unsigned int j=0;
|
2013-03-15 09:26:04 +00:00
|
|
|
for(unsigned int i=0;i<sum.length();++i){
|
2013-03-15 09:17:30 +00:00
|
|
|
if(sum[i]==',') j++;
|
2014-05-28 19:29:09 +00:00
|
|
|
else if (sum[i] != ' ') ret[j]+=sum[i];
|
2013-03-15 09:17:30 +00:00
|
|
|
}
|
2014-05-28 19:29:09 +00:00
|
|
|
|
2017-05-06 21:05:13 +00:00
|
|
|
return osg::Vec4f(std::stoi(ret[0])/255.f,std::stoi(ret[1])/255.f,std::stoi(ret[2])/255.f, 1.f);
|
2013-03-15 09:17:30 +00:00
|
|
|
}
|
|
|
|
}
|
2015-06-16 18:36:48 +00:00
|
|
|
|
2013-03-15 09:17:30 +00:00
|
|
|
}
|