crawlserv++  [under development]
Application for crawling and analyzing textual content of websites.
crawlservpp::Wrapper::PCRE Class Reference

RAII wrapper for Perl-compatible regular expressions. More...

#include <PCRE.hpp>

Construction and Destruction

 PCRE ()=default
 Default constructor. More...
 
 PCRE (pcre2_code *regExPtr) noexcept
 Constructor setting the underlying pointer. More...
 
virtual ~PCRE ()
 Destructor freeing the underlying regular expression if necessary. More...
 

Getters

pcre2_code * get () noexcept
 Gets a pointer to the underlying regular expression. More...
 
const pcre2_code * getc () const noexcept
 Gets a const pointer to the underlying regular expression. More...
 
bool valid () const noexcept
 Checks whether the underlying regular expression is valid. More...
 

Setter

void set (pcre2_code *regExPtr)
 Sets a PERL-compatibe regular expression. More...
 

Cleanup

void clear () noexcept
 Clears the underlying regular expression if necessary. More...
 

Copy and Move

The class is both copyable and moveable.

 PCRE (const PCRE &other)
 Copy constructor. More...
 
PCREoperator= (const PCRE &other)
 Copy assignment operator. More...
 
 PCRE (PCRE &&other) noexcept
 Move constructor. More...
 
PCREoperator= (PCRE &&other) noexcept
 Move assignment operator. More...
 

Detailed Description

RAII wrapper for Perl-compatible regular expressions.

Sets an empty pointer on construction and clears the RegEx on destruction if necessary, avoiding memory leaks.

At the moment, this class is used exclusively by the Query::Regex class.

For more information about the PCRE library used, visit its website.

Note
The class does not own the underlying pointer, but takes care of its deletion via API call.

Constructor & Destructor Documentation

◆ PCRE() [1/4]

crawlservpp::Wrapper::PCRE::PCRE ( )
default

Default constructor.

◆ PCRE() [2/4]

crawlservpp::Wrapper::PCRE::PCRE ( pcre2_code *  regExPtr)
inlineexplicitnoexcept

Constructor setting the underlying pointer.

Parameters
regExPtrThe address to which the underlying pointer should be set. Can either be nullptr or a valid pointer to a compiled regular expression.
Note
The underlying pointer will be cleared in-class via API call.
See also
set

◆ ~PCRE()

crawlservpp::Wrapper::PCRE::~PCRE ( )
inlinevirtual

Destructor freeing the underlying regular expression if necessary.

References clear().

◆ PCRE() [3/4]

crawlservpp::Wrapper::PCRE::PCRE ( const PCRE other)
inline

Copy constructor.

Creates a copy of the underlying regular expression in the given instance, saving it in this instance.

Both pattern code points and character tables are copied.

If the other regular expression is invalid, the current instance will also be invalid.

Note
Uses the same allocator used in other.
Warning
JIT (just-in-time) information cannot be copied and needs to be re-compiled if needed.
Parameters
otherThe regular expression to copy from.

References getc().

◆ PCRE() [4/4]

crawlservpp::Wrapper::PCRE::PCRE ( PCRE &&  other)
inlinenoexcept

Move constructor.

Moves the regular expression from the specified location into this instance of the class.

Note
The other expression will be invalidated by this move.
Parameters
otherThe regular expression to move from.
See also
valid

Member Function Documentation

◆ clear()

void crawlservpp::Wrapper::PCRE::clear ( )
inlinenoexcept

Clears the underlying regular expression if necessary.

The regular expression will be invalid and valid() will return false afterwards.

Note
Does nothing if the underlying regular expression is not valid.
See also
valid

Referenced by operator=(), set(), and ~PCRE().

◆ get()

pcre2_code * crawlservpp::Wrapper::PCRE::get ( )
inlinenoexcept

Gets a pointer to the underlying regular expression.

Returns
A pointer to the underlying regular expression or nullptr if none is set.

◆ getc()

const pcre2_code * crawlservpp::Wrapper::PCRE::getc ( ) const
inlinenoexcept

Gets a const pointer to the underlying regular expression.

Returns
A const pointer to the underlying regular expression or nullptr if none is set.

Referenced by crawlservpp::Query::RegEx::getAll(), crawlservpp::Query::RegEx::getBool(), crawlservpp::Query::RegEx::getFirst(), operator=(), and PCRE().

◆ operator=() [1/2]

PCRE & crawlservpp::Wrapper::PCRE::operator= ( const PCRE other)
inline

Copy assignment operator.

Clears the existing regular expression if necessary and creates a copy of the underlying regular expression in the given instance, saving it in this instance.

Note
Uses the same allocator used in other.
Nothing will be done if used on itself.
Warning
JIT (jut-in-time) information cannot be copied and needs to be re-compiled if needed.
Parameters
otherThe regular expression to copy from.
Returns
A reference to the class containing the copy of the regular expression (i.e. *this).

References clear(), and getc().

◆ operator=() [2/2]

PCRE & crawlservpp::Wrapper::PCRE::operator= ( PCRE &&  other)
inlinenoexcept

Move assignment operator.

Moves the regular expression from the specified location into this instance of the class.

Note
The other expression will be invalidated by this move.
Nothing will be done if used on itself.
Parameters
otherThe regular expression to move from.
Returns
A reference to the instance containing the regular expression after moving (i.e. *this).
See also
valid

References clear().

◆ set()

void crawlservpp::Wrapper::PCRE::set ( pcre2_code *  regExPtr)
inline

Sets a PERL-compatibe regular expression.

If another expression is already managed by the class, it will be cleared.

Parameters
regExPtrA pointer to the new regular expression to be stored or nullptr to just clear the old expression if necessary.
Note
The underlying pointer will be cleared in-class via API call.

References clear().

Referenced by crawlservpp::Query::RegEx::RegEx().

◆ valid()

bool crawlservpp::Wrapper::PCRE::valid ( ) const
inlinenoexcept

Checks whether the underlying regular expression is valid.

Returns
True, if the regular expression is valid, i.e. a pointer has been set. False otherwise.
See also
clear

Referenced by crawlservpp::Query::RegEx::getAll(), crawlservpp::Query::RegEx::getBool(), crawlservpp::Query::RegEx::getFirst(), crawlservpp::Query::RegEx::RegEx(), and crawlservpp::Query::RegEx::valid().


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