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
14class _MISC_CLASS LineBuffer : public std::streambuf
15{
16 public:
20 explicit LineBuffer(unsigned max_lines);
21
25 ~LineBuffer() override;
26
30 static constexpr std::streambuf::char_type clearChar = '\x12';
31
35 std::string getLine(unsigned line) const;
36
40 int lineCount() const;
41
45 int totalLineCount() const;
46
50 void clear();
51
55 void setMaxLines(unsigned max_lines);
56
61 typedef TClosure<void, LineBuffer* /*sender*/, const std::string* /*line*/> handler_type;
62
66 void setNewLineHandler(const handler_type& event);
72
73 private:
77 int overflow(int c /*=EOF*/) override;
78
82 std::streamsize xsputn(const char* s, std::streamsize count) override;
83
85 int _totalLineCount;
86 handler_type _handleNewLine;
87};
88
89}// namespace sf
Special std::streambuf class for capturing lines.
Definition LineBuffer.h:15
void setNewLineHandler(const handler_type &event)
When a new line is added this event is triggered.
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.
int lineCount() const
TClosure< void, LineBuffer *, const std::string * > handler_type
Closure handler type to handle buffer changes. When the std:string line argument is a nullptr the buf...
Definition LineBuffer.h:61
const handler_type & newLineHandler()
Returns the new line handler.
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