Vehicle Specific Modules SDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ugcs::vsm::Text_stream_filter Class Reference

Class for convenient filtering of a text stream using regular expressions. More...

#include <text_stream_filter.h>

Inheritance diagram for ugcs::vsm::Text_stream_filter:

Public Types

typedef std::shared_ptr
< Text_stream_filter
 Pointer type.
typedef std::weak_ptr
< Text_stream_filter
 Pointer type.
typedef std::vector< std::string > Lines_list
 List of accumulated lines. More...
typedef Callback_proxy< bool,
regex::smatch *, Lines_list
*, Io_result
 Match handler called when entry matched the input line. More...
typedef Callback_proxy< bool,
const std::string * > 
 Received line handler. More...
typedef uint32_t Entry_handle
 Manipulation handle for an entry. More...

Public Member Functions

template<class __Callable , typename... __Args>
 __DEFINE_CALLBACK_BUILDER_BODY (Make_match_handler,(regex::smatch *, Text_stream_filter::Lines_list *, Io_result),(nullptr, nullptr, Io_result::OK))
 Builder for match handlers. More...
template<class __Callable , typename... __Args>
 __DEFINE_CALLBACK_BUILDER_BODY (Make_line_handler,(const std::string *),(nullptr))
 Builder for line handler. More...
 Text_stream_filter (Io_stream::Ref stream, Request_completion_context::Ptr comp_ctx, size_t max_read=MAX_READ)
 Construct filter bound to a stream. More...
void Enable ()
 Enable the filter. More...
void Disable (bool close_stream=true)
 Disable the filter. More...
Entry_handle Add_entry (const regex::regex &re, Match_handler handler, std::chrono::milliseconds timeout=std::chrono::milliseconds::zero(), size_t ctx_lines_before=0, size_t ctx_lines_after=0)
 Add matching entry to the filter. More...
void Set_line_handler (Line_handler handler)
 Set handler for pre-filtering all received lines. More...

Static Public Member Functions

template<typename... Args>
static Ptr Create (Args &&...args)
 Create an instance. More...

Static Public Attributes

static constexpr size_t MAX_HISTORY_LINES = 10
 Maximal number of lines saved before the matched line. More...
static constexpr size_t MAX_LINE_LENGTH = 512
 Maximal number of characters in one line which is supported. More...
static constexpr size_t MAX_READ = 64
 Maximal number of bytes to read at once. More...

Detailed Description

Class for convenient filtering of a text stream using regular expressions.

Member Typedef Documentation

Manipulation handle for an entry.

typedef Callback_proxy<bool, const std::string *> ugcs::vsm::Text_stream_filter::Line_handler

Received line handler.

true if line is captured by the handler and should not be fed to filter entries.
typedef std::vector<std::string> ugcs::vsm::Text_stream_filter::Lines_list

List of accumulated lines.

Match handler called when entry matched the input line.

true to perceive the handler in the filter, false to remove it. Timeout (if any) is restarted when "true" is returned. It is allowed to return true only for OK and TIMED_OUT result codes.

Constructor & Destructor Documentation

ugcs::vsm::Text_stream_filter::Text_stream_filter ( Io_stream::Ref  stream,
Request_completion_context::Ptr  comp_ctx,
size_t  max_read = MAX_READ 

Construct filter bound to a stream.

Member Function Documentation

template<class __Callable , typename... __Args>
ugcs::vsm::Text_stream_filter::__DEFINE_CALLBACK_BUILDER_BODY ( Make_match_handler  ,
(regex::smatch *, Text_stream_filter::Lines_list *, Io_result ,
(nullptr, nullptr, Io_result::OK  

Builder for match handlers.

template<class __Callable , typename... __Args>
ugcs::vsm::Text_stream_filter::__DEFINE_CALLBACK_BUILDER_BODY ( Make_line_handler  ,
(const std::string *)  ,

Builder for line handler.

Entry_handle ugcs::vsm::Text_stream_filter::Add_entry ( const regex::regex &  re,
Match_handler  handler,
std::chrono::milliseconds  timeout = std::chrono::milliseconds::zero(),
size_t  ctx_lines_before = 0,
size_t  ctx_lines_after = 0 

Add matching entry to the filter.

Should not be called, when related stream is already closed.

reRegular expression which is matched against each line. Handler is fired when match is found and enough context lines received.
handlerHandler to invoke. In case of timeout it is fired with result argument equal to Io_result::TIMED_OUT. In this case lines list and match object can contain some data if timeout occurred when waiting for required succeeding context lines.
timeoutTimeout value. Zero if no timeout needed.
ctx_lines_beforeNumber of context lines to capture before the matching line. Cannot be greater than MAX_HISTORY_LINES.
ctx_lines_afterNumber of context lines to capture after the matching lines.
Entry handle.
template<typename... Args>
static Ptr ugcs::vsm::Text_stream_filter::Create ( Args &&...  args)

Create an instance.

void ugcs::vsm::Text_stream_filter::Disable ( bool  close_stream = true)

Disable the filter.

void ugcs::vsm::Text_stream_filter::Enable ( )

Enable the filter.

void ugcs::vsm::Text_stream_filter::Set_line_handler ( Line_handler  handler)

Set handler for pre-filtering all received lines.

Member Data Documentation

constexpr size_t ugcs::vsm::Text_stream_filter::MAX_HISTORY_LINES = 10

Maximal number of lines saved before the matched line.

constexpr size_t ugcs::vsm::Text_stream_filter::MAX_LINE_LENGTH = 512

Maximal number of characters in one line which is supported.

constexpr size_t ugcs::vsm::Text_stream_filter::MAX_READ = 64

Maximal number of bytes to read at once.

The documentation for this class was generated from the following file: