mirror of https://github.com/OpenMW/openmw.git
Move Fallback map to components/
parent
ece40b1e96
commit
6546c05428
@ -1,18 +1,19 @@
|
|||||||
#ifndef GAME_MWWORLD_FALLBACK_H
|
#ifndef OPENMW_COMPONENTS_FALLBACK_H
|
||||||
#define GAME_MWWORLD_FALLBACK_H
|
#define OPENMW_COMPONENTS_FALLBACK_H
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <osg/Vec4f>
|
#include <osg/Vec4f>
|
||||||
|
|
||||||
namespace MWWorld
|
namespace Fallback
|
||||||
{
|
{
|
||||||
class Fallback
|
/// @brief contains settings imported from the Morrowind INI file.
|
||||||
|
class Map
|
||||||
{
|
{
|
||||||
const std::map<std::string,std::string> mFallbackMap;
|
const std::map<std::string,std::string> mFallbackMap;
|
||||||
public:
|
public:
|
||||||
Fallback(const std::map<std::string,std::string>& fallback);
|
Map(const std::map<std::string,std::string>& fallback);
|
||||||
std::string getFallbackString(const std::string& fall) const;
|
std::string getFallbackString(const std::string& fall) const;
|
||||||
float getFallbackFloat(const std::string& fall) const;
|
float getFallbackFloat(const std::string& fall) const;
|
||||||
int getFallbackInt(const std::string& fall) const;
|
int getFallbackInt(const std::string& fall) const;
|
@ -0,0 +1,48 @@
|
|||||||
|
#ifndef OPENMW_COMPONENTS_FALLBACK_VALIDATE_H
|
||||||
|
#define OPENMW_COMPONENTS_FALLBACK_VALIDATE_H
|
||||||
|
|
||||||
|
#include <boost/program_options.hpp>
|
||||||
|
|
||||||
|
// Parses and validates a fallback map from boost program_options.
|
||||||
|
// Note: for boost to pick up the validate function, you need to pull in the namespace e.g.
|
||||||
|
// by using namespace Fallback;
|
||||||
|
|
||||||
|
namespace Fallback
|
||||||
|
{
|
||||||
|
|
||||||
|
struct FallbackMap {
|
||||||
|
std::map<std::string,std::string> mMap;
|
||||||
|
};
|
||||||
|
|
||||||
|
void validate(boost::any &v, std::vector<std::string> const &tokens, FallbackMap*, int)
|
||||||
|
{
|
||||||
|
if(v.empty())
|
||||||
|
{
|
||||||
|
v = boost::any(FallbackMap());
|
||||||
|
}
|
||||||
|
|
||||||
|
FallbackMap *map = boost::any_cast<FallbackMap>(&v);
|
||||||
|
|
||||||
|
for(std::vector<std::string>::const_iterator it=tokens.begin(); it != tokens.end(); ++it)
|
||||||
|
{
|
||||||
|
int sep = it->find(",");
|
||||||
|
if(sep < 1 || sep == (int)it->length()-1)
|
||||||
|
#if (BOOST_VERSION < 104200)
|
||||||
|
throw boost::program_options::validation_error("invalid value");
|
||||||
|
#else
|
||||||
|
throw boost::program_options::validation_error(boost::program_options::validation_error::invalid_option_value);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
std::string key(it->substr(0,sep));
|
||||||
|
std::string value(it->substr(sep+1));
|
||||||
|
|
||||||
|
if(map->mMap.find(key) == map->mMap.end())
|
||||||
|
{
|
||||||
|
map->mMap.insert(std::make_pair (key,value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue