Use std::string_view and fmtlib across all libraries (#3402)

- Twine, StringRef, Format, and NativeFormatting have been removed
- Logging now uses fmtlib style formatting
- Nearly all uses of wpi::outs/errs have been replaced with fmt::print() or
std::puts()/std::fputs() (for unformatted strings).
- A wpi/fmt/raw_ostream.h header has been added to enable
fmt::print() with wpi::raw_ostream
This commit is contained in:
Peter Johnson
2021-06-06 16:13:58 -07:00
committed by GitHub
parent 4f1cecb8e7
commit b2c3b2dd8e
441 changed files with 5061 additions and 9749 deletions

View File

@@ -48,7 +48,7 @@ void glass::DisplayAnalogInput(AnalogInputModel* model, int index) {
}
void glass::DisplayAnalogInputs(AnalogInputsModel* model,
wpi::StringRef noneMsg) {
std::string_view noneMsg) {
ImGui::Text("(Use Ctrl+Click to edit value)");
bool hasAny = false;
bool first = true;
@@ -65,6 +65,6 @@ void glass::DisplayAnalogInputs(AnalogInputsModel* model,
hasAny = true;
});
if (!hasAny && !noneMsg.empty()) {
ImGui::TextUnformatted(noneMsg.begin(), noneMsg.end());
ImGui::TextUnformatted(noneMsg.data(), noneMsg.data() + noneMsg.size());
}
}

View File

@@ -104,7 +104,7 @@ void glass::DisplayDIO(DIOModel* model, int index, bool outputsEnabled) {
}
void glass::DisplayDIOs(DIOsModel* model, bool outputsEnabled,
wpi::StringRef noneMsg) {
std::string_view noneMsg) {
bool hasAny = false;
ImGui::PushItemWidth(ImGui::GetFontSize() * 8);
@@ -116,6 +116,6 @@ void glass::DisplayDIOs(DIOsModel* model, bool outputsEnabled,
});
ImGui::PopItemWidth();
if (!hasAny && !noneMsg.empty()) {
ImGui::TextUnformatted(noneMsg.begin(), noneMsg.end());
ImGui::TextUnformatted(noneMsg.data(), noneMsg.data() + noneMsg.size());
}
}

View File

