All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
Public Member Functions | List of all members
hext::AttributeCapture Class Referencefinal

Captures an HTML Element's attribute. More...

Inheritance diagram for hext::AttributeCapture:
Inheritance graph
[legend]
Collaboration diagram for hext::AttributeCapture:
Collaboration graph
[legend]

Public Member Functions

 AttributeCapture (std::string attr_name, std::string result_name, std::unique_ptr< StringPipe > pipe=nullptr) noexcept
 Constructs an AttributeCapture. More...
 
 AttributeCapture (const AttributeCapture &other)
 
 AttributeCapture (AttributeCapture &&) noexcept=default
 
AttributeCaptureoperator= (const AttributeCapture &other)
 
AttributeCaptureoperator= (AttributeCapture &&) noexcept=default
 
boost::optional< ResultPaircapture (const GumboNode *node) const override
 Captures an HTML element's attribute called attr_name (as given in the constructor). More...
 
- Public Member Functions inherited from hext::Cloneable< AttributeCapture, 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 an HTML Element's attribute.

Example:
GumboNode * node = ...; // <img src="bob.jpg"/>
"src", // attribute name
"image" // result name
);
if( auto result = img.capture(node) )
// attribute found and captured
assert(*result == ResultPair("image", "bob.jpg"));
Example with regex:
GumboNode * node = ...; // <a href="/highway-61"></a>
"href", // attribute name
"U.S. Route" // result name
std::make_unique<RegexPipe>(boost::regex("\\d+"))
);
if( auto result = highway.capture(node) )
// attribute found and captured
assert(*result == ResultPair("U.S. Route", "61"));

Definition at line 61 of file AttributeCapture.h.

Constructor & Destructor Documentation

hext::AttributeCapture::AttributeCapture ( std::string  attr_name,
std::string  result_name,
std::unique_ptr< StringPipe pipe = nullptr 
)
noexcept

Constructs an AttributeCapture.

Parameters
attr_nameThe name of the HTML attribute whose value will be captured.
result_nameThe name for the result that is returned from AttributeCapture::capture.
pipeIf given, the captured value will be sent through this StringPipe before returning from capture().
hext::AttributeCapture::AttributeCapture ( const AttributeCapture other)
hext::AttributeCapture::AttributeCapture ( AttributeCapture &&  )
defaultnoexcept

Member Function Documentation

boost::optional<ResultPair> hext::AttributeCapture::capture ( const GumboNode *  node) const
overridevirtual

Captures an HTML element's attribute called attr_name (as given in the constructor).

Optionally applies a StringPipe to the value before returning.

Parameters
nodeA pointer to a GumboNode of type GUMBO_NODE_ELEMENT.
Returns
A pair in the form of {result_name, attribute_value} or an empty optional if the attribute cannot be found.

Implements hext::Capture.

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

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