mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-06 00:55:50 +00:00
added typesafe access functions for GMST values
This commit is contained in:
parent
fca3b67507
commit
677158c477
@ -1,8 +1,15 @@
|
||||
#include "loadgmst.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include "defs.hpp"
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
|
||||
/// \todo Review GMST "fixing". Probably remove completely or at least make it optional. Its definitely not
|
||||
/// working properly in its current state and I doubt it can be fixed without breaking other stuff.
|
||||
|
||||
// Some handy macros
|
||||
#define cI(s,x) { if(id == (s)) return (i == (x)); }
|
||||
#define cF(s,x) { if(id == (s)) return (f == (x)); }
|
||||
@ -169,4 +176,32 @@ void GameSetting::load(ESMReader &esm)
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
int GameSetting::getInt() const
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case VT_Float: return static_cast<int> (f);
|
||||
case VT_Int: return i;
|
||||
default: throw std::runtime_error ("GMST " + id + " is not of a numeric type");
|
||||
}
|
||||
}
|
||||
|
||||
int GameSetting::getFloat() const
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case VT_Float: return f;
|
||||
case VT_Int: return i;
|
||||
default: throw std::runtime_error ("GMST " + id + " is not of a numeric type");
|
||||
}
|
||||
}
|
||||
|
||||
std::string GameSetting::getString() const
|
||||
{
|
||||
if (type==VT_String)
|
||||
return str;
|
||||
|
||||
throw std::runtime_error ("GMST " + id + " is not a string");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -83,6 +83,15 @@ struct GameSetting
|
||||
bool isDirtyBloodmoon();
|
||||
|
||||
void load(ESMReader &esm);
|
||||
|
||||
int getInt() const;
|
||||
///< Throws an exception if GMST is not of type int or float.
|
||||
|
||||
int getFloat() const;
|
||||
///< Throws an exception if GMST is not of type int or float.
|
||||
|
||||
std::string getString() const;
|
||||
///< Throwns an exception if GMST is not of type string.
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user