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

RAII wrapper for buffers used by the tidy-html5 API. More...

#include <TidyBuffer.hpp>

Construction and Destruction

 TidyBuffer ()=default
 Default constructor. More...
 
virtual ~TidyBuffer ()
 Destructor clearing the underlying buffer if necessary. More...
 

Getters

::TidyBufferget () noexcept
 Gets a pointer to the underlying buffer. More...
 
const ::TidyBuffergetc () const noexcept
 Gets a const pointer to the underlying buffer. More...
 
std::string getString () const noexcept
 Copies the content of the underlying buffer into a string. More...
 
bool valid () const noexcept
 Checks whether the underlying buffer is valid. More...
 
std::size_t size () const noexcept
 Gets the current size of the content in the underlying buffer in bytes. More...
 
bool empty () const noexcept
 Checks whether the underlying buffer is empty. More...
 
std::size_t capacity () const noexcept
 Gets the current capacity of the underlying buffer in bytes. More...
 

Cleanup

void clear () noexcept
 Frees the underlying buffer. More...
 

Copy and Move

The class is both copyable and moveable.

 TidyBuffer (const TidyBuffer &other)
 Copy constructor. More...
 
TidyBufferoperator= (const TidyBuffer &other)
 Copy assignment operator. More...
 
 TidyBuffer (TidyBuffer &&other) noexcept
 Move constructor. More...
 
TidyBufferoperator= (TidyBuffer &&other) noexcept
 Move assignment operator. More...
 

Detailed Description

RAII wrapper for buffers used by the tidy-html5 API.

Zeroes the buffer on construction and automatically clears it on destruction, avoiding memory leaks.

At the moment, this class is used exclusively by TidyDoc.

Constructor & Destructor Documentation

◆ TidyBuffer() [1/3]

crawlservpp::Wrapper::TidyBuffer::TidyBuffer ( )
default

Default constructor.

◆ ~TidyBuffer()

crawlservpp::Wrapper::TidyBuffer::~TidyBuffer ( )
inlinevirtual

Destructor clearing the underlying buffer if necessary.

References clear().

◆ TidyBuffer() [2/3]

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

Copy constructor.

Allocates the same amount of memory as the capacity() of the other buffer and copies its content.

Note
Uses the allocator used in other, or the default allocator if none can be detected.
Parameters
otherThe buffer to copy from.

◆ TidyBuffer() [3/3]

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

Move constructor.

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

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

References size().

Member Function Documentation

◆ capacity()

std::size_t crawlservpp::Wrapper::TidyBuffer::capacity ( ) const
inlinenoexcept

Gets the current capacity of the underlying buffer in bytes.

  • Note
    The size() of the actual content in the buffer, i.e. the number of used bytes, might be smaller.
    The return value is zero if the buffer has not been initialized.
    Returns
    The number of bytes currently allocated for the underlying buffer.

Referenced by operator=().

◆ clear()

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

Frees the underlying buffer.

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

Note
Does nothing if the underlying buffer is not initialized.

Referenced by crawlservpp::Wrapper::TidyDoc::cleanAndRepair(), crawlservpp::Wrapper::TidyDoc::getOutput(), operator=(), crawlservpp::Wrapper::TidyDoc::parse(), and ~TidyBuffer().

◆ empty()

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

Checks whether the underlying buffer is empty.

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

References size().

Referenced by crawlservpp::Wrapper::TidyDoc::cleanAndRepair(), crawlservpp::Wrapper::TidyDoc::getOutput(), operator=(), and crawlservpp::Wrapper::TidyDoc::parse().

◆ get()

TidyBuffer * crawlservpp::Wrapper::TidyBuffer::get ( )
inlinenoexcept

Gets a pointer to the underlying buffer.

Returns
A pointer to the underlying TidyBuffer instance.

Referenced by crawlservpp::Wrapper::TidyDoc::getOutput(), and crawlservpp::Wrapper::TidyDoc::TidyDoc().

◆ getc()

const ::TidyBuffer * crawlservpp::Wrapper::TidyBuffer::getc ( ) const
inlinenoexcept

Gets a const pointer to the underlying buffer.

Returns
A const pointer to the underlying TidyBuffer instance.

◆ getString()

std::string crawlservpp::Wrapper::TidyBuffer::getString ( ) const
inlinenoexcept

Copies the content of the underlying buffer into a string.

Returns
A string copy of the contents of the underlying buffer or an empty string if the buffer is invalid (or empty).

References size().

Referenced by crawlservpp::Wrapper::TidyDoc::cleanAndRepair(), crawlservpp::Wrapper::TidyDoc::getOutput(), and crawlservpp::Wrapper::TidyDoc::parse().

◆ operator=() [1/2]

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

Copy assignment operator.

Clears the existing buffer, allocates the same amount of memory as capacity() of the other buffer and copies its content.

Note
Uses the allocator used in other, or the default allocator if none can be detected.
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 buffer (i.e. *this).

References capacity(), clear(), empty(), size(), and valid().

◆ operator=() [2/2]

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

Move assignment operator.

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

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

References clear(), and size().

◆ size()

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

Gets the current size of the content in the underlying buffer in bytes.

Returns
The size of the content in the underlying buffer in bytes, i.e. the bytes it currently uses.
Note
The return value is zero if the buffer has not been initialized.
See also
capacity

References size().

Referenced by empty(), getString(), operator=(), size(), and TidyBuffer().

◆ valid()

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

Checks whether the underlying buffer is valid.

Returns
True, if the buffer is valid. False otherwise.
Note
Also returns true if the underlying buffer is empty, but valid.
See also
empty, clear

Referenced by crawlservpp::Wrapper::TidyDoc::cleanAndRepair(), crawlservpp::Wrapper::TidyDoc::getOutput(), operator=(), and crawlservpp::Wrapper::TidyDoc::parse().


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