add logger and some tests

This commit is contained in:
chatlanin
2025-01-03 11:53:18 +03:00
parent 67eab0a97f
commit 4fc81c4c04
8 changed files with 83 additions and 55 deletions

View File

@@ -8,6 +8,8 @@
#include "hack/iterators/sequence_ostream_iterator.hpp"
#include "hack/iterators/associative_ostream_iterator.hpp"
#include "hack/patterns/ring_buffer.hpp"
namespace hack
{
class log
@@ -133,6 +135,12 @@ namespace hack
std::cout << data << (count != 0 ? devider : "");
}
template<typename T, std::size_t size>
static void print_t(const hack::patterns::ring_buffer<T, size>& rb)
{
print_t(rb.get_src());
}
friend class warn;
friend class error;
};

View File

@@ -1,3 +1,5 @@
#pragma once
#include <array>
#include <mutex>
#include <optional>
@@ -56,41 +58,46 @@ namespace hack::patterns
return val;
}
bool empty() noexcept
std::array<T, BUFFER_SIZE>& get_src() const noexcept
{
return m_data;
}
bool empty() const noexcept
{
MUTEX lock(m_mutex);
return (!m_full && (m_head == m_tail));
}
size_t size() noexcept
{
MUTEX lock(m_mutex);
std::size_t size() const noexcept
{
MUTEX lock(m_mutex);
std::size_t size;
if(!m_full)
size = (m_head >= m_tail) ? m_head - m_tail : BUFFER_SIZE - (m_tail - m_head);
else
size = BUFFER_SIZE;
std::size_t size;
if(!m_full)
size = (m_head >= m_tail) ? m_head - m_tail : BUFFER_SIZE - (m_tail - m_head);
else
size = BUFFER_SIZE;
return size;
}
return size;
}
void reset() noexcept
{
MUTEX lock(m_mutex);
m_head = m_tail;
m_full = false;
}
void reset() noexcept
{
MUTEX lock(m_mutex);
m_head = m_tail;
m_full = false;
}
bool full() const noexcept
{
return m_full;
}
bool full() const noexcept
{
return m_full;
}
std::size_t capacity() const noexcept
{
return BUFFER_SIZE;
}
std::size_t capacity() const noexcept
{
return BUFFER_SIZE;
}
private:
void head_refresh()
@@ -106,8 +113,7 @@ namespace hack::patterns
std::size_t m_tail{ 0 };
private:
std::recursive_mutex m_mutex;
std::array<T, BUFFER_SIZE> m_data;
mutable std::recursive_mutex m_mutex;
mutable std::array<T, BUFFER_SIZE> m_data;
};
}

View File

@@ -6,7 +6,7 @@ headers = [
'hack/iterators/associative_ostream_iterator.hpp',
'hack/iterators/sequence_ostream_iterator.hpp',
'hack/log/log.hpp',
'hack/logger/logger.hpp',
'hack/mt/algorithms/max.hpp',
'hack/mt/algorithms/sort.hpp',