Skip to content

Commit

Permalink
Store pointer to group instead of string
Browse files Browse the repository at this point in the history
  • Loading branch information
rzblue committed Oct 21, 2024
1 parent 7e0248c commit 2c9ad83
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions wpilibc/src/main/native/cpp/Alert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Alert::Alert(std::string_view text, AlertType type)
: Alert("Alerts", text, type) {}

Alert::Alert(std::string_view group, std::string_view text, AlertType type)
: m_type(type), m_text(text), m_group{group} {}
: m_type(type), m_text(text), m_group{&GetGroupSendable(group)} {}

Alert::~Alert() {
Set(false);
Expand All @@ -48,11 +48,9 @@ void Alert::Set(bool active) {

if (active) {
m_activeStartTime = frc::RobotController::GetFPGATime();
GetGroupSendable(m_group).GetSetForType(m_type).emplace(m_activeStartTime,
m_text);
m_group->GetSetForType(m_type).emplace(m_activeStartTime, m_text);
} else {
GetGroupSendable(m_group).GetSetForType(m_type).erase(
{m_activeStartTime, m_text});
m_group->GetSetForType(m_type).erase({m_activeStartTime, m_text});
}
m_active = active;
}
Expand All @@ -63,7 +61,7 @@ void Alert::SetText(std::string_view text) {
}

if (m_active) {
auto set = GetGroupSendable(m_group).GetSetForType(m_type);
auto set = m_group->GetSetForType(m_type);
auto iter = set.find({m_activeStartTime, m_text});
auto hint = set.erase(iter);
set.emplace_hint(hint, m_activeStartTime, m_text);
Expand Down
2 changes: 1 addition & 1 deletion wpilibc/src/main/native/include/frc/Alert.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class Alert {

AlertType m_type;
std::string m_text;
std::string m_group;
SendableAlerts* m_group;

bool m_active = false;
uint64_t m_activeStartTime;
Expand Down

0 comments on commit 2c9ad83

Please sign in to comment.