//--------------------------------------------------------- void ofDeserialize(const ofxXmlSettings & xml, ofAbstractParameter & parameter){ if(!parameter.isSerializable()) return; string name = parameter.getEscapedName(); if(parameter.type()==typeid(ofParameterGroup).name()){ ofParameterGroup & group = static_cast<ofParameterGroup&>(parameter); if(xml.tagExists(name)){ const_cast<ofxXmlSettings&>(xml).pushTag(name); for(int i=0;i<group.size();i++){ ofDeserialize(xml, group.get(i)); } const_cast<ofxXmlSettings&>(xml).popTag(); } }else{ if(xml.tagExists(name)){ if(parameter.type()==typeid(ofParameter<int>).name()){ parameter.cast<int>() = xml.getValue(name,0); }else if(parameter.type()==typeid(ofParameter<float>).name()){ parameter.cast<float>() = xml.getValue(name,0.0f); }else if(parameter.type()==typeid(ofParameter<bool>).name()){ parameter.cast<bool>() = xml.getValue(name,false); }else if(parameter.type()==typeid(ofParameter<string>).name()){ parameter.cast<string>() = xml.getValue(name,""); }else{ parameter.fromString(xml.getValue(name,"")); } } } }
void ofDeserialize(const ofXml & xml, ofAbstractParameter & parameter){ if(!parameter.isSerializable()){ return; } string name = parameter.getEscapedName(); ofXml child = xml.findFirst(name); if(child){ if(parameter.type() == typeid(ofParameterGroup).name()){ ofParameterGroup & group = static_cast <ofParameterGroup &>(parameter); for(auto & p: group){ ofDeserialize(child, *p); } }else{ if(parameter.type() == typeid(ofParameter <int> ).name()){ parameter.cast <int>() = child.getIntValue(); }else if(parameter.type() == typeid(ofParameter <float> ).name()){ parameter.cast <float>() = child.getFloatValue(); }else if(parameter.type() == typeid(ofParameter <bool> ).name()){ parameter.cast <bool>() = child.getBoolValue(); }else if(parameter.type() == typeid(ofParameter <string> ).name()){ parameter.cast <string>() = child.getValue(); }else{ parameter.fromString(child.getValue()); } } } }