Skip to content
This repository was archived by the owner on Nov 26, 2025. It is now read-only.

Commit f3006eb

Browse files
MikeGitbdcyoung
authored andcommitted
fix_cpp_interface (#107)
* [libsweep/c++] Fix: Mark functions implemented in header as inline * [Libsweep/c++] Remove const from scan members * [libsweep/c++] Refactor get_scan * [libsweep/c++] Run clang format over sweep.hpp
1 parent 92ff978 commit f3006eb

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

libsweep/include/sweep/sweep.hpp

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ struct device_error final : std::runtime_error {
3131
// Interface
3232

3333
struct sample {
34-
const std::int32_t angle;
35-
const std::int32_t distance;
36-
const std::int32_t signal_strength;
34+
std::int32_t angle;
35+
std::int32_t distance;
36+
std::int32_t signal_strength;
3737
};
3838

3939
struct scan {
@@ -74,55 +74,57 @@ struct error_to_exception {
7474

7575
::sweep_error_s error = nullptr;
7676
};
77-
}
77+
} // namespace detail
7878

79-
sweep::sweep(const char* port)
79+
inline sweep::sweep(const char* port)
8080
: device{::sweep_device_construct_simple(port, detail::error_to_exception{}), &::sweep_device_destruct} {}
8181

82-
sweep::sweep(const char* port, std::int32_t bitrate)
82+
inline sweep::sweep(const char* port, std::int32_t bitrate)
8383
: device{::sweep_device_construct(port, bitrate, detail::error_to_exception{}), &::sweep_device_destruct} {}
8484

85-
void sweep::start_scanning() { ::sweep_device_start_scanning(device.get(), detail::error_to_exception{}); }
85+
inline void sweep::start_scanning() { ::sweep_device_start_scanning(device.get(), detail::error_to_exception{}); }
8686

87-
void sweep::stop_scanning() { ::sweep_device_stop_scanning(device.get(), detail::error_to_exception{}); }
87+
inline void sweep::stop_scanning() { ::sweep_device_stop_scanning(device.get(), detail::error_to_exception{}); }
8888

89-
bool sweep::get_motor_ready() { return ::sweep_device_get_motor_ready(device.get(), detail::error_to_exception{}); }
89+
inline bool sweep::get_motor_ready() { return ::sweep_device_get_motor_ready(device.get(), detail::error_to_exception{}); }
9090

91-
std::int32_t sweep::get_motor_speed() { return ::sweep_device_get_motor_speed(device.get(), detail::error_to_exception{}); }
91+
inline std::int32_t sweep::get_motor_speed() {
92+
return ::sweep_device_get_motor_speed(device.get(), detail::error_to_exception{});
93+
}
9294

93-
void sweep::set_motor_speed(std::int32_t speed) {
95+
inline void sweep::set_motor_speed(std::int32_t speed) {
9496
::sweep_device_set_motor_speed(device.get(), speed, detail::error_to_exception{});
9597
}
9698

97-
std::int32_t sweep::get_sample_rate() { return ::sweep_device_get_sample_rate(device.get(), detail::error_to_exception{}); }
99+
inline std::int32_t sweep::get_sample_rate() {
100+
return ::sweep_device_get_sample_rate(device.get(), detail::error_to_exception{});
101+
}
98102

99-
void sweep::set_sample_rate(std::int32_t rate) {
103+
inline void sweep::set_sample_rate(std::int32_t rate) {
100104
::sweep_device_set_sample_rate(device.get(), rate, detail::error_to_exception{});
101105
}
102106

103-
scan sweep::get_scan() {
107+
inline scan sweep::get_scan() {
104108
using scan_owner = std::unique_ptr<::sweep_scan, decltype(&::sweep_scan_destruct)>;
105109

106-
scan_owner releasing_scan{::sweep_device_get_scan(device.get(), detail::error_to_exception{}), &::sweep_scan_destruct};
110+
const scan_owner releasing_scan{::sweep_device_get_scan(device.get(), detail::error_to_exception{}), &::sweep_scan_destruct};
107111

108-
auto num_samples = ::sweep_scan_get_number_of_samples(releasing_scan.get());
109-
110-
scan result;
111-
result.samples.reserve(num_samples);
112+
const auto num_samples = ::sweep_scan_get_number_of_samples(releasing_scan.get());
112113

114+
scan result{std::vector<sample>(num_samples)};
113115
for (std::int32_t n = 0; n < num_samples; ++n) {
114-
auto angle = ::sweep_scan_get_angle(releasing_scan.get(), n);
115-
auto distance = ::sweep_scan_get_distance(releasing_scan.get(), n);
116-
auto signal = ::sweep_scan_get_signal_strength(releasing_scan.get(), n);
117-
118-
result.samples.push_back(sample{angle, distance, signal});
116+
// clang-format off
117+
result.samples[n].angle = ::sweep_scan_get_angle (releasing_scan.get(), n);
118+
result.samples[n].distance = ::sweep_scan_get_distance (releasing_scan.get(), n);
119+
result.samples[n].signal_strength = ::sweep_scan_get_signal_strength(releasing_scan.get(), n);
120+
// clang-format on
119121
}
120122

121123
return result;
122124
}
123125

124-
void sweep::reset() { ::sweep_device_reset(device.get(), detail::error_to_exception{}); }
126+
inline void sweep::reset() { ::sweep_device_reset(device.get(), detail::error_to_exception{}); }
125127

126-
} // ns
128+
} // namespace sweep
127129

128130
#endif

0 commit comments

Comments
 (0)