@@ -4,6 +4,7 @@
#include "glass/hardware/Encoder.h"
#include <fmt/format.h>
#include <imgui.h>
#include "glass/Context.h"
@@ -11,8 +12,8 @@
using namespace glass;
void EncoderModel::SetName(const wpi::Twine& name) {
if (name.str().empty()) {
void EncoderModel::SetName(std::string_view name) {
if (name.empty()) {
if (auto distancePerPulse = GetDistancePerPulseData()) {
distancePerPulse->SetName("");
}
@@ -33,22 +34,22 @@ void EncoderModel::SetName(const wpi::Twine& name) {
}
} else {
if (auto distancePerPulse = GetDistancePerPulseData()) {
distancePerPulse->SetName(name + " Distance/Count");
distancePerPulse->SetName(fmt::format("{} Distance/Count", name));
}
if (auto count = GetCountData()) {
count->SetName(name + " Count");
count->SetName(fmt::format("{} Count", name));
}
if (auto period = GetPeriodData()) {
period->SetName(name + " Period");
period->SetName(fmt::format("{} Period", name));
}
if (auto direction = GetDirectionData()) {
direction->SetName(name + " Direction");
direction->SetName(fmt::format("{} Direction", name));
}
if (auto distance = GetDistanceData()) {
distance->SetName(name + " Distance");
distance->SetName(fmt::format("{} Distance", name));
}
if (auto rate = GetRateData()) {
rate->SetName(name + " Rate");
rate->SetName(fmt::format("{} Rate", name));
}
}
}
@@ -153,7 +154,7 @@ void glass::DisplayEncoder(EncoderModel* model) {
ImGui::PopItemWidth();
}
void glass::DisplayEncoders(EncodersModel* model, wpi::StringRef noneMsg) {
void glass::DisplayEncoders(EncodersModel* model, std::string_view noneMsg) {
bool hasAny = false;
model->ForEachEncoder([&](EncoderModel& encoder, int i) {
hasAny = true;
@@ -162,6 +163,6 @@ void glass::DisplayEncoders(EncodersModel* model, wpi::StringRef noneMsg) {
PopID();
});
if (!hasAny && !noneMsg.empty()) {
ImGui::TextUnformatted(noneMsg.begin(), noneMsg.end());
ImGui::TextUnformatted(noneMsg.data(), noneMsg.data() + noneMsg.size());
}
}

View File

@@ -83,7 +83,7 @@ bool glass::DisplayPCMSolenoids(PCMModel* model, int index,
}
void glass::DisplayPCMsSolenoids(PCMsModel* model, bool outputsEnabled,
wpi::StringRef noneMsg) {
std::string_view noneMsg) {
bool hasAny = false;
model->ForEachPCM([&](PCMModel& pcm, int i) {
PushID(i);
@@ -93,7 +93,7 @@ void glass::DisplayPCMsSolenoids(PCMsModel* model, bool outputsEnabled,
PopID();
});
if (!hasAny && !noneMsg.empty()) {
ImGui::TextUnformatted(noneMsg.begin(), noneMsg.end());
ImGui::TextUnformatted(noneMsg.data(), noneMsg.data() + noneMsg.size());
}
}

View File

@@ -79,7 +79,7 @@ void glass::DisplayPDP(PDPModel* model, int index) {
}
}
void glass::DisplayPDPs(PDPsModel* model, wpi::StringRef noneMsg) {
void glass::DisplayPDPs(PDPsModel* model, std::string_view noneMsg) {
bool hasAny = false;
model->ForEachPDP([&](PDPModel& pdp, int i) {
hasAny = true;
@@ -88,6 +88,6 @@ void glass::DisplayPDPs(PDPsModel* model, wpi::StringRef noneMsg) {
PopID();
});
if (!hasAny && !noneMsg.empty()) {
ImGui::TextUnformatted(noneMsg.begin(), noneMsg.end());
ImGui::TextUnformatted(noneMsg.data(), noneMsg.data() + noneMsg.size());
}
}

View File

@@ -41,7 +41,7 @@ void glass::DisplayPWM(PWMModel* model, int index, bool outputsEnabled) {
}
void glass::DisplayPWMs(PWMsModel* model, bool outputsEnabled,
wpi::StringRef noneMsg) {
std::string_view noneMsg) {
bool hasAny = false;
bool first = true;
model->ForEachPWM([&](PWMModel& pwm, int i) {
@@ -58,6 +58,6 @@ void glass::DisplayPWMs(PWMsModel* model, bool outputsEnabled,
PopID();
});
if (!hasAny && !noneMsg.empty()) {
ImGui::TextUnformatted(noneMsg.begin(), noneMsg.end());
ImGui::TextUnformatted(noneMsg.data(), noneMsg.data() + noneMsg.size());
}
}

View File

@@ -60,7 +60,7 @@ void glass::DisplayRelay(RelayModel* model, int index, bool outputsEnabled) {
}
void glass::DisplayRelays(RelaysModel* model, bool outputsEnabled,
wpi::StringRef noneMsg) {
std::string_view noneMsg) {
bool hasAny = false;
bool first = true;
model->ForEachRelay([&](RelayModel& relay, int i) {
@@ -77,6 +77,6 @@ void glass::DisplayRelays(RelaysModel* model, bool outputsEnabled,
PopID();
});
if (!hasAny && !noneMsg.empty()) {
ImGui::TextUnformatted(noneMsg.begin(), noneMsg.end());
ImGui::TextUnformatted(noneMsg.data(), noneMsg.data() + noneMsg.size());
}
}