Skip to content

Commit

Permalink
shrink header by moving as much to cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
rzblue committed Nov 1, 2024
1 parent 0375edc commit 129294c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 40 deletions.
35 changes: 33 additions & 2 deletions wpilibc/src/main/native/cpp/Alert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,54 @@

#include "frc/Alert.h"

#include <frc/RobotController.h>
#include <stdint.h>

#include <algorithm>
#include <set>
#include <string>
#include <utility>
#include <vector>

#include <fmt/format.h>
#include <networktables/NTSendable.h>
#include <networktables/NTSendableBuilder.h>
#include <wpi/StringMap.h>
#include <wpi/sendable/SendableHelper.h>
#include <wpi/sendable/SendableRegistry.h>

#include "frc/Errors.h"
#include "frc/RobotController.h"
#include "frc/smartdashboard/SmartDashboard.h"

using namespace frc;

class Alert::PublishedAlert {
public:
PublishedAlert(uint64_t timestamp, std::string_view text)
: timestamp{timestamp}, text{text} {}
uint64_t timestamp;
std::string text;
auto operator<=>(const PublishedAlert&) const = default;
};

class Alert::SendableAlerts : public nt::NTSendable,
public wpi::SendableHelper<SendableAlerts> {
public:
SendableAlerts();
void InitSendable(nt::NTSendableBuilder& builder) override;

/**
* Returns a reference to the set of active alerts for the given type.
* @param type the type
* @return reference to the set of active alerts for the type
*/
std::set<PublishedAlert>& GetActiveAlertsStorage(AlertType type);
const std::set<PublishedAlert>& GetActiveAlertsStorage(AlertType type) const;

private:
std::vector<std::string> GetStrings(AlertType type) const;
std::array<std::set<PublishedAlert>, 3> m_alerts;
};

// TODO: throw if matching (group, text, type) already constructed
Alert::Alert(std::string_view text, AlertType type)
: Alert("Alerts", text, type) {}
Expand Down
40 changes: 2 additions & 38 deletions wpilibc/src/main/native/include/frc/Alert.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,8 @@

#pragma once

#include <stdint.h>

#include <array>
#include <memory>
#include <set>
#include <string>
#include <vector>

#include <networktables/NTSendable.h>
#include <wpi/SmallVector.h>
#include <wpi/StringMap.h>
#include <wpi/sendable/SendableHelper.h>

namespace frc {

Expand Down Expand Up @@ -131,34 +121,8 @@ class Alert {
AlertType GetType() const { return m_type; }

private:
class PublishedAlert {
public:
PublishedAlert(uint64_t timestamp, std::string_view text)
: timestamp{timestamp}, text{text} {}
uint64_t timestamp;
std::string text;
auto operator<=>(const PublishedAlert&) const = default;
};

class SendableAlerts : public nt::NTSendable,
public wpi::SendableHelper<SendableAlerts> {
public:
SendableAlerts();
void InitSendable(nt::NTSendableBuilder& builder) override;

/**
* Returns a reference to the set of active alerts for the given type.
* @param type the type
* @return reference to the set of active alerts for the type
*/
std::set<PublishedAlert>& GetActiveAlertsStorage(AlertType type);
const std::set<PublishedAlert>& GetActiveAlertsStorage(
AlertType type) const;

private:
std::vector<std::string> GetStrings(AlertType type) const;
std::array<std::set<PublishedAlert>, 3> m_alerts;
};
class PublishedAlert;
class SendableAlerts;

AlertType m_type;
std::string m_text;
Expand Down

0 comments on commit 129294c

Please sign in to comment.