There is some code sharing allowed by using a generic array in SensorReading. For example, Sensor.h provides a ReadingValue() function that can be called by IDL accessors:
double Sensor::ReadingValueUnchecked(int index) const {
DCHECK(sensor_proxy_);
DCHECK(index >= 0 && index < device::SensorReading::kValuesCount);
return sensor_proxy_->Reading().values[index];
}
double Sensor::ReadingValue(int index, bool& is_null) const {
is_null = !CanReturnReadings();
return is_null ? 0.0 : ReadingValueUnchecked(index);
}
double Gyroscope::x(bool& is_null) const {
return ReadingValue(0, is_null);
}
If we use a union this will become:
const device::Reading& Sensor::Reading() const {
return sensor_proxy_->Reading();
}
double Gyroscope::x(bool& is_null) const {
is_null = !CanReturnReadings();
return sensor_proxy_->Reading().gyroscope.x;
}
I think this is reasonable.
Comment 1 by reillyg@chromium.org
, May 4 2017There is some code sharing allowed by using a generic array in SensorReading. For example, Sensor.h provides a ReadingValue() function that can be called by IDL accessors: double Sensor::ReadingValueUnchecked(int index) const { DCHECK(sensor_proxy_); DCHECK(index >= 0 && index < device::SensorReading::kValuesCount); return sensor_proxy_->Reading().values[index]; } double Sensor::ReadingValue(int index, bool& is_null) const { is_null = !CanReturnReadings(); return is_null ? 0.0 : ReadingValueUnchecked(index); } double Gyroscope::x(bool& is_null) const { return ReadingValue(0, is_null); } If we use a union this will become: const device::Reading& Sensor::Reading() const { return sensor_proxy_->Reading(); } double Gyroscope::x(bool& is_null) const { is_null = !CanReturnReadings(); return sensor_proxy_->Reading().gyroscope.x; } I think this is reasonable.