All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
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
 
boost::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.

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")
);
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"));

Definition at line 62 of file FunctionCapture.h.

Constructor & Destructor Documentation

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().
hext::FunctionCapture::FunctionCapture ( const FunctionCapture other)
hext::FunctionCapture::FunctionCapture ( FunctionCapture &&  )
defaultnoexcept

Member Function Documentation

boost::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.

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

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