void Serialized::CreateObjects(const wxXmlNode& root) { wxString uid; if (root.GetPropVal(wxT("uid"), &uid)) { if (m_Objects.find(uid) == m_Objects.end()) { wxString classname = root.GetName(); std::map<wxString, Creator>::iterator it = m_Creators.find(classname); if (it == m_Creators.end()) { THROW(TXT("Class \"%s\" not found."), root.GetName().c_str()); } Serialized *obj = (it->second)(root); m_Objects.insert(std::pair<wxString, Serialized *>(uid, obj)); } } wxXmlNode *child = root.GetChildren(); while (child != NULL) { CreateObjects(*child); child = child->GetNext(); } }
int GetIntAttribute(const wxXmlNode& node, const wxString& name, const wxString& def) { wxString value = GetStringAttribute(node, name, def); long l; if (!value.ToLong(&l, 0)) { THROW("Attribute \"%s\" in element <%s> is not an integer.", name.c_str(), node.GetName().c_str()); } return l; }
wxString GetStringAttribute(const wxXmlNode& node, const wxString& name, const wxString& def) { wxString value; if (!node.GetPropVal(name, &value)) { if (def == wxEmptyString) { THROW("Couldn't find attribute \"%s\" in element <%s>.", name.c_str(), node.GetName().c_str()); } value = def; } return value; }
bool GetBoolAttribute(const wxXmlNode& node, const wxString& name, const wxString& def) { wxString value = GetStringAttribute(node, name, def); if (value == wxT("true")) { return true; } else if (value == wxT("false")) { return false; } else { THROW("Attribute \"%s\" in element <%s> is not a boolean.", name.c_str(), node.GetName().c_str()); } }