Fix python __str__ wrapper (#1730)

This commit is contained in:
xmyqsh 2019-06-12 18:56:32 +08:00 committed by Néstor Subirón
parent 978019be32
commit 104b1e36ec
7 changed files with 45 additions and 44 deletions

View File

@ -16,6 +16,7 @@
* API extension: waypoint's `junction_id` that returns de OpenDrive identifier of the current junction * API extension: waypoint's `junction_id` that returns de OpenDrive identifier of the current junction
* API extension: add gamma value as attribute to RGB camera * API extension: add gamma value as attribute to RGB camera
* API change: deprecated waypoint's `is_intersection`, now is `is_junction` * API change: deprecated waypoint's `is_intersection`, now is `is_junction`
* API update: solve the problem of RuntimeError: std::bad_cast described here: #1125 (comment)
* Removed deprecated code and content * Removed deprecated code and content
* New recorder features: * New recorder features:
- Added optional parameter to show more details about a recorder file (related to `show_recorder_file_info.py`) - Added optional parameter to show more details about a recorder file (related to `show_recorder_file_info.py`)

View File

@ -17,10 +17,10 @@ namespace sensor {
namespace data { namespace data {
std::ostream &operator<<(std::ostream &out, const Color &color) { std::ostream &operator<<(std::ostream &out, const Color &color) {
out << "Color(" << int(color.r) out << "Color(" << std::to_string(color.r)
<< ',' << int(color.g) << ',' << std::to_string(color.g)
<< ',' << int(color.b) << ',' << std::to_string(color.b)
<< ',' << int(color.a) << ')'; << ',' << std::to_string(color.a) << ')';
return out; return out;
} }

View File

@ -19,44 +19,44 @@ namespace rpc {
}; };
std::ostream &operator<<(std::ostream &out, const VehicleControl &control) { std::ostream &operator<<(std::ostream &out, const VehicleControl &control) {
out << "VehicleControl(throttle=" << control.throttle out << "VehicleControl(throttle=" << std::to_string(control.throttle)
<< ", steer=" << control.steer << ", steer=" << std::to_string(control.steer)
<< ", brake=" << control.brake << ", brake=" << std::to_string(control.brake)
<< ", hand_brake=" << boolalpha(control.hand_brake) << ", hand_brake=" << boolalpha(control.hand_brake)
<< ", reverse=" << boolalpha(control.reverse) << ", reverse=" << boolalpha(control.reverse)
<< ", manual_gear_shift=" << boolalpha(control.manual_gear_shift) << ", manual_gear_shift=" << boolalpha(control.manual_gear_shift)
<< ", gear=" << control.gear << ')'; << ", gear=" << std::to_string(control.gear) << ')';
return out; return out;
} }
std::ostream &operator<<(std::ostream &out, const WalkerControl &control) { std::ostream &operator<<(std::ostream &out, const WalkerControl &control) {
out << "WalkerControl(direction=" << control.direction out << "WalkerControl(direction=" << control.direction
<< ", speed=" << control.speed << ", speed=" << std::to_string(control.speed)
<< ", jump=" << boolalpha(control.jump) << ')'; << ", jump=" << boolalpha(control.jump) << ')';
return out; return out;
} }
std::ostream &operator<<(std::ostream &out, const WheelPhysicsControl &control) { std::ostream &operator<<(std::ostream &out, const WheelPhysicsControl &control) {
out << "WheelPhysicsControl(tire_friction=" << control.tire_friction out << "WheelPhysicsControl(tire_friction=" << std::to_string(control.tire_friction)
<< ", damping_rate=" << control.damping_rate << ", damping_rate=" << std::to_string(control.damping_rate)
<< ", max_steer_angle=" << control.max_steer_angle << ", max_steer_angle=" << std::to_string(control.max_steer_angle)
<< ", radius=" << control.radius << ", radius=" << std::to_string(control.radius)
<< ", position=" << control.position << ')'; << ", position=" << control.position << ')';
return out; return out;
} }
std::ostream &operator<<(std::ostream &out, const VehiclePhysicsControl &control) { std::ostream &operator<<(std::ostream &out, const VehiclePhysicsControl &control) {
out << "VehiclePhysicsControl(torque_curve=" << control.torque_curve out << "VehiclePhysicsControl(torque_curve=" << control.torque_curve
<< ", max_rpm=" << control.max_rpm << ", max_rpm=" << std::to_string(control.max_rpm)
<< ", moi=" << control.moi << ", moi=" << std::to_string(control.moi)
<< ", damping_rate_full_throttle=" << control.damping_rate_full_throttle << ", damping_rate_full_throttle=" << std::to_string(control.damping_rate_full_throttle)
<< ", damping_rate_zero_throttle_clutch_engaged=" << control.damping_rate_zero_throttle_clutch_engaged << ", damping_rate_zero_throttle_clutch_engaged=" << std::to_string(control.damping_rate_zero_throttle_clutch_engaged)
<< ", damping_rate_zero_throttle_clutch_disengaged=" << control.damping_rate_zero_throttle_clutch_disengaged << ", damping_rate_zero_throttle_clutch_disengaged=" << std::to_string(control.damping_rate_zero_throttle_clutch_disengaged)
<< ", use_gear_autobox=" << boolalpha(control.use_gear_autobox) << ", use_gear_autobox=" << boolalpha(control.use_gear_autobox)
<< ", gear_switch_time=" << control.gear_switch_time << ", gear_switch_time=" << std::to_string(control.gear_switch_time)
<< ", clutch_strength=" << control.clutch_strength << ", clutch_strength=" << std::to_string(control.clutch_strength)
<< ", mass=" << control.mass << ", mass=" << std::to_string(control.mass)
<< ", drag_coefficient=" << control.drag_coefficient << ", drag_coefficient=" << std::to_string(control.drag_coefficient)
<< ", center_of_mass=" << control.center_of_mass << ", center_of_mass=" << control.center_of_mass
<< ", steering_curve=" << control.steering_curve << ", steering_curve=" << control.steering_curve
<< ", wheels=" << control.wheels << ')'; << ", wheels=" << control.wheels << ')';

View File

@ -23,16 +23,16 @@ namespace geom {
template <typename T> template <typename T>
static void WriteVector2D(std::ostream &out, const char *name, const T &vector2D) { static void WriteVector2D(std::ostream &out, const char *name, const T &vector2D) {
out << name out << name
<< "(x=" << vector2D.x << "(x=" << std::to_string(vector2D.x)
<< ", y=" << vector2D.y << ')'; << ", y=" << std::to_string(vector2D.y) << ')';
} }
template <typename T> template <typename T>
static void WriteVector3D(std::ostream &out, const char *name, const T &vector3D) { static void WriteVector3D(std::ostream &out, const char *name, const T &vector3D) {
out << name out << name
<< "(x=" << vector3D.x << "(x=" << std::to_string(vector3D.x)
<< ", y=" << vector3D.y << ", y=" << std::to_string(vector3D.y)
<< ", z=" << vector3D.z << ')'; << ", z=" << std::to_string(vector3D.z) << ')';
} }
std::ostream &operator<<(std::ostream &out, const Vector2D &vector2D) { std::ostream &operator<<(std::ostream &out, const Vector2D &vector2D) {
@ -51,9 +51,9 @@ namespace geom {
} }
std::ostream &operator<<(std::ostream &out, const Rotation &rotation) { std::ostream &operator<<(std::ostream &out, const Rotation &rotation) {
out << "Rotation(pitch=" << rotation.pitch out << "Rotation(pitch=" << std::to_string(rotation.pitch)
<< ", yaw=" << rotation.yaw << ", yaw=" << std::to_string(rotation.yaw)
<< ", roll=" << rotation.roll << ')'; << ", roll=" << std::to_string(rotation.roll) << ')';
return out; return out;
} }
@ -70,9 +70,9 @@ namespace geom {
} }
std::ostream &operator<<(std::ostream &out, const GeoLocation &geo_location) { std::ostream &operator<<(std::ostream &out, const GeoLocation &geo_location) {
out << "GeoLocation(latitude=" << geo_location.latitude out << "GeoLocation(latitude=" << std::to_string(geo_location.latitude)
<< ", longitude=" << geo_location.longitude << ", longitude=" << std::to_string(geo_location.longitude)
<< ", altitude=" << geo_location.altitude << ')'; << ", altitude=" << std::to_string(geo_location.altitude) << ')';
return out; return out;
} }

View File

@ -12,12 +12,12 @@ namespace carla {
namespace rpc { namespace rpc {
std::ostream &operator<<(std::ostream &out, const WeatherParameters &weather) { std::ostream &operator<<(std::ostream &out, const WeatherParameters &weather) {
out << "WeatherParameters(cloudyness=" << weather.cloudyness out << "WeatherParameters(cloudyness=" << std::to_string(weather.cloudyness)
<< ", precipitation=" << weather.precipitation << ", precipitation=" << std::to_string(weather.precipitation)
<< ", precipitation_deposits=" << weather.precipitation_deposits << ", precipitation_deposits=" << std::to_string(weather.precipitation_deposits)
<< ", wind_intensity=" << weather.wind_intensity << ", wind_intensity=" << std::to_string(weather.wind_intensity)
<< ", sun_azimuth_angle=" << weather.sun_azimuth_angle << ", sun_azimuth_angle=" << std::to_string(weather.sun_azimuth_angle)
<< ", sun_altitude_angle=" << weather.sun_altitude_angle << ')'; << ", sun_altitude_angle=" << std::to_string(weather.sun_altitude_angle) << ')';
return out; return out;
} }

View File

@ -19,10 +19,10 @@ namespace client {
} }
std::ostream &operator<<(std::ostream &out, const Timestamp &timestamp) { std::ostream &operator<<(std::ostream &out, const Timestamp &timestamp) {
out << "Timestamp(frame_count=" << timestamp.frame_count out << "Timestamp(frame_count=" << std::to_string(timestamp.frame_count)
<< ",elapsed_seconds=" << timestamp.elapsed_seconds << ",elapsed_seconds=" << std::to_string(timestamp.elapsed_seconds)
<< ",delta_seconds=" << timestamp.delta_seconds << ",delta_seconds=" << std::to_string(timestamp.delta_seconds)
<< ",platform_timestamp=" << timestamp.platform_timestamp << ')'; << ",platform_timestamp=" << std::to_string(timestamp.platform_timestamp) << ')';
return out; return out;
} }

View File

@ -113,7 +113,7 @@ class TestTransform(unittest.TestCase):
t = carla.Transform( t = carla.Transform(
carla.Location(x=1.0, y=2.0, z=3.0), carla.Location(x=1.0, y=2.0, z=3.0),
carla.Rotation(pitch=4.0, yaw=5.0, roll=6.0)) carla.Rotation(pitch=4.0, yaw=5.0, roll=6.0))
s = 'Transform(Location(x=1, y=2, z=3), Rotation(pitch=4, yaw=5, roll=6))' s = 'Transform(Location(x=1.000000, y=2.000000, z=3.000000), Rotation(pitch=4.000000, yaw=5.000000, roll=6.000000))'
self.assertEqual(str(t), s) self.assertEqual(str(t), s)
def test_translation(self): def test_translation(self):