bool Robot::initXml(TiXmlElement *root) { assert(hw_); TiXmlElement *xit = NULL; // Constructs the joints. for (xit = root->FirstChildElement("joint"); xit; xit = xit->NextSiblingElement("joint")) { Joint *j = new Joint; if (j->initXml(xit)) joints_.push_back(j); else delete j; } // Constructs the transmissions. for (xit = root->FirstChildElement("transmission"); xit; xit = xit->NextSiblingElement("transmission")) { const char *type = xit->Attribute("type"); Transmission *t = type ? TransmissionFactory::instance().create(type) : NULL; if (!t) fprintf(stderr, "Unknown transmission type: \"%s\"\n", type); else if (!t->initXml(xit, this)) delete t; else // Success! transmissions_.push_back(t); } // Constructs the links. for (xit = root->FirstChildElement("link"); xit; xit = xit->NextSiblingElement("link")) { Link *link = new Link; if (link->initXml(xit, this)) links_.push_back(link); else delete link; } // For now, we only care about the sensors as links. for (xit = root->FirstChildElement("sensor"); xit; xit = xit->NextSiblingElement("sensor")) { Link *link = new Link; if (link->initXml(xit, this)) links_.push_back(link); else delete link; } return true; }