SimulatorResourceModel::Attribute &m_attrItem;
};
-class Converter
-{
- public:
- void convert(const OC::OCRepresentation::AttributeItem &attrItem)
- {
- if (attrItem.type() == OC::AttributeType::Integer)
- m_attribute.setValue(attrItem.getValue<int>());
- if (attrItem.type() == OC::AttributeType::Double)
- m_attribute.setValue(attrItem.getValue<double>());
- if (attrItem.type() == OC::AttributeType::String)
- m_attribute.setValue(attrItem.getValue<std::string>());
- }
-
- SimulatorResourceModel::Attribute &&get()
- {
- return std::move(m_attribute);
- }
-
- private:
- SimulatorResourceModel::Attribute m_attribute;
-};
-
SimulatorResourceModel::Attribute::ValueVariant
&SimulatorResourceModel::Attribute::AllowedValues::at(int index)
{
}
void SimulatorResourceModel::Attribute::addValuetoRepresentation(OC::OCRepresentation &rep,
- const std::string &key)
+ const std::string &key) const
{
add_to_representation visitor(rep, key);
boost::apply_visitor(visitor, m_value);
return;
}
-OC::OCRepresentation SimulatorResourceModel::getOCRepresentation()
+OC::OCRepresentation SimulatorResourceModel::getOCRepresentation() const
{
OC::OCRepresentation rep;
for (auto & attribute : m_attributes)
return rep;
}
-bool SimulatorResourceModel::update(OC::OCRepresentation &ocRep, UpdateType type)
+bool SimulatorResourceModel::update(OC::OCRepresentation &ocRep)
{
if (0 == ocRep.size())
return true;
// Convert OCRepresentation to SimulatorResourceModel
- SimulatorResourceModel resModel;
- for (auto & attributeItem : ocRep)
- {
- Converter converter;
- converter.convert(attributeItem);
- SimulatorResourceModel::Attribute attribute = converter.get();
- attribute.setName(attributeItem.attrname());
- resModel.m_attributes[attributeItem.attrname()] = attribute;
- }
+ SimulatorResourceModel resModel = create(ocRep);
- return update(resModel, type);
+ return update(resModel);
}
-bool SimulatorResourceModel::update(SimulatorResourceModel &repModel, UpdateType type)
+bool SimulatorResourceModel::update(SimulatorResourceModel &repModel)
{
std::map<std::string, SimulatorResourceModel::Attribute> attributes = repModel.getAttributes();
for (auto & attributeItem : attributes)
{
// Check the attribute presence
SimulatorResourceModel::Attribute attribute;
- if (type == PUT)
- {
- if (false == getAttribute((attributeItem.second).getName(), attribute))
- {
- return false;
- }
-
- // Check the validity of the value to be set
- if (false == attribute.compare(attributeItem.second))
- {
- return false;
- }
- m_attributes[(attributeItem.second).getName()].setValue((attributeItem.second).getValue());
- }
- else if (type == POST)
+ if (false == getAttribute((attributeItem.second).getName(), attribute))
{
- if (false == getAttribute((attributeItem.second).getName(), attribute))
- {
- addAttribute(((attributeItem.second).getName()) , ((attributeItem.second).getValue()));
- continue;
- }
- else
- {
- // Check the validity of the value to be set
- if (false == attribute.compare(attributeItem.second))
- {
- return false;
- }
- m_attributes[(attributeItem.second).getName()].setValue((attributeItem.second).getValue());
- }
+ return false;
}
- else if (type == DELETE )
+
+ // Check the validity of the value to be set
+ if (false == attribute.compare(attributeItem.second))
{
- if (true == getAttribute((attributeItem.second).getName(), attribute))
- {
- removeAttribute((attributeItem.second).getName());
- }
+ return false;
}
+ m_attributes[(attributeItem.second).getName()].setValue((attributeItem.second).getValue());
}
+
return true;
-}
\ No newline at end of file
+}
+
+SimulatorResourceModel SimulatorResourceModel::create(const OC::OCRepresentation &ocRep)
+{
+ SimulatorResourceModel resModel;
+ for (auto & attributeItem : ocRep)
+ {
+ SimulatorResourceModel::Attribute attribute;
+ if (attributeItem.type() == OC::AttributeType::Integer)
+ attribute.setValue(attributeItem.getValue<int>());
+ if (attributeItem.type() == OC::AttributeType::Double)
+ attribute.setValue(attributeItem.getValue<double>());
+ if (attributeItem.type() == OC::AttributeType::String)
+ attribute.setValue(attributeItem.getValue<std::string>());
+
+ attribute.setName(attributeItem.attrname());
+ resModel.m_attributes[attributeItem.attrname()] = attribute;
+ }
+
+ return resModel;
+}
+