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; }
bool CSettings::SetList(const std::string &id, const std::vector<CVariant> &value) { CSetting *setting = m_settingsManager->GetSetting(id); if (setting == NULL || setting->GetType() != SettingTypeList) return false; CSettingList *listSetting = static_cast<CSettingList*>(setting); SettingPtrList newValues; bool ret = true; int index = 0; for (std::vector<CVariant>::const_iterator itValue = value.begin(); itValue != value.end(); ++itValue) { CSetting *settingValue = listSetting->GetDefinition()->Clone(StringUtils::Format("%s.%d", listSetting->GetId().c_str(), index++)); if (settingValue == NULL) return false; switch (listSetting->GetElementType()) { case SettingTypeBool: if (!itValue->isBoolean()) return false; ret = static_cast<CSettingBool*>(settingValue)->SetValue(itValue->asBoolean()); break; case SettingTypeInteger: if (!itValue->isInteger()) return false; ret = static_cast<CSettingInt*>(settingValue)->SetValue((int)itValue->asInteger()); break; case SettingTypeNumber: if (!itValue->isDouble()) return false; ret = static_cast<CSettingNumber*>(settingValue)->SetValue(itValue->asDouble()); break; case SettingTypeString: if (!itValue->isString()) return false; 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 listSetting->SetValue(newValues); }
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); }
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)); } }