// Adding a car involves: // - Registering the object using the registerObjectInstance method // - Updating the newly registered car's attributes using the // updateAttributeValues method void HLAmodule::addCar(const Car& car) throw (rti1516e::Exception) { // May throw rti1516e::Exception, won't leave data structures in inconsistent state ObjectInstanceHandle carHandle = _rtiAmbassador->registerObjectInstance(_objectClassCarHandle); AttributeHandleValueMap attributeMap; { boost::unique_lock<boost::mutex> lock(_carMutex); // Map car id to the object instance handle and cache the car's state int id = car.getID(); _localCars.insert(HLAcar(id, carHandle)); HLAcarState state(car); _carStateCache[id] = state; _hlaCarNameEncoder.set(car.getName()); attributeMap[_nameAttributeHandle] = _hlaCarNameEncoder.encode(); _hlaCarLicensePlateEncoder.set(car.getLicensePlate()); attributeMap[_licensePlateAttributeHandle] = _hlaCarLicensePlateEncoder.encode(); attributeMap[_fuelTypeAttributeHandle] = _hlaCarFuelTypeEncoder.encode(car.getFuelType()); } // Updating attribute values may throw an exception but we don't have to handle that. // We assume that the values will get updated soon enough through updated Car state or // by getting a request for values from another federate. try { _rtiAmbassador->updateAttributeValues(carHandle, attributeMap, VariableLengthData()); } catch (const rti1516e::Exception&) { // Internal data structures are still valid so no clean up is performed } }
void WindowAdmin::readFromXML() { xml_document XMLListOfTeams; QString Path = QCoreApplication::applicationDirPath() +"/../Software/data.xml"; if (!XMLListOfTeams.load_file(Path.toStdString().c_str())) { QMessageBox Error; Error.setText("Can't read the XML file"); } else { listOfTeams.clear(); HighestID=0; xml_node LOT=XMLListOfTeams.child("ListOfTeams"); for(xml_node ReadTeam=LOT.child("Team");ReadTeam;ReadTeam=ReadTeam.next_sibling("Team")) { Team TempTeam; TempTeam.setName(ReadTeam.attribute("Name").value()); xml_node ReadLeader = ReadTeam.child("Leader"); TempTeam.LeaderInfo.setName( ReadLeader.attribute("Name").value()); TempTeam.LeaderInfo.setSurname( ReadLeader.attribute("Surname").value()); TempTeam.LeaderInfo.setPhone( ReadLeader.attribute("Phone").value()); TempTeam.LeaderInfo.setEmail( ReadLeader.attribute("Email").value()); TempTeam.LeaderInfo.setCity( ReadLeader.attribute("City").value()); TempTeam.LeaderInfo.setOrganization( ReadLeader.attribute("Organization").value()); Member TempMember; for(xml_node ReadMember=ReadTeam.child("Member");ReadMember;ReadMember=ReadMember.next_sibling("Member")) { TempMember.setName( ReadMember.attribute("Name").value()); TempMember.setSurname( ReadMember.attribute("Surname").value()); TempTeam.ListOfMembers.push_back(TempMember); } Car TempCar; for(xml_node ReadCar=ReadTeam.child("Car");ReadCar;ReadCar=ReadCar.next_sibling("Car")) { TempCar.clear(); TempCar.setName( ReadCar.attribute("Name").value()); TempCar.setID( ReadCar.attribute("ID").value()); if(TempCar.getID().toInt() >= HighestID) HighestID = TempCar.getID().toInt(); //zapisuje najwyższy numer ID xml_node ReadCarCategory = ReadCar.child("Category"); QString Val; if( Val.append( ReadCarCategory.attribute("MO").value() ) == "Yes") TempCar.setCategoryMO(true); Val.clear(); if( Val.append( ReadCarCategory.attribute("RC").value() ) == "Yes") TempCar.setCategoryRC(true); Val.clear(); if( Val.append( ReadCarCategory.attribute("RD").value() ) == "Yes") TempCar.setCategoryRD(true); xml_node ReadCarCompetition = ReadCar.child("Competition"); Val.clear(); if( Val.append( ReadCarCompetition.attribute("TA").value() ) == "Yes") TempCar.setCompetitionTA(true); Val.clear(); if( Val.append( ReadCarCompetition.attribute("FR").value() ) == "Yes") TempCar.setCompetitionFR(true); TempTeam.ListOfCars.push_back(TempCar); } listOfTeams.push_back(TempTeam); } } }