DevSpecp.yy: Fix mirror list use of std::move()d objects

We were building a list of mirrored items filled with the memory
pointed to by unique_ptrs which had already been std::move()d into
other unique_ptrs.
This commit is contained in:
2025-01-13 07:06:28 -04:00
parent 8e94e829d0
commit edf51a4441
+28 -3
View File
@@ -7,6 +7,7 @@
#include <stdexcept> #include <stdexcept>
#include <memory> #include <memory>
#include <functional> #include <functional>
#include <user/senseDeviceSpec.h>
#include <deviceManager/deviceManager.h> #include <deviceManager/deviceManager.h>
#ifndef yylex #ifndef yylex
@@ -33,6 +34,32 @@ void yyerror(const char *message)
+ std::string(message)); + std::string(message));
} }
void mirrorDeviceSpecs() {
for (const auto& interoSpec : DeviceManager::interoceptorDeviceSpecs) {
auto it = std::find_if(
DeviceManager::senseDeviceSpecs.begin(),
DeviceManager::senseDeviceSpecs.end(),
[&interoSpec](const SenseDeviceSpec& spec) {
return spec == *interoSpec;
});
if (it == DeviceManager::senseDeviceSpecs.end()) {
DeviceManager::senseDeviceSpecs.push_back(*interoSpec);
}
}
for (const auto& extroSpec : DeviceManager::extrospectorDeviceSpecs) {
auto it = std::find_if(
DeviceManager::senseDeviceSpecs.begin(),
DeviceManager::senseDeviceSpecs.end(),
[&extroSpec](const SenseDeviceSpec& spec) {
return spec == *extroSpec;
});
if (it == DeviceManager::senseDeviceSpecs.end()) {
DeviceManager::senseDeviceSpecs.push_back(*extroSpec);
}
}
}
%} %}
%union { %union {
@@ -57,7 +84,7 @@ void yyerror(const char *message)
%% %%
file: /* NOTHING */ file: /* NOTHING */
| sensor_specs | sensor_specs { mirrorDeviceSpecs(); }
; ;
sensor_specs: sensor_specs:
@@ -77,7 +104,6 @@ interoceptor_spec:
spec->sensorType = $1; spec->sensorType = $1;
DeviceManager::interoceptorDeviceSpecs.push_back(std::move(spec)); DeviceManager::interoceptorDeviceSpecs.push_back(std::move(spec));
DeviceManager::senseDeviceSpecs.push_back(*spec);
delete $3; delete $3;
} }
; ;
@@ -89,7 +115,6 @@ extrospector_spec:
spec->sensorType = $1; spec->sensorType = $1;
DeviceManager::extrospectorDeviceSpecs.push_back(std::move(spec)); DeviceManager::extrospectorDeviceSpecs.push_back(std::move(spec));
DeviceManager::senseDeviceSpecs.push_back(*spec);
delete $3; delete $3;
} }
; ;