libhext: C++ Library Documentation  0.8.2-e5d504d
Public Member Functions | List of all members
hext::FunctionCapture Class Referencefinal

Captures the result of applying a function to an HTML node. More...

Inheritance diagram for hext::FunctionCapture:
Inheritance graph
Collaboration diagram for hext::FunctionCapture:
Collaboration graph

Public Member Functions

 FunctionCapture (CaptureFunction func, std::string result_name, std::unique_ptr< StringPipe > pipe={}) noexcept
 Constructs a FunctionCapture. More...
 FunctionCapture (const FunctionCapture &other)
 FunctionCapture (FunctionCapture &&) noexcept=default
FunctionCaptureoperator= (const FunctionCapture &other)
FunctionCaptureoperator= (FunctionCapture &&) noexcept=default
std::optional< ResultPaircapture (const GumboNode *node) const override
 Captures the result of calling a given CaptureFunction with node as its argument. More...
- Public Member Functions inherited from hext::Cloneable< FunctionCapture, Capture >
virtual std::unique_ptr< Captureclone () const
 Clones objects of template type Derived and returns an owning pointer to the newly allocated Base. More...
- Public Member Functions inherited from hext::Capture
 Capture () noexcept=default
 Capture (const Capture &)=default
 Capture (Capture &&) noexcept=default
Captureoperator= (const Capture &)=default
Captureoperator= (Capture &&) noexcept=default
virtual ~Capture () noexcept=default

Detailed Description

Captures the result of applying a function to an HTML node.

GumboNode * node = ...; // <div>5 reasons why foo is better than bar</div>
TextBuiltin, // predefined CaptureFunction
"text" // result name
if( auto result = text.capture(node) )
*result == ResultPair("text", "5 reasons why foo is better than bar")
Example with regex:
GumboNode * node = ...; // <div>The result is 25cm.</div>
FunctionCapture centimeters(
InnerHtmlBuiltin, // predefined CaptureFunction
"centimeters", // result name
if( auto result = centimeters.capture(node) )
assert(*result == ResultPair("centimeters", "25"));

Definition at line 63 of file FunctionCapture.h.

Constructor & Destructor Documentation

◆ FunctionCapture() [1/3]

hext::FunctionCapture::FunctionCapture ( CaptureFunction  func,
std::string  result_name,
std::unique_ptr< StringPipe pipe = {} 

Constructs a FunctionCapture.

funcThe function that will be applied to an HTML node.
result_nameThe name for the result that is returned from FuntionCapture::capture.
pipeIf given, the captured value will be sent through this StringPipe before returning from capture().

◆ FunctionCapture() [2/3]

hext::FunctionCapture::FunctionCapture ( const FunctionCapture other)

◆ FunctionCapture() [3/3]

hext::FunctionCapture::FunctionCapture ( FunctionCapture &&  )

Member Function Documentation

◆ capture()

std::optional<ResultPair> hext::FunctionCapture::capture ( const GumboNode *  node) const

Captures the result of calling a given CaptureFunction with node as its argument.

Optionally applies a StringPipe to the value before returning.

nodeA pointer to a GumboNode.
A pair in the form of {result_name, result_value} or an empty optional if the capture failed.

Implements hext::Capture.

◆ operator=() [1/2]

FunctionCapture& hext::FunctionCapture::operator= ( const FunctionCapture other)

◆ operator=() [2/2]

FunctionCapture& hext::FunctionCapture::operator= ( FunctionCapture &&  )

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