Example #1
0
std::string CSettingList::toString(const SettingPtrList &values) const
{
    std::vector<std::string> strValues;
    for (SettingPtrList::const_iterator it = values.begin(); it != values.end(); ++it)
    {
        if (*it != NULL)
            strValues.push_back((*it)->ToString());
    }

    return StringUtils::Join(strValues, m_delimiter);
}
Example #2
0
void CSettingList::SetDefault(const SettingPtrList &values)
{
    CExclusiveLock lock(m_critical);

    m_defaults.clear();
    m_defaults.insert(m_defaults.begin(), values.begin(), values.end());

    if (!m_changed)
    {
        m_values.clear();
        for (SettingPtrList::const_iterator it = m_defaults.begin(); it != m_defaults.end(); ++it)
            m_values.push_back(SettingPtr((*it)->Clone((*it)->GetId())));
    }
}
Example #3
0
void CSettingList::copy(const SettingPtrList &srcValues, SettingPtrList &dstValues)
{
    dstValues.clear();

    for (SettingPtrList::const_iterator itValue = srcValues.begin(); itValue != srcValues.end(); ++itValue)
    {
        if (*itValue == NULL)
            continue;

        CSetting *valueCopy = (*itValue)->Clone((*itValue)->GetId());
        if (valueCopy == NULL)
            continue;

        dstValues.push_back(SettingPtr(valueCopy));
    }
}
Example #4
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;
}