00001 /*+-------------------------------------------------------------------------+ 00002 | MultiVehicle simulator (libmvsim) | 00003 | | 00004 | Copyright (C) 2014 Jose Luis Blanco Claraco (University of Almeria) | 00005 | Copyright (C) 2017 Borys Tymchenko (Odessa Polytechnic University) | 00006 | Distributed under GNU General Public License version 3 | 00007 | See <http://www.gnu.org/licenses/> | 00008 +-------------------------------------------------------------------------+ */ 00009 00010 #include <mvsim/FrictionModels/FrictionBase.h> 00011 #include <mvsim/FrictionModels/DefaultFriction.h> 00012 #include <mvsim/FrictionModels/WardIagnemmaFriction.h> 00013 #include <mvsim/VehicleBase.h> 00014 #include <rapidxml.hpp> 00015 00016 using namespace mvsim; 00017 00018 TClassFactory_friction mvsim::classFactory_friction; 00019 00020 // Explicit registration calls seem to be one (the unique?) way to assure 00021 // registration takes place: 00022 void register_all_friction() 00023 { 00024 static bool done = false; 00025 if (done) 00026 return; 00027 else 00028 done = true; 00029 00030 REGISTER_FRICTION("default", DefaultFriction) 00031 REGISTER_FRICTION("wardiagnemma", WardIagnemmaFriction) 00032 } 00033 00034 FrictionBase::FrictionBase(VehicleBase& my_vehicle) 00035 : m_world(my_vehicle.getWorldObject()), m_my_vehicle(my_vehicle) 00036 { 00037 } 00038 00039 FrictionBase::~FrictionBase() {} 00040 FrictionBase* FrictionBase::factory( 00041 VehicleBase& parent, const rapidxml::xml_node<char>* xml_node) 00042 { 00043 register_all_friction(); 00044 00045 using namespace std; 00046 using namespace rapidxml; 00047 00048 if (!xml_node || 0 != strcmp(xml_node->name(), "friction")) 00049 throw runtime_error( 00050 "[FrictionBase::factory] Expected XML node <friction>"); 00051 00052 // Parse: 00053 const xml_attribute<>* frict_class = xml_node->first_attribute("class"); 00054 if (!frict_class || !frict_class->value()) 00055 throw runtime_error( 00056 "[FrictionBase::factory] Missing mandatory attribute 'class' in " 00057 "node <friction>"); 00058 00059 return classFactory_friction.create(frict_class->value(), parent, xml_node); 00060 } 00061 00062 void FrictionBase::setLogger(const std::weak_ptr<CSVLogger>& logger) 00063 { 00064 m_logger = logger; 00065 }