Updated clang format to google style

This commit is contained in:
gabime
2023-09-25 02:35:55 +03:00
parent 66de161355
commit 6de0ffa15f
86 changed files with 2164 additions and 3466 deletions

View File

@@ -4,14 +4,13 @@
// circular q view of std::vector.
#pragma once
#include <vector>
#include <cassert>
#include <vector>
namespace spdlog {
namespace details {
template<typename T>
class circular_q
{
template <typename T>
class circular_q {
size_t max_items_ = 0;
typename std::vector<T>::size_type head_ = 0;
typename std::vector<T>::size_type tail_ = 0;
@@ -26,30 +25,24 @@ public:
explicit circular_q(size_t max_items)
: max_items_(max_items + 1) // one item is reserved as marker for full q
, v_(max_items_)
{}
,
v_(max_items_) {}
circular_q(const circular_q &) = default;
circular_q &operator=(const circular_q &) = default;
// move cannot be default,
// since we need to reset head_, tail_, etc to zero in the moved object
circular_q(circular_q &&other) noexcept
{
copy_moveable(std::move(other));
}
circular_q(circular_q &&other) noexcept { copy_moveable(std::move(other)); }
circular_q &operator=(circular_q &&other) noexcept
{
circular_q &operator=(circular_q &&other) noexcept {
copy_moveable(std::move(other));
return *this;
}
// push back, overrun (oldest) item if no room left
void push_back(T &&item)
{
if (max_items_ > 0)
{
void push_back(T &&item) {
if (max_items_ > 0) {
v_[tail_] = std::move(item);
tail_ = (tail_ + 1) % max_items_;
@@ -63,78 +56,53 @@ public:
// Return const reference to the front item.
// If there are no elements in the container, the behavior is undefined.
[[nodiscard]] const T &front() const
{
return v_[head_];
}
[[nodiscard]] const T &front() const { return v_[head_]; }
// Return reference to the front item.
// If there are no elements in the container, the behavior is undefined.
[[nodiscard]] T &front()
{
return v_[head_];
}
[[nodiscard]] T &front() { return v_[head_]; }
// Return number of elements actually stored
[[nodiscard]] size_t size() const
{
if (tail_ >= head_)
{
[[nodiscard]] size_t size() const {
if (tail_ >= head_) {
return tail_ - head_;
}
else
{
} else {
return max_items_ - (head_ - tail_);
}
}
// Return const reference to item by index.
// If index is out of range 0…size()-1, the behavior is undefined.
const T &operator[](size_t idx) const
{
const T &operator[](size_t idx) const {
assert(idx < size());
assert(max_items_ > 0);
return v_[(head_ + idx) % max_items_];
}
// Pop item from front if not empty.
void pop_front()
{
if (!empty())
{
void pop_front() {
if (!empty()) {
head_ = (head_ + 1) % max_items_;
}
}
[[nodiscard]] bool empty() const
{
return tail_ == head_;
}
[[nodiscard]] bool empty() const { return tail_ == head_; }
[[nodiscard]] bool full() const
{
[[nodiscard]] bool full() const {
// head is ahead of the tail by 1
if (max_items_ > 0)
{
if (max_items_ > 0) {
return ((tail_ + 1) % max_items_) == head_;
}
return true;
}
[[nodiscard]] size_t overrun_counter() const
{
return overrun_counter_;
}
[[nodiscard]] size_t overrun_counter() const { return overrun_counter_; }
void reset_overrun_counter()
{
overrun_counter_ = 0;
}
void reset_overrun_counter() { overrun_counter_ = 0; }
private:
// copy from other&& and reset it to disabled state
void copy_moveable(circular_q &&other) noexcept
{
void copy_moveable(circular_q &&other) noexcept {
max_items_ = other.max_items_;
head_ = other.head_;
tail_ = other.tail_;