libhext: C++ Library Documentation  1.0.12-3ea013c
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
[legend]
Collaboration diagram for hext::FunctionCapture:
Collaboration graph
[legend]

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 override
 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.

Example:
GumboNode * node = ...; // <div>5 reasons why foo is better than bar</div>
TextBuiltin, // predefined CaptureFunction
"text" // result name
);
if( auto result = text.capture(node) )
assert(
*result == ResultPair("text", "5 reasons why foo is better than bar")
);
FunctionCapture(CaptureFunction func, std::string result_name, std::unique_ptr< StringPipe > pipe={}) noexcept
Constructs a FunctionCapture.
HEXT_PUBLIC const CaptureFunction TextBuiltin
A CaptureFunction that returns the text of an HTML element.
std::pair< std::string, std::string > ResultPair
A string-pair containing a name and a value.
Definition: Result.h:32
Example with regex:
GumboNode * node = ...; // <div>The result is 25cm.</div>
FunctionCapture centimeters(
InnerHtmlBuiltin, // predefined CaptureFunction
"centimeters", // result name
std::make_unique<RegexPipe>(boost::regex("(\\d+)cm"))
);
if( auto result = centimeters.capture(node) )
assert(*result == ResultPair("centimeters", "25"));
HEXT_PUBLIC const CaptureFunction InnerHtmlBuiltin
A CaptureFunction that returns the inner HTML of an HTML element.

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 = {} 
)
noexcept

Constructs a FunctionCapture.

Parameters
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 &&  )
defaultnoexcept

Member Function Documentation

◆ capture()

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

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

Optionally applies a StringPipe to the value before returning.

Parameters
nodeA pointer to a GumboNode.
Returns
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 &&  )
defaultnoexcept

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