Skip to content

Commit

Permalink
[wpiutil] SendableBuilder: Add PublishConst methods (wpilibsuite#5158)
Browse files Browse the repository at this point in the history
  • Loading branch information
Starlight220 authored and calcmogul committed Oct 9, 2023
1 parent 9e05ab8 commit eabf2f1
Show file tree
Hide file tree
Showing 5 changed files with 385 additions and 0 deletions.
67 changes: 67 additions & 0 deletions wpilibc/src/main/native/cpp/smartdashboard/SendableBuilderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,76 +141,133 @@ void SendableBuilderImpl::AddPropertyImpl(Topic topic, Getter getter,
m_properties.emplace_back(std::move(prop));
}

template <typename Topic, typename Value>
void SendableBuilderImpl::PublishConstImpl(Topic topic, Value value) {
auto prop = std::make_unique<PropertyImpl<Topic>>();
prop->pub = topic.Publish();
prop->pub.Set(value);
m_properties.emplace_back(std::move(prop));
}

void SendableBuilderImpl::AddBooleanProperty(std::string_view key,
std::function<bool()> getter,
std::function<void(bool)> setter) {
AddPropertyImpl(m_table->GetBooleanTopic(key), std::move(getter),
std::move(setter));
}

void SendableBuilderImpl::PublishConstBoolean(std::string_view key,
bool value) {
PublishConstImpl(m_table->GetBooleanTopic(key), value);
}

void SendableBuilderImpl::AddIntegerProperty(
std::string_view key, std::function<int64_t()> getter,
std::function<void(int64_t)> setter) {
AddPropertyImpl(m_table->GetIntegerTopic(key), std::move(getter),
std::move(setter));
}

void SendableBuilderImpl::PublishConstInteger(std::string_view key,
int64_t value) {
PublishConstImpl(m_table->GetIntegerTopic(key), value);
}

void SendableBuilderImpl::AddFloatProperty(std::string_view key,
std::function<float()> getter,
std::function<void(float)> setter) {
AddPropertyImpl(m_table->GetFloatTopic(key), std::move(getter),
std::move(setter));
}

void SendableBuilderImpl::PublishConstFloat(std::string_view key, float value) {
PublishConstImpl(m_table->GetFloatTopic(key), value);
}

void SendableBuilderImpl::AddDoubleProperty(
std::string_view key, std::function<double()> getter,
std::function<void(double)> setter) {
AddPropertyImpl(m_table->GetDoubleTopic(key), std::move(getter),
std::move(setter));
}

void SendableBuilderImpl::PublishConstDouble(std::string_view key,
double value) {
PublishConstImpl(m_table->GetDoubleTopic(key), value);
}

void SendableBuilderImpl::AddStringProperty(
std::string_view key, std::function<std::string()> getter,
std::function<void(std::string_view)> setter) {
AddPropertyImpl(m_table->GetStringTopic(key), std::move(getter),
std::move(setter));
}

void SendableBuilderImpl::PublishConstString(std::string_view key,
std::string_view value) {
PublishConstImpl(m_table->GetStringTopic(key), value);
}

void SendableBuilderImpl::AddBooleanArrayProperty(
std::string_view key, std::function<std::vector<int>()> getter,
std::function<void(std::span<const int>)> setter) {
AddPropertyImpl(m_table->GetBooleanArrayTopic(key), std::move(getter),
std::move(setter));
}

void SendableBuilderImpl::PublishConstBooleanArray(std::string_view key,
std::span<const int> value) {
PublishConstImpl(m_table->GetBooleanArrayTopic(key), value);
}

void SendableBuilderImpl::AddIntegerArrayProperty(
std::string_view key, std::function<std::vector<int64_t>()> getter,
std::function<void(std::span<const int64_t>)> setter) {
AddPropertyImpl(m_table->GetIntegerArrayTopic(key), std::move(getter),
std::move(setter));
}

void SendableBuilderImpl::PublishConstIntegerArray(
std::string_view key, std::span<const int64_t> value) {
PublishConstImpl(m_table->GetIntegerArrayTopic(key), value);
}

void SendableBuilderImpl::AddFloatArrayProperty(
std::string_view key, std::function<std::vector<float>()> getter,
std::function<void(std::span<const float>)> setter) {
AddPropertyImpl(m_table->GetFloatArrayTopic(key), std::move(getter),
std::move(setter));
}

void SendableBuilderImpl::PublishConstFloatArray(std::string_view key,
std::span<const float> value) {
PublishConstImpl(m_table->GetFloatArrayTopic(key), value);
}

void SendableBuilderImpl::AddDoubleArrayProperty(
std::string_view key, std::function<std::vector<double>()> getter,
std::function<void(std::span<const double>)> setter) {
AddPropertyImpl(m_table->GetDoubleArrayTopic(key), std::move(getter),
std::move(setter));
}

void SendableBuilderImpl::PublishConstDoubleArray(
std::string_view key, std::span<const double> value) {
PublishConstImpl(m_table->GetDoubleArrayTopic(key), value);
}

void SendableBuilderImpl::AddStringArrayProperty(
std::string_view key, std::function<std::vector<std::string>()> getter,
std::function<void(std::span<const std::string>)> setter) {
AddPropertyImpl(m_table->GetStringArrayTopic(key), std::move(getter),
std::move(setter));
}

void SendableBuilderImpl::PublishConstStringArray(
std::string_view key, std::span<const std::string> value) {
PublishConstImpl(m_table->GetStringArrayTopic(key), value);
}

void SendableBuilderImpl::AddRawProperty(
std::string_view key, std::string_view typeString,
std::function<std::vector<uint8_t>()> getter,
Expand All @@ -235,6 +292,16 @@ void SendableBuilderImpl::AddRawProperty(
m_properties.emplace_back(std::move(prop));
}

void SendableBuilderImpl::PublishConstRaw(std::string_view key,
std::string_view typeString,
std::span<const uint8_t> value) {
auto topic = m_table->GetRawTopic(key);
auto prop = std::make_unique<PropertyImpl<nt::RawTopic>>();
prop->pub = topic.Publish(typeString);
prop->pub.Set(value);
m_properties.emplace_back(std::move(prop));
}

template <typename T, size_t Size, typename Topic, typename Getter,
typename Setter>
void SendableBuilderImpl::AddSmallPropertyImpl(Topic topic, Getter getter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,44 +96,73 @@ class SendableBuilderImpl : public nt::NTSendableBuilder {
void AddBooleanProperty(std::string_view key, std::function<bool()> getter,
std::function<void(bool)> setter) override;

void PublishConstBoolean(std::string_view key, bool value) override;

void AddIntegerProperty(std::string_view key, std::function<int64_t()> getter,
std::function<void(int64_t)> setter) override;

void PublishConstInteger(std::string_view key, int64_t value) override;

void AddFloatProperty(std::string_view key, std::function<float()> getter,
std::function<void(float)> setter) override;

void PublishConstFloat(std::string_view key, float value) override;

void AddDoubleProperty(std::string_view key, std::function<double()> getter,
std::function<void(double)> setter) override;

void PublishConstDouble(std::string_view key, double value) override;

void AddStringProperty(std::string_view key,
std::function<std::string()> getter,
std::function<void(std::string_view)> setter) override;

void PublishConstString(std::string_view key,
std::string_view value) override;

void AddBooleanArrayProperty(
std::string_view key, std::function<std::vector<int>()> getter,
std::function<void(std::span<const int>)> setter) override;

void PublishConstBooleanArray(std::string_view key,
std::span<const int> value) override;

void AddIntegerArrayProperty(
std::string_view key, std::function<std::vector<int64_t>()> getter,
std::function<void(std::span<const int64_t>)> setter) override;

void PublishConstIntegerArray(std::string_view key,
std::span<const int64_t> value) override;

void AddFloatArrayProperty(
std::string_view key, std::function<std::vector<float>()> getter,
std::function<void(std::span<const float>)> setter) override;

void PublishConstFloatArray(std::string_view key,
std::span<const float> value) override;

void AddDoubleArrayProperty(
std::string_view key, std::function<std::vector<double>()> getter,
std::function<void(std::span<const double>)> setter) override;

void PublishConstDoubleArray(std::string_view key,
std::span<const double> value) override;

void AddStringArrayProperty(
std::string_view key, std::function<std::vector<std::string>()> getter,
std::function<void(std::span<const std::string>)> setter) override;

void PublishConstStringArray(std::string_view key,
std::span<const std::string> value) override;

void AddRawProperty(
std::string_view key, std::string_view typeString,
std::function<std::vector<uint8_t>()> getter,
std::function<void(std::span<const uint8_t>)> setter) override;

void PublishConstRaw(std::string_view key, std::string_view typeString,
std::span<const uint8_t> value) override;

void AddSmallStringProperty(
std::string_view key,
std::function<std::string_view(wpi::SmallVectorImpl<char>& buf)> getter,
Expand Down Expand Up @@ -198,6 +227,9 @@ class SendableBuilderImpl : public nt::NTSendableBuilder {
template <typename Topic, typename Getter, typename Setter>
void AddPropertyImpl(Topic topic, Getter getter, Setter setter);

template <typename Topic, typename Value>
void PublishConstImpl(Topic topic, Value value);

template <typename T, size_t Size, typename Topic, typename Getter,
typename Setter>
void AddSmallPropertyImpl(Topic topic, Getter getter, Setter setter);
Expand Down
Loading

0 comments on commit eabf2f1

Please sign in to comment.