mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-08-14 13:18:36 -05:00
Add helper to get int from variable
This commit is contained in:
@@ -44,4 +44,14 @@ std::optional<double> GetDouble(const std::string &str)
|
||||
return {};
|
||||
}
|
||||
|
||||
std::optional<int> GetInt(const std::string &str)
|
||||
{
|
||||
char *end = nullptr;
|
||||
int value = std::strtol(str.c_str(), &end, 10);
|
||||
if (end != str.c_str() && *end == '\0') {
|
||||
return value;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
} // namespace advss
|
||||
|
||||
@@ -9,5 +9,6 @@ std::variant<double, std::string>
|
||||
EvalMathExpression(const std::string &expression);
|
||||
bool IsValidNumber(const std::string &);
|
||||
std::optional<double> GetDouble(const std::string &);
|
||||
std::optional<int> GetInt(const std::string &);
|
||||
|
||||
} // namespace advss
|
||||
|
||||
@@ -53,6 +53,11 @@ std::optional<double> Variable::DoubleValue() const
|
||||
return GetDouble(_value);
|
||||
}
|
||||
|
||||
std::optional<int> Variable::IntValue() const
|
||||
{
|
||||
return GetInt(_value);
|
||||
}
|
||||
|
||||
void Variable::SetValue(const std::string &val)
|
||||
{
|
||||
_value = val;
|
||||
|
||||
@@ -20,6 +20,7 @@ public:
|
||||
void Save(obs_data_t *obj) const;
|
||||
std::string Value() const { return _value; }
|
||||
std::optional<double> DoubleValue() const;
|
||||
std::optional<int> IntValue() const;
|
||||
void SetValue(const std::string &val);
|
||||
void SetValue(double);
|
||||
static std::shared_ptr<Item> Create()
|
||||
|
||||
Reference in New Issue
Block a user