mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpiutil] SendableBuilder: Add PublishConst methods (#5158)
This commit is contained in:
@@ -141,6 +141,14 @@ 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) {
|
||||
@@ -148,6 +156,11 @@ void SendableBuilderImpl::AddBooleanProperty(std::string_view key,
|
||||
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) {
|
||||
@@ -155,6 +168,11 @@ void SendableBuilderImpl::AddIntegerProperty(
|
||||
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) {
|
||||
@@ -162,6 +180,10 @@ void SendableBuilderImpl::AddFloatProperty(std::string_view key,
|
||||
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) {
|
||||
@@ -169,6 +191,11 @@ void SendableBuilderImpl::AddDoubleProperty(
|
||||
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) {
|
||||
@@ -176,6 +203,11 @@ void SendableBuilderImpl::AddStringProperty(
|
||||
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) {
|
||||
@@ -183,6 +215,11 @@ void SendableBuilderImpl::AddBooleanArrayProperty(
|
||||
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) {
|
||||
@@ -190,6 +227,11 @@ void SendableBuilderImpl::AddIntegerArrayProperty(
|
||||
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) {
|
||||
@@ -197,6 +239,11 @@ void SendableBuilderImpl::AddFloatArrayProperty(
|
||||
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) {
|
||||
@@ -204,6 +251,11 @@ void SendableBuilderImpl::AddDoubleArrayProperty(
|
||||
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) {
|
||||
@@ -211,6 +263,11 @@ void SendableBuilderImpl::AddStringArrayProperty(
|
||||
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,
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user