mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[glass] Fix compilation errors from C++23 clang (#8008)
This commit is contained in:
@@ -30,80 +30,15 @@ static void ConvertColor(std::string_view in, ImU32* out) {
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
class NTMechanismObjectModel;
|
||||
|
||||
class NTMechanismGroupImpl final {
|
||||
public:
|
||||
NTMechanismGroupImpl(nt::NetworkTableInstance inst, std::string_view path,
|
||||
std::string_view name)
|
||||
: m_inst{inst}, m_path{path}, m_name{name} {}
|
||||
|
||||
const char* GetName() const { return m_name.c_str(); }
|
||||
void ForEachObject(wpi::function_ref<void(MechanismObjectModel& model)> func);
|
||||
|
||||
void NTUpdate(const nt::Event& event, std::string_view name);
|
||||
|
||||
protected:
|
||||
nt::NetworkTableInstance m_inst;
|
||||
std::string m_path;
|
||||
std::string m_name;
|
||||
std::vector<std::unique_ptr<NTMechanismObjectModel>> m_objects;
|
||||
};
|
||||
|
||||
class NTMechanismObjectModel final : public MechanismObjectModel {
|
||||
public:
|
||||
NTMechanismObjectModel(nt::NetworkTableInstance inst, std::string_view path,
|
||||
std::string_view name)
|
||||
: m_group{inst, path, name},
|
||||
m_typeTopic{inst.GetTopic(fmt::format("{}/.type", path))},
|
||||
m_colorTopic{inst.GetTopic(fmt::format("{}/color", path))},
|
||||
m_weightTopic{inst.GetTopic(fmt::format("{}/weight", path))},
|
||||
m_angleTopic{inst.GetTopic(fmt::format("{}/angle", path))},
|
||||
m_lengthTopic{inst.GetTopic(fmt::format("{}/length", path))} {}
|
||||
|
||||
const char* GetName() const final { return m_group.GetName(); }
|
||||
void ForEachObject(
|
||||
wpi::function_ref<void(MechanismObjectModel& model)> func) final {
|
||||
m_group.ForEachObject(func);
|
||||
}
|
||||
|
||||
const char* GetType() const final { return m_typeValue.c_str(); }
|
||||
ImU32 GetColor() const final { return m_colorValue; }
|
||||
double GetWeight() const final { return m_weightValue; }
|
||||
frc::Rotation2d GetAngle() const final { return m_angleValue; }
|
||||
units::meter_t GetLength() const final { return m_lengthValue; }
|
||||
|
||||
bool NTUpdate(const nt::Event& event, std::string_view name);
|
||||
|
||||
private:
|
||||
NTMechanismGroupImpl m_group;
|
||||
|
||||
nt::Topic m_typeTopic;
|
||||
nt::Topic m_colorTopic;
|
||||
nt::Topic m_weightTopic;
|
||||
nt::Topic m_angleTopic;
|
||||
nt::Topic m_lengthTopic;
|
||||
|
||||
std::string m_typeValue;
|
||||
ImU32 m_colorValue = IM_COL32_WHITE;
|
||||
double m_weightValue = 1.0;
|
||||
frc::Rotation2d m_angleValue;
|
||||
units::meter_t m_lengthValue = 0.0_m;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
void NTMechanismGroupImpl::ForEachObject(
|
||||
void NTMechanism2DModel::NTMechanismGroupImpl::ForEachObject(
|
||||
wpi::function_ref<void(MechanismObjectModel& model)> func) {
|
||||
for (auto&& obj : m_objects) {
|
||||
func(*obj);
|
||||
}
|
||||
}
|
||||
|
||||
void NTMechanismGroupImpl::NTUpdate(const nt::Event& event,
|
||||
std::string_view name) {
|
||||
void NTMechanism2DModel::NTMechanismGroupImpl::NTUpdate(const nt::Event& event,
|
||||
std::string_view name) {
|
||||
if (name.empty()) {
|
||||
return;
|
||||
}
|
||||
@@ -140,8 +75,8 @@ void NTMechanismGroupImpl::NTUpdate(const nt::Event& event,
|
||||
}
|
||||
}
|
||||
|
||||
bool NTMechanismObjectModel::NTUpdate(const nt::Event& event,
|
||||
std::string_view childName) {
|
||||
bool NTMechanism2DModel::NTMechanismObjectModel::NTUpdate(
|
||||
const nt::Event& event, std::string_view childName) {
|
||||
if (auto info = event.GetTopicInfo()) {
|
||||
if (info->topic == m_typeTopic.GetHandle()) {
|
||||
if (event.flags & nt::EventFlags::kUnpublish) {
|
||||
@@ -181,31 +116,6 @@ bool NTMechanismObjectModel::NTUpdate(const nt::Event& event,
|
||||
return false;
|
||||
}
|
||||
|
||||
class NTMechanism2DModel::RootModel final : public MechanismRootModel {
|
||||
public:
|
||||
RootModel(nt::NetworkTableInstance inst, std::string_view path,
|
||||
std::string_view name)
|
||||
: m_group{inst, path, name},
|
||||
m_xTopic{inst.GetTopic(fmt::format("{}/x", path))},
|
||||
m_yTopic{inst.GetTopic(fmt::format("{}/y", path))} {}
|
||||
|
||||
const char* GetName() const final { return m_group.GetName(); }
|
||||
void ForEachObject(
|
||||
wpi::function_ref<void(MechanismObjectModel& model)> func) final {
|
||||
m_group.ForEachObject(func);
|
||||
}
|
||||
|
||||
bool NTUpdate(const nt::Event& event, std::string_view childName);
|
||||
|
||||
frc::Translation2d GetPosition() const override { return m_pos; };
|
||||
|
||||
private:
|
||||
NTMechanismGroupImpl m_group;
|
||||
nt::Topic m_xTopic;
|
||||
nt::Topic m_yTopic;
|
||||
frc::Translation2d m_pos;
|
||||
};
|
||||
|
||||
bool NTMechanism2DModel::RootModel::NTUpdate(const nt::Event& event,
|
||||
std::string_view childName) {
|
||||
if (auto info = event.GetTopicInfo()) {
|
||||
|
||||
Reference in New Issue
Block a user