Skip to content

Commit

Permalink
Fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterJohnson committed Dec 24, 2024
1 parent 0cbee59 commit b1f5f6c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 27 deletions.
2 changes: 2 additions & 0 deletions glass/src/lib/native/cpp/DataSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "glass/DataSource.h"

#include <string>

#include <fmt/format.h>

#include "glass/ContextInternal.h"
Expand Down
1 change: 1 addition & 0 deletions glass/src/lib/native/include/glass/DataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <string>
#include <string_view>
#include <utility>

#include <imgui.h>
#include <wpi/SmallVector.h>
Expand Down
2 changes: 2 additions & 0 deletions glass/src/libnt/native/cpp/NTFMS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include <stdint.h>

#include <utility>

#include <fmt/format.h>
#include <wpi/SmallVector.h>
#include <wpi/timestamp.h>
Expand Down
56 changes: 31 additions & 25 deletions glass/src/libnt/native/cpp/NetworkTables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include <algorithm>
#include <cinttypes>
#include <concepts>
#include <cstring>
#include <functional>
#include <initializer_list>
Expand Down Expand Up @@ -631,33 +630,40 @@ static void UpdateJsonValueSource(NetworkTablesModel& model,
}
}

template <typename T>
void NetworkTablesModel::ValueSource::UpdateDiscreteSource(
std::string_view name, T value, int64_t time) {
std::string_view name, bool value, int64_t time) {
valueChildren.clear();
if constexpr (std::same_as<T, bool>) {
if (!source || source->GetKind() != DataSource::kBoolean) {
source = std::make_unique<BooleanSource>(fmt::format("NT:{}", name));
}
static_cast<BooleanSource*>(source.get())->SetValue(value, time);
} else if constexpr (std::same_as<T, double>) {
if (!source || source->GetKind() != DataSource::kDouble) {
source = std::make_unique<DoubleSource>(fmt::format("NT:{}", name));
}
static_cast<DoubleSource*>(source.get())->SetValue(value, time);
} else if constexpr (std::same_as<T, float>) {
if (!source || source->GetKind() != DataSource::kFloat) {
source = std::make_unique<FloatSource>(fmt::format("NT:{}", name));
}
static_cast<FloatSource*>(source.get())->SetValue(value, time);
} else if constexpr (std::same_as<T, int64_t>) {
if (!source || source->GetKind() != DataSource::kInteger) {
source = std::make_unique<IntegerSource>(fmt::format("NT:{}", name));
}
static_cast<IntegerSource*>(source.get())->SetValue(value, time);
} else {
static_assert(false, "Unknown type");
if (!source || source->GetKind() != DataSource::kBoolean) {
source = std::make_unique<BooleanSource>(fmt::format("NT:{}", name));
}
static_cast<BooleanSource*>(source.get())->SetValue(value, time);
}

void NetworkTablesModel::ValueSource::UpdateDiscreteSource(
std::string_view name, float value, int64_t time) {
valueChildren.clear();
if (!source || source->GetKind() != DataSource::kFloat) {
source = std::make_unique<FloatSource>(fmt::format("NT:{}", name));
}
static_cast<FloatSource*>(source.get())->SetValue(value, time);
}

void NetworkTablesModel::ValueSource::UpdateDiscreteSource(
std::string_view name, double value, int64_t time) {
valueChildren.clear();
if (!source || source->GetKind() != DataSource::kDouble) {
source = std::make_unique<DoubleSource>(fmt::format("NT:{}", name));
}
static_cast<DoubleSource*>(source.get())->SetValue(value, time);
}

void NetworkTablesModel::ValueSource::UpdateDiscreteSource(
std::string_view name, int64_t value, int64_t time) {
valueChildren.clear();
if (!source || source->GetKind() != DataSource::kInteger) {
source = std::make_unique<IntegerSource>(fmt::format("NT:{}", name));
}
static_cast<IntegerSource*>(source.get())->SetValue(value, time);
}

template <bool IsBoolean, typename T, typename MakeValue>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ class NetworkTablesModel : public Model {
bool valueChildrenMap = false;

private:
template <typename T>
void UpdateDiscreteSource(std::string_view name, T value, int64_t time);
void UpdateDiscreteSource(std::string_view name, bool value, int64_t time);
void UpdateDiscreteSource(std::string_view name, float value, int64_t time);
void UpdateDiscreteSource(std::string_view name, double value,
int64_t time);
void UpdateDiscreteSource(std::string_view name, int64_t value,
int64_t time);

template <bool IsBoolean, typename T, typename MakeValue>
void UpdateDiscreteArray(std::string_view name, std::span<const T> arr,
Expand Down

0 comments on commit b1f5f6c

Please sign in to comment.