Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
LineBuffer.h
Go to the documentation of this file.
1#pragma once
2#include <iostream>
3#include <misc/gen/TClosure.h>
5#include <misc/global.h>
6
7namespace sf
8{
9
13class _MISC_CLASS LineBuffer : public std::streambuf
14{
15 public:
19 explicit LineBuffer(unsigned max_lines);
23 ~LineBuffer() override;
27 [[nodiscard]] std::string getLine(unsigned line) const;
31 [[nodiscard]] int lineCount() const;
35 [[nodiscard]] int totalLineCount() const
36 {
37 return _totalLineCount;
38 }
42 void clear();
46 void setMaxLines(unsigned max_lines);
50 typedef TClosure<void, LineBuffer* /*sender*/, const std::string& /*line*/> event_t;
54 void setNewLineHandler(const event_t& event);
60
61 private:
65 int overflow(int c /*=EOF*/) override;
69 std::streamsize xsputn(const char* s, std::streamsize count) override;
77 int _totalLineCount;
81 event_t _onOnNewLine;
82};
83
84}// namespace sf
Special std::streambuf class for capturing lines.
Definition LineBuffer.h:14
LineBuffer(unsigned max_lines)
Constructor settings the maximum lines the buffer can hold.
std::string getLine(unsigned line) const
Returns requested line in the buffer.
int totalLineCount() const
Returns the total lines passed through the fifo buffer.
Definition LineBuffer.h:35
int lineCount() const
TClosure< void, LineBuffer *, const std::string & > event_t
Closure Event type.
Definition LineBuffer.h:50
const event_t & newLineHandler()
Returns the new line handler.
void setNewLineHandler(const event_t &event)
When a new line is added this event is triggered.
void setMaxLines(unsigned max_lines)
Sets the maximum lines the stream can hold. Flushes all lines first.
~LineBuffer() override
Overridden virtual destructor.
Encapsulates the std::function() template.
Definition TClosure.h:14
Fifo template for classes and structure pointers.
Definition TFifoClass.h:14
#define _MISC_CLASS
Definition misc/global.h:40
Definition Application.h:10