X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Fvehicletype.cpp;h=720b922a183a911bef72f9b916243a0bc1d9a63e;hb=d0af7846e05691d65d8021e46c8f81e8ca05199a;hp=c6c399243d9c40854192b0540f4784a4a7f802f6;hpb=d15ac13f2e170f155b4bbd124df48400c339b644;p=r2c2.git diff --git a/source/libr2c2/vehicletype.cpp b/source/libr2c2/vehicletype.cpp index c6c3992..720b922 100644 --- a/source/libr2c2/vehicletype.cpp +++ b/source/libr2c2/vehicletype.cpp @@ -1,3 +1,5 @@ +#include +#include #include "vehicletype.h" using namespace std; @@ -24,30 +26,30 @@ unsigned VehicleType::get_max_function() const const VehicleType::Axle &VehicleType::get_fixed_axle(unsigned i) const { if(i>=axles.size()) - throw InvalidParameterValue("Axle index out of range"); + throw out_of_range("VehicleType::get_fixed_axle"); return axles[i]; } const VehicleType::Bogie &VehicleType::get_bogie(unsigned i) const { if(i>=bogies.size()) - throw InvalidParameterValue("Axle index out of range"); + throw out_of_range("VehicleType::get_bogie"); return bogies[i]; } const VehicleType::Axle &VehicleType::get_bogie_axle(unsigned i, unsigned j) const { if(i>=bogies.size()) - throw InvalidParameterValue("Axle index out of range"); + throw out_of_range("VehicleType::get_bogie_axle"); if(j>=bogies[i].axles.size()) - throw InvalidParameterValue("Axle index out of range"); + throw out_of_range("VehicleType::get_bogie_axle"); return bogies[i].axles[j]; } const VehicleType::Rod &VehicleType::get_rod(unsigned i) const { if(i>=rods.size()) - throw InvalidParameterValue("Rod index out of range"); + throw out_of_range("VehicleType::get_rod"); return rods[i]; } @@ -223,10 +225,7 @@ VehicleType::Rod::Loader::Loader(Rod &r, const map &t): void VehicleType::Rod::Loader::connect(const string &t, float px, float pz, float ox, float oz) { - map::const_iterator i = tags.find(t); - if(i==tags.end()) - throw KeyError("Unknown rod tag", t); - obj.connect_index = i->second; + obj.connect_index = get_item(tags, t); obj.connect_point = Vector(px/1000, 0, pz/1000); obj.connect_offset = Vector(ox/1000, 0, oz/1000); } @@ -251,11 +250,8 @@ void VehicleType::Rod::Loader::pivot_bogie_axle(unsigned i, unsigned j) void VehicleType::Rod::Loader::pivot_rod(const string &t) { - map::const_iterator i = tags.find(t); - if(i==tags.end()) - throw KeyError("Unknown rod tag", t); + obj.pivot_index = get_item(tags, t); obj.pivot = ROD; - obj.pivot_index = i->second; } void VehicleType::Rod::Loader::position(float x, float y, float z) @@ -279,7 +275,7 @@ void operator>>(const LexicalConverter &c, VehicleType::Rod::Limit &l) else if(s=="SLIDE_X") l = VehicleType::Rod::SLIDE_X; else - throw LexicalError("Invalid value for Rod::Limit"); + throw lexical_error(format("conversion of '%s' to Rod::Limit", s)); } } // namespace R2C2