Skip to content

Commit 43281b8

Browse files
committed
Fixed clangd warnings.
1 parent 4aaabe2 commit 43281b8

File tree

7 files changed

+33
-40
lines changed

7 files changed

+33
-40
lines changed

include/RhythmGameUtilities/Audio.hpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <algorithm>
34
#include <cmath>
45

56
#ifdef _WIN32
@@ -23,10 +24,10 @@ extern "C"
2324
* @public
2425
*/
2526

26-
PACKAGE_API int **ConvertSamplesToWaveform(float *samples, int size,
27+
PACKAGE_API int **ConvertSamplesToWaveform(const float *samples, int size,
2728
int width, int height)
2829
{
29-
auto waveform = new int *[width];
30+
auto *waveform = new int *[width];
3031

3132
auto step = floor(size / width);
3233
auto amp = height / 2;
@@ -40,19 +41,12 @@ extern "C"
4041

4142
for (auto j = 0; j < step; j += 1)
4243
{
43-
auto index = static_cast<int>(x * step + j);
44+
auto index = static_cast<int>((x * step) + j);
4445

4546
auto datum = samples[index];
4647

47-
if (datum < min)
48-
{
49-
min = datum;
50-
}
51-
52-
if (datum > max)
53-
{
54-
max = datum;
55-
}
48+
min = std::min(datum, min);
49+
max = std::max(datum, max);
5650
}
5751

5852
auto minY = static_cast<int>((1 + min) * amp);

include/RhythmGameUtilities/Common.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ extern "C"
2626

2727
PACKAGE_API float Lerp(float a, float b, float t)
2828
{
29-
return (1 - t) * a + b * t;
29+
return ((1 - t) * a) + (b * t);
3030
}
3131

3232
/**
@@ -82,7 +82,7 @@ inline std::vector<std::string> Split(const char *contents,
8282
}
8383

8484
inline std::vector<std::string> FindAllMatches(const char *contents,
85-
std::regex pattern)
85+
const std::regex &pattern)
8686
{
8787
auto currentMatch =
8888
std::cregex_iterator(contents, contents + strlen(contents), pattern);
@@ -103,14 +103,14 @@ inline std::vector<std::string> FindAllMatches(const char *contents,
103103
}
104104

105105
inline std::vector<std::string> FindMatchGroups(const char *contents,
106-
std::regex pattern)
106+
const std::regex &pattern)
107107
{
108108
auto currentMatch =
109109
std::cregex_iterator(contents, contents + strlen(contents), pattern);
110110

111111
auto matches = std::vector<std::string>();
112112

113-
auto match = *currentMatch;
113+
const auto &match = *currentMatch;
114114

115115
for (auto i = 0; i < match.size(); i += 1)
116116
{

include/RhythmGameUtilities/File.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ inline std::vector<uint8_t> ReadBytesFromFile(const char *path)
2222

2323
if (!file.is_open())
2424
{
25-
std::cerr << "Failed to open " << path << "." << std::endl;
25+
std::cerr << "Failed to open " << path << ".\n";
2626
}
2727

2828
auto fileSize = file.tellg();
@@ -49,13 +49,13 @@ inline std::string ReadStringFromFile(const char *path)
4949

5050
if (!file)
5151
{
52-
std::cerr << "Failed to open " << path << "." << std::endl;
52+
std::cerr << "Failed to open " << path << ".\n";
5353

5454
return "";
5555
}
5656

57-
return std::string((std::istreambuf_iterator<char>(file)),
58-
std::istreambuf_iterator<char>());
57+
return {(std::istreambuf_iterator<char>(file)),
58+
std::istreambuf_iterator<char>()};
5959
}
6060

6161
} // namespace RhythmGameUtilities

include/RhythmGameUtilities/Parsers.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ ParseSectionsFromChart(const char *contents)
7676
std::regex_replace(values[k], std::regex("^\"|\"$"), "");
7777
}
7878

79-
items.push_back(std::make_pair(key, values));
79+
items.emplace_back(key, values);
8080
}
8181

8282
sections.insert({parts[1].c_str(), items});

include/RhythmGameUtilities/ParsersInternal.hpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,33 +22,33 @@ extern "C"
2222

2323
*outSize = internalSections.size();
2424

25-
auto sections = (ChartSectionInternal *)malloc(
25+
auto *sections = (ChartSectionInternal *)malloc(
2626
internalSections.size() * sizeof(ChartSectionInternal));
2727

2828
int i = 0;
2929

30-
for (auto section = internalSections.begin();
31-
section != internalSections.end(); section++)
30+
for (auto &internalSection : internalSections)
3231
{
33-
auto nameLength = section->first.size() + 1;
32+
auto nameLength = internalSection.first.size() + 1;
3433
sections[i].name = (char *)malloc(nameLength);
35-
strncpy(sections[i].name, section->first.c_str(), nameLength - 1);
34+
strncpy(sections[i].name, internalSection.first.c_str(),
35+
nameLength - 1);
3636
sections[i].name[nameLength - 1] = '\0';
3737

3838
sections[i].lines = (KeyValuePairInternal *)malloc(
39-
section->second.size() * sizeof(KeyValuePairInternal));
39+
internalSection.second.size() * sizeof(KeyValuePairInternal));
4040

41-
sections[i].lineCount = section->second.size();
41+
sections[i].lineCount = internalSection.second.size();
4242

43-
for (auto j = 0; j < section->second.size(); j += 1)
43+
for (auto j = 0; j < internalSection.second.size(); j += 1)
4444
{
45-
auto keyLength = section->second[j].first.size() + 1;
45+
auto keyLength = internalSection.second[j].first.size() + 1;
4646
sections[i].lines[j].key = (char *)malloc(keyLength);
4747
strncpy(sections[i].lines[j].key,
48-
section->second[j].first.c_str(), keyLength - 1);
48+
internalSection.second[j].first.c_str(), keyLength - 1);
4949
sections[i].lines[j].key[keyLength - 1] = '\0';
5050

51-
auto values = section->second[j].second;
51+
auto values = internalSection.second[j].second;
5252

5353
for (auto k = 0; k < values.size(); k += 1)
5454
{

include/RhythmGameUtilities/Utilities.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ ConvertSecondsToTicks(float seconds, int resolution,
9595
*/
9696

9797
inline std::vector<std::tuple<int, int>>
98-
GenerateAdjacentKeyPairs(std::map<int, int> keyValuePairs)
98+
GenerateAdjacentKeyPairs(const std::map<int, int> &keyValuePairs)
9999
{
100100
auto adjacentKeyPairs = std::vector<std::tuple<int, int>>();
101101

@@ -110,16 +110,15 @@ GenerateAdjacentKeyPairs(std::map<int, int> keyValuePairs)
110110

111111
for (auto i = 0; i < sortedKeys.size() - 1; i += 1)
112112
{
113-
adjacentKeyPairs.push_back(
114-
std::make_tuple(sortedKeys[i], sortedKeys[i + 1]));
113+
adjacentKeyPairs.emplace_back(sortedKeys[i], sortedKeys[i + 1]);
115114
}
116115

117116
return adjacentKeyPairs;
118117
}
119118

120-
inline std::vector<BeatBar> CalculateBeatBars(std::vector<Tempo> tempoChanges,
121-
int resolution, int ts,
122-
bool includeHalfNotes)
119+
inline std::vector<BeatBar>
120+
CalculateBeatBars(const std::vector<Tempo> &tempoChanges, int resolution,
121+
int ts, bool includeHalfNotes)
123122
{
124123
std::vector<BeatBar> beatBars;
125124

@@ -146,7 +145,7 @@ inline std::vector<BeatBar> CalculateBeatBars(std::vector<Tempo> tempoChanges,
146145

147146
if (includeHalfNotes && tick != endTick)
148147
{
149-
beatBars.push_back({tick + resolution / 2, bpm});
148+
beatBars.push_back({tick + (resolution / 2), bpm});
150149
}
151150
}
152151
}

include/RhythmGameUtilities/UtilitiesInternal.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ extern "C"
5555

5656
*outSize = internalBeatBars.size();
5757

58-
auto beatBars =
58+
auto *beatBars =
5959
(BeatBar *)malloc(internalBeatBars.size() * sizeof(BeatBar));
6060

6161
for (auto i = 0; i < internalBeatBars.size(); i += 1)

0 commit comments

Comments
 (0)