Line data Source code
1 : /*! 2 : * \file esys/repo/tui/logbuffer.h 3 : * \brief Thread-safe ring buffer for TUI Output pane lines 4 : * 5 : * \cond 6 : * __legal_b__ 7 : * 8 : * Copyright (c) 2026 Michel Gillet 9 : * Distributed under the MIT License. 10 : * (See accompanying file LICENSE.txt or 11 : * copy at https://opensource.org/licenses/MIT) 12 : * 13 : * __legal_e__ 14 : * \endcond 15 : * 16 : */ 17 : 18 : #pragma once 19 : 20 : #include "esys/repo/esysrepo_defs.h" 21 : 22 : #include <cstddef> 23 : #include <deque> 24 : #include <mutex> 25 : #include <string> 26 : #include <vector> 27 : 28 : namespace esys::repo::tui 29 : { 30 : 31 : /*! \class LogBuffer esys/repo/tui/logbuffer.h "esys/repo/tui/logbuffer.h" 32 : * \brief Bounded log lines shared between CaptureLogger and the UI thread 33 : */ 34 0 : class ESYSREPO_API LogBuffer 35 : { 36 : public: 37 : explicit LogBuffer(std::size_t capacity = 1000); 38 : 39 : void push(std::string line); 40 : std::vector<std::string> snapshot() const; 41 : std::size_t size() const; 42 : 43 : private: 44 : mutable std::mutex m_mutex; 45 : std::size_t m_capacity = 1000; 46 : std::deque<std::string> m_lines; 47 : }; 48 : 49 : } // namespace esys::repo::tui