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

RAII wrapper for lists used by the libcurl API. More...

#include <CurlList.hpp>

Construction and Destruction

 CurlList ()=default
 Default constructor. More...
 
virtual ~CurlList ()
 Destructor resetting the list if necessary. More...
 

Getters

curl_slist * get () noexcept
 Gets a pointer to the underlying list. More...
 
const curl_slist * getc () const noexcept
 Gets a const pointer to the underlying list. More...
 
bool valid () const noexcept
 Checks whether the underlying list is valid. More...
 
std::size_t size () const noexcept
 Gets the current number of elements in the list. More...
 
bool empty () const noexcept
 Checks whether the list is empty. More...
 

Manipulation and Cleanup

void append (const CurlList &other)
 Appends another list to the list. More...
 
void append (const std::vector< std::string > &newElements)
 Appends the elements of a vector to the list. More...
 
void append (const std::string &newElement)
 Appends an element to the list. More...
 
void clear () noexcept
 Resets the list and frees its memory. More...
 

Copy and Move

The class is both copyable and moveable.

 CurlList (const CurlList &other)
 Copy constructor. More...
 
CurlListoperator= (const CurlList &other)
 Copy assignment operator. More...
 
 CurlList (CurlList &&other) noexcept
 Move constructor. More...
 
CurlListoperator= (CurlList &&other) noexcept
 Move assignment operator. More...
 

Detailed Description

RAII wrapper for lists used by the libcurl API.

Sets the list to nullptr on construction and automatically clears it 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.

Note
This class does not have ownership of the underlying pointer.

Constructor & Destructor Documentation

◆ CurlList() [1/3]

crawlservpp::Wrapper::CurlList::CurlList ( )
default

Default constructor.

◆ ~CurlList()

crawlservpp::Wrapper::CurlList::~CurlList ( )
inlinevirtual

Destructor resetting the list if necessary.

References clear().

◆ CurlList() [2/3]

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

Copy constructor.

Creates a new list and copies all elements of the given list into it.

Note
Calling this function with an invalid list has no effect.
Parameters
otherThe list to copy from.
Exceptions
std::runtime_errorif the new list could not be created or any of the elements could not be appended to it.

References append().

◆ CurlList() [3/3]

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

Move constructor.

Moves the list from the specified location into this instance of the class.

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

Member Function Documentation

◆ append() [1/3]

void crawlservpp::Wrapper::CurlList::append ( const CurlList other)
inline

Appends another list to the list.

Note
Calling this function on itself has no effect.
Parameters
otherA const reference to the list which elements should be appended.
Exceptions
std::runtime_errorif appending to the list failed.

Referenced by append(), CurlList(), operator=(), crawlservpp::Network::Curl::setConfigGlobal(), and crawlservpp::Network::Curl::setHeaders().

◆ append() [2/3]

void crawlservpp::Wrapper::CurlList::append ( const std::vector< std::string > &  newElements)
inline

Appends the elements of a vector to the list.

Parameters
newElementsA const reference to the vector of strings that should be appended to the list.
Exceptions
std::runtime_errorif appending to the list failed.

References append().

◆ append() [3/3]

void crawlservpp::Wrapper::CurlList::append ( const std::string &  newElement)
inline

Appends an element to the list.

A new list will be created if no list already exists.

Note
String views cannot be used, because the underlying API requires a null-terminated string.
Parameters
newElementA const reference to a string that should be appended at the end of the list.
Exceptions
std::runtime_errorif the element could not be appended by the underlying API.

◆ clear()

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

Resets the list and frees its memory.

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

Note
Does nothing if the underlying list is not initialized.
See also
valid

Referenced by operator=(), crawlservpp::Network::Curl::resetConnection(), crawlservpp::Network::Curl::setHeaders(), crawlservpp::Network::Curl::unsetHeaders(), and ~CurlList().

◆ empty()

bool crawlservpp::Wrapper::CurlList::empty ( ) const
inlinenoexcept

Checks whether the list is empty.

Returns
True, if the list is empty or invalid. False otherwise.
See also
valid

◆ get()

curl_slist * crawlservpp::Wrapper::CurlList::get ( )
inlinenoexcept

Gets a pointer to the underlying list.

Returns
A pointer to the underlying libcurl list or nullptr if no list has been created or the list has already been resetted.

Referenced by crawlservpp::Network::Curl::writerInClass().

◆ getc()

const curl_slist * crawlservpp::Wrapper::CurlList::getc ( ) const
inlinenoexcept

Gets a const pointer to the underlying list.

Returns
A const pointer to the underlying libcurl list or nullptr if no list has been created or the list has already been resetted.

◆ operator=() [1/2]

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

Copy assignment operator.

Clears the existing list, creates a new one and copies all elements of the given list into it.

Note
Nothing will be done if used on itself.
Parameters
otherThe buffer to copy from.
Returns
A reference to the class containing the copy of the list (i.e. *this).
Exceptions
std::runtime_errorif the new list could not be created or any of the elements could not be appended to it.

References append(), and clear().

◆ operator=() [2/2]

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

Move assignment operator.

Moves the list from the specified location into this instance of the class.

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

References clear().

◆ size()

std::size_t crawlservpp::Wrapper::CurlList::size ( ) const
inlinenoexcept

Gets the current number of elements in the list.

Returns
The number of elements in the underlying list.
Note
The return value is zero if the list has not been initialized.

◆ valid()

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

Checks whether the underlying list is valid.

Returns
True, if a list has been created and not been resetted. False otherwise.

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