Esempio n. 1
0
bool CSettingList::Equals(const std::string &value) const
{
    SettingPtrList values;
    if (!fromString(value, values) ||
            values.size() != m_values.size())
        return false;

    bool ret = true;
    for (size_t index = 0; index < values.size(); index++)
    {
        if (!m_values[index]->Equals(values[index]->ToString()))
        {
            ret = false;
            break;
        }
    }

    return ret;
}
Esempio n. 2
0
bool CSettingList::SetValue(const SettingPtrList &values)
{
    CExclusiveLock lock(m_critical);

    if ((int)values.size() < m_minimumItems ||
            (m_maximumItems > 0 && (int)values.size() > m_maximumItems))
        return false;

    bool equal = values.size() == m_values.size();
    for (size_t index = 0; index < values.size(); index++)
    {
        if (values[index]->GetType() != GetElementType())
            return false;

        if (equal &&
                !values[index]->Equals(m_values[index]->ToString()))
            equal = false;
    }

    if (equal)
        return true;

    SettingPtrList oldValues = m_values;
    m_values.clear();
    m_values.insert(m_values.begin(), values.begin(), values.end());

    if (!OnSettingChanging(this))
    {
        m_values = oldValues;

        // the setting couldn't be changed because one of the
        // callback handlers failed the OnSettingChanging()
        // callback so we need to let all the callback handlers
        // know that the setting hasn't changed
        OnSettingChanging(this);
        return false;
    }

    m_changed = (toString(m_values) != toString(m_defaults));
    OnSettingChanged(this);
    return true;
}