Skip to content

Commit af80a13

Browse files
committed
Bump boards, use std::string_view instead of full strings
1 parent 14d0027 commit af80a13

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

OpenFIREmain/OpenFIREprefs.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ int OF_Prefs::SaveProfiles()
7676
if(pair.second == OF_Const::profCurrent) {
7777
if(!currentProfLogged) {
7878
// only write string and profile num
79-
prefsFile.write((const uint8_t*)pair.first.c_str(), pair.first.length()+1);
79+
prefsFile.write((const uint8_t*)pair.first.data(), pair.first.length()+1);
8080
prefsFile.write((uint8_t)currentProfile);
8181
currentProfLogged = true;
8282
}
8383
} else {
8484
// write data type:
85-
prefsFile.write((const uint8_t*)pair.first.c_str(), pair.first.length()+1);
85+
prefsFile.write((const uint8_t*)pair.first.data(), pair.first.length()+1);
8686
// Append profile number:
8787
prefsFile.write((uint8_t*)&i, 1);
8888

@@ -108,12 +108,12 @@ int OF_Prefs::SaveProfiles()
108108
} else return Error_Write;
109109
}
110110

111-
int OF_Prefs::SaveToPtr(File prefsFile, void *dataPtr, const std::unordered_map<std::string, int> &mapPtr, const size_t &dataSize)
111+
int OF_Prefs::SaveToPtr(File prefsFile, void *dataPtr, const std::unordered_map<std::string_view, int> &mapPtr, const size_t &dataSize)
112112
{
113113
if(prefsFile) {
114114
for(auto &pair : mapPtr) {
115115
if((pair.second >= 0 && dataPtr != backupButtonDesc) || dataPtr == backupButtonDesc && pair.second >= 0 && pair.second < ButtonCount) {
116-
prefsFile.write((const uint8_t*)pair.first.c_str(), pair.first.length()+1);
116+
prefsFile.write((const uint8_t*)pair.first.data(), pair.first.length()+1);
117117
prefsFile.write((uint8_t)dataSize);
118118
prefsFile.write((uint8_t*)dataPtr + (dataSize * pair.second), dataSize);
119119
}
@@ -124,7 +124,7 @@ int OF_Prefs::SaveToPtr(File prefsFile, void *dataPtr, const std::unordered_map<
124124
} else return Error_NoData;
125125
}
126126

127-
int OF_Prefs::LoadToPtr(File prefsFile, void *dataPtr, const std::unordered_map<std::string, int> &mapPtr)
127+
int OF_Prefs::LoadToPtr(File prefsFile, void *dataPtr, const std::unordered_map<std::string_view, int> &mapPtr)
128128
{
129129
if(prefsFile) {
130130
char buf[32];

OpenFIREmain/OpenFIREprefs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ class OF_Prefs
140140

141141
/// @brief Generic saving method using provided pointers to a block of data and its associated string map for lookups
142142
/// @return An error code from Errors_e
143-
static int SaveToPtr(File, void*, const std::unordered_map<std::string, int>&, const size_t&);
143+
static int SaveToPtr(File, void*, const std::unordered_map<std::string_view, int>&, const size_t&);
144144

145145
/// @brief Generic loading method using provided pointers to a block of data and its associated string map for lookups
146146
/// @return An error code from Errors_e
147-
static int LoadToPtr(File, void*, const std::unordered_map<std::string, int>&);
147+
static int LoadToPtr(File, void*, const std::unordered_map<std::string_view, int>&);
148148

149149
/// @brief Load preferences
150150
/// @return An error code from Errors_e

OpenFIREmain/OpenFIREserial.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,14 +1125,14 @@ void OF_Serial::SerialProcessingDocked()
11251125
}
11261126
}
11271127

1128-
void OF_Serial::SerialBatchSend(void *dataPtr, const std::unordered_map<std::string, int> &mapPtr, const size_t &dataSize, const int &profNum)
1128+
void OF_Serial::SerialBatchSend(void *dataPtr, const std::unordered_map<std::string_view, int> &mapPtr, const size_t &dataSize, const int &profNum)
11291129
{
11301130
size_t pos;
11311131
bool profNumSent = false;
11321132
for(auto &pair : mapPtr) {
11331133
if(pair.second >= 0) {
11341134
pos = 0;
1135-
strcpy(&TXbuf[pos], pair.first.c_str());
1135+
strcpy(&TXbuf[pos], pair.first.data());
11361136
pos += pair.first.length()+1;
11371137
if(&mapPtr == &OF_Prefs::OFPresets.profSettingTypes_Strings) {
11381138
if(pair.second == OF_Const::profCurrent) {
@@ -1184,7 +1184,7 @@ void OF_Serial::SerialBatchSend(void *dataPtr, const std::unordered_map<std::str
11841184
}
11851185
}
11861186

1187-
void OF_Serial::SerialBatchRecv(const char *bufPtr, void *dataPtr, const std::unordered_map<std::string, int> &mapPtr, const size_t &dataSize, const size_t &rxDatSize, const size_t &rxBufSize)
1187+
void OF_Serial::SerialBatchRecv(const char *bufPtr, void *dataPtr, const std::unordered_map<std::string_view, int> &mapPtr, const size_t &dataSize, const size_t &rxDatSize, const size_t &rxBufSize)
11881188
{
11891189
if(mapPtr.count(bufPtr)) {
11901190
if(&mapPtr == &OF_Prefs::OFPresets.profSettingTypes_Strings && mapPtr.at(bufPtr) == OF_Const::profCurrent) {

OpenFIREmain/OpenFIREserial.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ class OF_Serial
2323
static void SerialProcessingDocked();
2424

2525
/// @brief Generic method for sending data over Serial to connected host
26-
static void SerialBatchSend(void*, const std::unordered_map<std::string, int> &, const size_t&, const int& = -1);
26+
static void SerialBatchSend(void*, const std::unordered_map<std::string_view, int> &, const size_t&, const int& = -1);
2727

2828
/// @brief Generic method for reading commit data over Serial from connected host
29-
static void SerialBatchRecv(const char*, void*, const std::unordered_map<std::string, int> &, const size_t&, const size_t&, const size_t&);
29+
static void SerialBatchRecv(const char*, void*, const std::unordered_map<std::string_view, int> &, const size_t&, const size_t&, const size_t&);
3030

3131
// Main routine that prints information to connected serial monitor when the gun enters Pause Mode.
3232
static void PrintResults();

OpenFIREmain/boards

0 commit comments

Comments
 (0)