[CI] Format code according to conventions (#26138)

Format code according to conventions
This commit is contained in:
QMK Bot
2026-04-09 22:26:08 +10:00
committed by GitHub
parent 92c0e2cee1
commit 18ed7c6caf
3 changed files with 58 additions and 55 deletions
+52 -49
View File
@@ -2,65 +2,68 @@
// A simple ringbuffer holding Size elements of type T // A simple ringbuffer holding Size elements of type T
template <typename T, uint8_t Size> template <typename T, uint8_t Size>
class RingBuffer { class RingBuffer {
protected: protected:
T buf_[Size]; T buf_[Size];
uint8_t head_{0}, tail_{0}; uint8_t head_{0}, tail_{0};
public:
inline uint8_t nextPosition(uint8_t position) {
return (position + 1) % Size;
}
inline uint8_t prevPosition(uint8_t position) { public:
if (position == 0) { inline uint8_t nextPosition(uint8_t position) {
return Size - 1; return (position + 1) % Size;
}
return position - 1;
}
inline bool enqueue(const T &item) {
static_assert(Size > 1, "RingBuffer size must be > 1");
uint8_t next = nextPosition(head_);
if (next == tail_) {
// Full
return false;
} }
buf_[head_] = item; inline uint8_t prevPosition(uint8_t position) {
head_ = next; if (position == 0) {
return true; return Size - 1;
} }
return position - 1;
inline bool get(T &dest, bool commit = true) {
auto tail = tail_;
if (tail == head_) {
// No more data
return false;
} }
dest = buf_[tail]; inline bool enqueue(const T &item) {
tail = nextPosition(tail); static_assert(Size > 1, "RingBuffer size must be > 1");
uint8_t next = nextPosition(head_);
if (next == tail_) {
// Full
return false;
}
if (commit) { buf_[head_] = item;
tail_ = tail; head_ = next;
return true;
} }
return true;
}
inline bool empty() const { return head_ == tail_; } inline bool get(T &dest, bool commit = true) {
auto tail = tail_;
if (tail == head_) {
// No more data
return false;
}
inline uint8_t size() const { dest = buf_[tail];
int diff = head_ - tail_; tail = nextPosition(tail);
if (diff >= 0) {
return diff; if (commit) {
tail_ = tail;
}
return true;
} }
return Size + diff;
}
inline T& front() { inline bool empty() const {
return buf_[tail_]; return head_ == tail_;
} }
inline bool peek(T &item) { inline uint8_t size() const {
return get(item, false); int diff = head_ - tail_;
} if (diff >= 0) {
return diff;
}
return Size + diff;
}
inline T &front() {
return buf_[tail_];
}
inline bool peek(T &item) {
return get(item, false);
}
}; };
+5 -5
View File
@@ -19,21 +19,21 @@
#include <ostream> #include <ostream>
#include "gmock/gmock.h" #include "gmock/gmock.h"
bool operator==(const report_keyboard_t& lhs, const report_keyboard_t& rhs); bool operator==(const report_keyboard_t& lhs, const report_keyboard_t& rhs);
std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& value); std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& value);
class KeyboardReportMatcher : public testing::MatcherInterface<report_keyboard_t&> { class KeyboardReportMatcher : public testing::MatcherInterface<report_keyboard_t&> {
public: public:
KeyboardReportMatcher(const std::vector<uint8_t>& keys); KeyboardReportMatcher(const std::vector<uint8_t>& keys);
virtual bool MatchAndExplain(report_keyboard_t& report, testing::MatchResultListener* listener) const override; virtual bool MatchAndExplain(report_keyboard_t& report, testing::MatchResultListener* listener) const override;
virtual void DescribeTo(::std::ostream* os) const override; virtual void DescribeTo(::std::ostream* os) const override;
virtual void DescribeNegationTo(::std::ostream* os) const override; virtual void DescribeNegationTo(::std::ostream* os) const override;
private:
private:
report_keyboard_t m_report; report_keyboard_t m_report;
}; };
template <typename... Ts>
template<typename... Ts>
inline testing::Matcher<report_keyboard_t&> KeyboardReport(Ts... keys) { inline testing::Matcher<report_keyboard_t&> KeyboardReport(Ts... keys) {
return testing::MakeMatcher(new KeyboardReportMatcher(std::vector<uint8_t>({keys...}))); return testing::MakeMatcher(new KeyboardReportMatcher(std::vector<uint8_t>({keys...})));
} }
+1 -1
View File
@@ -21,7 +21,7 @@
class TestLogger : public std::ostream { class TestLogger : public std::ostream {
public: public:
TestLogger() : std::ostream(&m_log){}; TestLogger() : std::ostream(&m_log) {};
TestLogger& info(); TestLogger& info();
TestLogger& trace(); TestLogger& trace();
TestLogger& error(); TestLogger& error();