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

RAII wrapper for handles of the libcurl API. More...

#include <Curl.hpp>

Construction and Destruction

 Curl ()
 Constructor initializing the libcurl API locally and globally, if necessary. More...
 
virtual ~Curl ()
 Destructor cleaning up the libcurl API locally and globally, if necessary. More...
 

Getters

CURL * get () noexcept
 Gets a pointer to the underlying libcurl handle. More...
 
CURL ** getPtr () noexcept
 Gets a pointer to the pointer containing the address of the underlying libcurl handle. More...
 
bool valid () const noexcept
 Checks whether the underlying libcurl handle is valid. More...
 

Initialization and Cleanup

void init ()
 Initializes the underlying libcurl handle. More...
 
void clear () noexcept
 Clears the underlying libcurl handle. More...
 

Copy and Move

The class is not copyable, only moveable.

 Curl (Curl &)=delete
 Deleted copy constructor. More...
 
Curloperator= (Curl &)=delete
 Deleted copy assignment operator. More...
 
 Curl (Curl &&other) noexcept
 Move constructor. More...
 
Curloperator= (Curl &&other) noexcept
 Move assignment operator. More...
 

Detailed Description

RAII wrapper for handles of the libcurl API.

Initializes the libcurl API locally and globally, if still necessary. Automatically resets the API on destruction, avoiding memory leaks.

At the moment, this class is used exclusively by Network::Curl.

For more information about the libcurl API, see its website.

Constructor & Destructor Documentation

◆ Curl() [1/3]

crawlservpp::Wrapper::Curl::Curl ( )
inline

Constructor initializing the libcurl API locally and globally, if necessary.

Exceptions
std::runtime_errorif the initialization of the API failed.
See also
curl_global_init, curl_easy_init

References init().

◆ ~Curl()

crawlservpp::Wrapper::Curl::~Curl ( )
inlinevirtual

Destructor cleaning up the libcurl API locally and globally, if necessary.

Also globally deinitializes the libcurl API if it was initialized during construction or the reponsibility for it received during move assignment.

See also
curl_global_cleanup, curl_easy_cleanup

References clear().

◆ Curl() [2/3]

crawlservpp::Wrapper::Curl::Curl ( Curl )
delete

Deleted copy constructor.

◆ Curl() [3/3]

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

Move constructor.

Moves the libcurl handle from the specified location into this instance of the class.

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

Member Function Documentation

◆ clear()

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

Clears the underlying libcurl handle.

If the handle is not initialized, the function will have no effect.

Warning
Does not clear the global initialization of the libcurl API, which will only be released on destruction or the responsibility for it transferred away during move assignment.
See also
curl_easy_cleanup

Referenced by init(), operator=(), crawlservpp::Network::Curl::resetConnection(), and ~Curl().

◆ get()

CURL * crawlservpp::Wrapper::Curl::get ( )
inlinenoexcept

◆ getPtr()

CURL ** crawlservpp::Wrapper::Curl::getPtr ( )
inlinenoexcept

Gets a pointer to the pointer containing the address of the underlying libcurl handle.

Returns
A pointer to the pointer containing the address of the underlying libcurl handle or a pointer to a pointer containing nullptr if the initialization failed or the handle has already been cleared.

◆ init()

void crawlservpp::Wrapper::Curl::init ( )
inline

Initializes the underlying libcurl handle.

If the underlying handle is already initialized, it will be cleared.

See also
curl_easy_init

References clear().

Referenced by Curl(), and crawlservpp::Network::Curl::resetConnection().

◆ operator=() [1/2]

Curl& crawlservpp::Wrapper::Curl::operator= ( Curl )
delete

Deleted copy assignment operator.

◆ operator=() [2/2]

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

Move assignment operator.

Moves the libcurl handle from the specified location into this instance of the class.

The responsibility to clear the libcurl API globally will be kept in this instance or transferred from the other instance if necessary.

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

References clear().

◆ valid()

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

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