Esempio n. 1
0
bool CSettingUtils::ValuesToList(const CSettingList *setting, const std::vector<CVariant> &values,
                                 std::vector< std::shared_ptr<CSetting> > &newValues)
{
  if (setting == NULL)
    return false;

  int index = 0;
  bool ret = true;
  for (std::vector<CVariant>::const_iterator itValue = values.begin(); itValue != values.end(); ++itValue)
  {
    CSetting *settingValue = setting->GetDefinition()->Clone(StringUtils::Format("%s.%d", setting->GetId().c_str(), index++));
    if (settingValue == NULL)
      return false;

    switch (setting->GetElementType())
    {
      case SettingTypeBool:
        if (!itValue->isBoolean())
          ret = false;
        else
          ret = static_cast<CSettingBool*>(settingValue)->SetValue(itValue->asBoolean());
        break;

      case SettingTypeInteger:
        if (!itValue->isInteger())
          ret = false;
        else
          ret = static_cast<CSettingInt*>(settingValue)->SetValue((int)itValue->asInteger());
        break;

      case SettingTypeNumber:
        if (!itValue->isDouble())
          ret = false;
        else
          ret = static_cast<CSettingNumber*>(settingValue)->SetValue(itValue->asDouble());
        break;

      case SettingTypeString:
        if (!itValue->isString())
          ret = false;
        else
          ret = static_cast<CSettingString*>(settingValue)->SetValue(itValue->asString());
        break;

      default:
        ret = false;
        break;
    }

    if (!ret)
    {
      delete settingValue;
      return false;
    }

    newValues.push_back(SettingPtr(settingValue));
  }

  return true;
}
Esempio n. 2
0
bool CSettingList::fromValues(const std::vector<std::string> &strValues, SettingPtrList &values) const
{
    if ((int)strValues.size() < m_minimumItems ||
            (m_maximumItems > 0 && (int)strValues.size() > m_maximumItems))
        return false;

    bool ret = true;
    int index = 0;
    for (std::vector<std::string>::const_iterator itValue = strValues.begin(); itValue != strValues.end(); ++itValue)
    {
        CSetting *settingValue = m_definition->Clone(StringUtils::Format("%s.%d", m_id.c_str(), index++));
        if (settingValue == NULL ||
                !settingValue->FromString(*itValue))
        {
            delete settingValue;
            ret = false;
            break;
        }

        values.push_back(SettingPtr(settingValue));
    }

    if (!ret)
        values.clear();

    return ret;
}
Esempio n. 3
0
void CSettingList::Reset()
{
    CExclusiveLock lock(m_critical);
    SettingPtrList values;
    for (SettingPtrList::const_iterator it = m_defaults.begin(); it != m_defaults.end(); ++it)
        values.push_back(SettingPtr((*it)->Clone((*it)->GetId())));

    SetValue(values);
}
SettingPtr DifficultySettings::getSettingById(int id) const {
    // Search all stored settings matching this classname
    SettingIdMap::const_iterator found = _settingIds.find(id);

    if (found != _settingIds.end()) {
        return found->second;
    }

    return SettingPtr(); // not found
}
Esempio n. 5
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())));
    }
}
Esempio n. 6
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));
    }
}