Ejemplo n.º 1
0
bool Double::set_value(const std::string& value)
{
    bool ok = true;
    format_ = (value.find_first_of('e') != std::string::npos) ? EXPONENT : AUTO;
    value_ = oskar_settings_utility_string_to_double(value, &ok);
    return ok;
}
Ejemplo n.º 2
0
bool DoubleRangeExt::from_string_(Value& value, const std::string& s) const
{
    if (s.empty())
        return false;

    if (s == ext_min_) {
        value = ext_min_;
    }
    else if (s == ext_max_) {
        value = ext_max_;
    }
    else {
        bool ok = true;
        double v = oskar_settings_utility_string_to_double(s, &ok);
        if (!ok) return false;
        if (v < min_ && !ext_min_.empty()) {
            value = ext_min_;
        }
        else if (v > max_ && !ext_max_.empty()) {
            value = ext_max_;
        }
        else {
            if (v >= max_) value = max_;
            else if (v <= min_) value = min_;
            else value = v;
        }
    }
    return true;
}
Ejemplo n.º 3
0
bool Time::from_string_(const std::string& s, Value& value) const
{
    bool ok = true;
    if (s.empty())
    {
        value.clear();
        return false;
    }
    // s.zzzzzzzzz
    else if (s.find(":") == std::string::npos)
    {
        double seconds = oskar_settings_utility_string_to_double(s, &ok);
        value.hours = floor(seconds / 3600.);
        value.minutes = floor((seconds - (value.hours * 3600.)) / 60.);
        value.seconds = seconds - (value.hours * 3600.) - (value.minutes * 60.);
        value.format = SECONDS;
    }
    // hh:mm:ss.zzzzzzzzz
    else
    {
        std::istringstream ss(s);
        std::string token;
        std::getline(ss, token, ':');
        value.hours = oskar_settings_utility_string_to_int(token);
        if (value.hours < 0) {
            value.hours = 0;
            return false;
        }
        std::getline(ss, token, ':');
        value.minutes = oskar_settings_utility_string_to_int(token);
        if (value.minutes < 0 || value.minutes >= 59) {
            value.minutes = 0;
            return false;
        }
        std::getline(ss, token);
        value.seconds = oskar_settings_utility_string_to_double(token, &ok);
        if (value.minutes < 0.0 || value.minutes >= 60.0) {
            value.seconds = 0.0;
            return false;
        }
        value.format = TIME_STRING;
    }
    return true;
}
Ejemplo n.º 4
0
bool DoubleRangeExt::init(const std::string& s)
{
    // Reset the value.
    ext_min_.clear();
    ext_max_.clear();
    value_ = 0.0;
    default_ = 0.0;

    // Extract range from the parameter CSV string.
    // Parameters, p, for DoubleRangeExt should be length 3 or 4.
    //  - With 3 entries the range is (p[0] to p[1]) with an extended minimum
    //    value of p[2]
    //  - With 4 entries the range is (p[0] to p[1]) with an extended minimum
    //    value of p[2] and an extended maximum value of p[3]
    //  - For the double range parameters, p[0] and p[1], special values
    //    of 'MIN' and 'MAX' map to -DBL_MAX and DBL_MIN respectively.
    bool ok = true;
    std::vector<std::string> p;
    p = oskar_settings_utility_string_get_type_params(s);
    if (p.size() < 3u || p.size() > 4u) {
        return false;
    }
    if (p[0] == "-DBL_MAX" || p[0] == "-MAX")
        min_ = -DBL_MAX;
    else if (p[0] == "DBL_MIN" || p[0] == "-DBL_MIN"
                    || p[0] == "MIN" || p[0] == "-MIN")
        min_ = -DBL_MIN;
    else
        min_ = oskar_settings_utility_string_to_double(p[0], &ok);
    if (!ok) return false;
    if (p[1] == "DBL_MAX" || p[1] == "MAX")
        max_ =  DBL_MAX;
    else
        max_ = oskar_settings_utility_string_to_double(p[1], &ok);
    ext_min_ = p[2];
    if (p.size() == 4u) {
        ext_max_ = p[3];
    }
    return ok;
}
Ejemplo n.º 5
0
bool Double::set_default(const std::string& value)
{
    bool ok = true;
    format_ = (value.find_first_of('e') != std::string::npos) ? EXPONENT : AUTO;
    default_ = oskar_settings_utility_string_to_double(value, &ok);
    if (ok) {
        value_ = default_;
    }
    else {
        value_ = 0.0;
        default_ = 0.0;
    }
    return ok;
}
Ejemplo n.º 6
0
bool DoubleList::from_string_(std::vector<double>& values,
                              const std::string& s) const
{
    // Clear any existing values.
    values.clear();

    // Convert the string to a vector of doubles.
    std::istringstream ss(s);
    std::string token;
    while (std::getline(ss, token, delimiter_))
    {
        bool valid = true;
        double v = oskar_settings_utility_string_to_double(token, &valid);
        if (!valid) return false;
        values.push_back(v);
    }
    return true;
}