C++ Utilities 5.24.7
Useful C++ classes and routines such as argument parser, IO and conversion utilities
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
CppUtilities::BufferSearch Class Reference

The BufferSearch struct invokes a callback if an initially given search term occurs in consecutively provided buffers. More...

#include <buffersearch.h>

Public Types

using CallbackType = std::function<void(BufferSearch &, std::string &&)>
 

Public Member Functions

 BufferSearch (std::string_view searchTerm, std::string_view terminationChars, std::string_view giveUpTerm, CallbackType &&callback)
 Constructs a new BufferSearch.
 
void operator() (std::string_view buffer)
 Processes the specified buffer.
 
void operator() (const std::string_view::value_type *buffer, std::size_t bufferSize)
 Processes the specified buffer.
 
template<std::size_t bufferCapacity>
void operator() (std::shared_ptr< std::array< std::string_view::value_type, bufferCapacity > > buffer, std::size_t bufferSize)
 Processes the specified buffer which is a shared array with fixed.
 
void reset ()
 Resets the search to its initial state (assuming no characters of the search term or give-up term have been found yet).
 

Detailed Description

The BufferSearch struct invokes a callback if an initially given search term occurs in consecutively provided buffers.

Remarks
  • The class works without making internal copies of the specified buffers, except for the search result.
  • The callback is invoked after the search term has been found and one of the specified termination characters occurred. The search result is passed to the callback.
  • The "search result" is the data after the last character of the search term and before any of the specified termination characters.
  • If no termination characters are specified, the callback is invoked directly after the search term occurred (with an empty search result).
  • If the specified give-up term has occurred, operator() will exit early and the specified callback will not be invoked anymore.
  • If the callback has been invoked, operator() will exit early and the callback will not be invoked anymore (even if the search term occurs again). Call reset() after consuming the result within the callback to continue the search.

Definition at line 15 of file buffersearch.h.

Member Typedef Documentation

◆ CallbackType

using CppUtilities::BufferSearch::CallbackType = std::function<void(BufferSearch &, std::string &&)>

Definition at line 17 of file buffersearch.h.

Constructor & Destructor Documentation

◆ BufferSearch()

CppUtilities::BufferSearch::BufferSearch ( std::string_view searchTerm,
std::string_view terminationChars,
std::string_view giveUpTerm,
CallbackType && callback )
inline

Constructs a new BufferSearch.

Might be overloaded in the future.

Definition at line 41 of file buffersearch.h.

Member Function Documentation

◆ operator()() [1/3]

void CppUtilities::BufferSearch::operator() ( const std::string_view::value_type * buffer,
std::size_t bufferSize )

Processes the specified buffer.

Invokes the callback according to the remarks mentioned in the class documentation.

Definition at line 27 of file buffersearch.cpp.

◆ operator()() [2/3]

template<std::size_t bufferCapacity>
void CppUtilities::BufferSearch::operator() ( std::shared_ptr< std::array< std::string_view::value_type, bufferCapacity > > buffer,
std::size_t bufferSize )
inline

Processes the specified buffer which is a shared array with fixed.

Template Parameters
bufferCapacity.Invokes the callback according to the remarks mentioned in the class documentation.

Definition at line 66 of file buffersearch.h.

◆ operator()() [3/3]

void CppUtilities::BufferSearch::operator() ( std::string_view buffer)
inline

Processes the specified buffer.

Invokes the callback according to the remarks mentioned in the class documentation.

Definition at line 57 of file buffersearch.h.

◆ reset()

void CppUtilities::BufferSearch::reset ( )

Resets the search to its initial state (assuming no characters of the search term or give-up term have been found yet).

Definition at line 71 of file buffersearch.cpp.


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