UDBase(3)

UDBase(3) Library Functions Manual UDBase(3)

NAME

UDBase - The UDBase class.

SYNOPSIS

#include <UDBase.h>

Public Member Functions


UDBase (const UDBase &other)
UDBase (UDBase &&other)
UDBase & operator= (const UDBase &other)
UDBase & operator= (UDBase &&other)
UDBase & operator+= (const UDBase &other)
void writeToBuffer (std::vector< char > &result)
void readFromBuffer (const std::vector< char > &buf, const size_t &offset=0, const size_t &bytes_to_read=0)
void writeToFile (const std::filesystem::path &f_path)
void readFromFile (const std::filesystem::path &f_path)
std::vector< UDBElement > * getRawBase () const
void addElement (const UDBElement &el)
void addElements (const std::vector< UDBElement > &elements)
virtual void removeElement (const UDBElement &el)
virtual void removeElements (std::function< bool(const UDBElement &)> predicate)
virtual void replaceElement (const UDBElement &old_el, const UDBElement &new_el)
void clearBase ()
void shrinkToFit ()
virtual UDBase searchElement (std::function< bool(const UDBElement &)> search_function)
virtual UDBase searchElement (std::function< void(const UDBElement &, UDBase &)> search_function)
virtual std::vector< UDBElement > searchElementV (std::function< bool(const UDBElement &)> search_function)
virtual void sortBase (std::function< bool(const UDBElement &, const UDBElement &)> sort_function)
size_t baseSize () const
size_t calculateWriteSize ()
std::vector< UDBase > splitBase (const size_t &bytes_limit, const size_t &minimum_elements=size_t(1))

Static Public Member Functions


static UDBase convertToBase (const std::vector< UDBElement > &elements)

Protected Member Functions


void readFromBufferInner (const std::vector< char > &buf, const size_t &offset, const size_t &bytes_to_read)
void writeToBufferInner (std::vector< char > &result)

Protected Attributes


std::vector< UDBElement > base
Internal base object. std::string base_version = 'UDB 1.0'
Base version string used to identify base in buffers and files.

Detailed Description

The UDBase class.

This class contains methods for database managing.

Constructor & Destructor Documentation

UDBase::UDBase (const UDBase & other)

Copy constructor.

Parameters

other UDBase object.

UDBase::UDBase (UDBase && other)

Move constructor.

Parameters

other UDBase object.

Member Function Documentation

void UDBase::addElement (const UDBElement & el)

Adds element to base.

Parameters

el Element to be added.

void UDBase::addElements (const std::vector< UDBElement > & elements)

Adds elements to base.

Parameters

elements Vector of elements to be added.

size_t UDBase::baseSize () const

Returns number of elements in database.

Returns

Number of elements.

size_t UDBase::calculateWriteSize ()

Calculates size of buffer, wich can be return by writeToBuffer() method.

Returns

Possible size of buffer.

void UDBase::clearBase ()

Removes all elements from base.

UDBase UDBase::convertToBase (const std::vector< UDBElement > & elements) [static]

Converts vector of UDBElement objects to base.

Parameters

elements Elements to be converted.

Returns

UDBase object.

std::vector< UDBElement > * UDBase::getRawBase () const

Returns pointer to internal base vector object.

Returns

Pointer to internal vector.

UDBase & UDBase::operator+= (const UDBase & other)

Appends other UDBase object values to current database.

Parameters

other UDBase object to be appended.

Returns

reference to UDBase object.

UDBase & UDBase::operator= (const UDBase & other)

Parameters

other UDBase object

Returns

reference to UDBase object.

UDBase & UDBase::operator= (UDBase && other)

Parameters

other UDBase object.

Returns

reference to UDBase object.

void UDBase::readFromBuffer (const std::vector< char > & buf, const size_t & offset = 0, const size_t & bytes_to_read = 0)

Tries to read database from given buffer.

Note

This method can throw std::exception in case of errors.

Parameters

buf Buffer database should be read from.
offset Position in buffer reading should be started from (default value is 0).
bytes_to_read Quantity of bytes to be read. If it is 0 (default), reads whole buffer starting from offset.

void UDBase::readFromBufferInner (const std::vector< char > & buf, const size_t & offset, const size_t & bytes_to_read) [protected]

Internal method used in readFromBuffer() and readFromFile() methods.

Parameters

buf Buffer base to be read from.
offset Number of byte reading to be started from.
bytes_to_read Number of bytes to be read.

void UDBase::readFromFile (const std::filesystem::path & f_path)

Tries to read database from file.

Note

This method can throw std::exception in case of errors.

Parameters

f_path Absolute path to file database should be read from.

virtual void UDBase::removeElement (const UDBElement & el) [virtual]

Removes from base all elements equal to el.

Parameters

el Element to be removed.

virtual void UDBase::removeElements (std::function< bool(const UDBElement &)> predicate) [virtual]

Removes elements from base according to predicate function conditions.

Note

This method can throw std::exception in case of errors.

Parameters

predicate Function to check removing conditions.

virtual void UDBase::replaceElement (const UDBElement & old_el, const UDBElement & new_el) [virtual]

Replaces all elements equal to old_el by new_el.

Parameters

old_el Element to be replaced.
new_el Element to be replaced by.

virtual UDBase UDBase::searchElement (std::function< bool(const UDBElement &)> search_function) [virtual]

Returns all elements that match the conditions specified in the search_function.

Parameters

search_function Function to check conditions.

Returns

Base with found elements.

virtual UDBase UDBase::searchElement (std::function< void(const UDBElement &, UDBase &)> search_function) [virtual]

Returns all elements added to UDBase parameter of search_function.

Parameters

search_function Function to add elements to result;

Returns

Base with found elements.

virtual std::vector< UDBElement > UDBase::searchElementV (std::function< bool(const UDBElement &)> search_function) [virtual]

Returns all elements that match the conditions specified in the search_function.

Parameters

search_function Function to check conditions.

Returns

Vector with found elements.

void UDBase::shrinkToFit ()

Reduces memory usage by freeing unused memory in internal containers.

virtual void UDBase::sortBase (std::function< bool(const UDBElement &, const UDBElement &)> sort_function) [virtual]

Sorts base (quicksort algorithm).

Parameters

sort_function Function to compare elements.

std::vector< UDBase > UDBase::splitBase (const size_t & bytes_limit, const size_t & minimum_elements = size_t(1))

Splits base into bases of smaller size.

Parameters

bytes_limit Maximum permitted size of smaller base.
minimum_elements Minimum elements in smaller base (default value is 1).

Returns

void UDBase::writeToBuffer (std::vector< char > & result)

Writes database to result buffer.

Parameters

result Vector base to be written to.

void UDBase::writeToBufferInner (std::vector< char > & result) [protected]

Internal method used in writeToBuffer() and writeToFile() methods.

Parameters

result Vecto base to be written to.

void UDBase::writeToFile (const std::filesystem::path & f_path)

Writes database to file.

Note

This method can throw std::exception in case of errors.

Parameters

f_path Absolute path to file database should be written to.

Author

Generated automatically by Doxygen for LibUDB from the source code.

Version 1.0.1 LibUDB