fastcgi++
A C++ FastCGI/Web API
Public Member Functions | Private Attributes | List of all members
Fastcgipp::Block Class Reference

Data structure to hold a block of raw data. More...

#include <fastcgi++/block.hpp>

Public Member Functions

 Block ()
 Initialize an empty block. More...
 
 Block (const size_t size_)
 Initialize a block with equal size and reserve. More...
 
 Block (const char *const data, const size_t size_)
 Initialize a block with equal size and reserve from source data. More...
 
void assign (const char *const data, const size_t size_)
 Assign a sequence a data to the block. More...
 
 Block (Block &&x)
 Steal the data from another block. More...
 
Blockoperator= (Block &&x)
 Steal the data from another block. More...
 
size_t reserve () const
 See the reserve size. More...
 
void reserve (size_t x)
 Set the reserve size. More...
 
size_t size () const
 See the relevant data size. More...
 
void size (size_t x)
 Set the relevant data size. More...
 
char * begin ()
 Pointer to the first element. More...
 
const char * begin () const
 Constant pointer to the first element. More...
 
char * end ()
 Pointer to 1+ the last element. More...
 
const char * end () const
 Constant pointer to 1+ the last element. More...
 
void clear ()
 Deallocate memory and set size and reserve to zero. More...
 
 Block (const Block &)=delete
 
Blockoperator= (const Block &)=delete
 

Private Attributes

size_t m_reserve
 Total bytes allocated. More...
 
size_t m_size
 Size of relevant part of data allocation. More...
 
std::unique_ptr< char[]> m_data
 Point to allocated data. More...
 

Detailed Description

Data structure to hold a block of raw data.

This is basically a stripped down std::vector. It contains a contiguous block of memory with two sizes associated with it. The reserve indicates how much data is actually allocated while the size tells us how much of the data is relevant. The motivation for this as opposed to a vector is that this lacks element initialization.

Definition at line 44 of file block.hpp.

Constructor & Destructor Documentation

◆ Block() [1/5]

Fastcgipp::Block::Block ( )

Initialize an empty block.

Definition at line 50 of file block.cpp.

◆ Block() [2/5]

Fastcgipp::Block::Block ( const size_t  size_)

Initialize a block with equal size and reserve.

Definition at line 55 of file block.cpp.

◆ Block() [3/5]

Fastcgipp::Block::Block ( const char *const  data,
const size_t  size_ 
)

Initialize a block with equal size and reserve from source data.

Definition at line 61 of file block.cpp.

References m_data.

◆ Block() [4/5]

Fastcgipp::Block::Block ( Block &&  x)

Steal the data from another block.

Definition at line 69 of file block.cpp.

◆ Block() [5/5]

Fastcgipp::Block::Block ( const Block )
delete

Member Function Documentation

◆ assign()

void Fastcgipp::Block::assign ( const char *const  data,
const size_t  size_ 
)

Assign a sequence a data to the block.

If the reserve if smaller the requested size then reallocation occurs. Otherwise the allocation is unchanged.

Definition at line 105 of file block.cpp.

◆ begin() [1/2]

char* Fastcgipp::Block::begin ( )
inline

◆ begin() [2/2]

const char* Fastcgipp::Block::begin ( ) const
inline

Constant pointer to the first element.

Definition at line 109 of file block.hpp.

References m_data.

◆ clear()

void Fastcgipp::Block::clear ( )

Deallocate memory and set size and reserve to zero.

Definition at line 98 of file block.cpp.

◆ end() [1/2]

char* Fastcgipp::Block::end ( )
inline

Pointer to 1+ the last element.

Definition at line 115 of file block.hpp.

References m_data, and m_size.

Referenced by Fastcgipp::FcgiStreambuf< charT >::emptyBuffer(), Fastcgipp::Manager_base::localHandler(), and Fastcgipp::Transceiver::transmit().

◆ end() [2/2]

const char* Fastcgipp::Block::end ( ) const
inline

Constant pointer to 1+ the last element.

Definition at line 121 of file block.hpp.

References m_data, and m_size.

◆ operator=() [1/2]

Fastcgipp::Block & Fastcgipp::Block::operator= ( Block &&  x)

Steal the data from another block.

Definition at line 78 of file block.cpp.

References m_reserve.

◆ operator=() [2/2]

Block& Fastcgipp::Block::operator= ( const Block )
delete

◆ reserve() [1/2]

size_t Fastcgipp::Block::reserve ( ) const
inline

◆ reserve() [2/2]

void Fastcgipp::Block::reserve ( size_t  x)

Set the reserve size.

Unlike std::vector this always obeys your command even if you are decreasing the reserve size. All data is copied over when a reserve is changed.

Definition at line 32 of file block.cpp.

References m_data, m_reserve, and m_size.

◆ size() [1/2]

size_t Fastcgipp::Block::size ( ) const
inline

See the relevant data size.

Definition at line 94 of file block.hpp.

References m_size.

Referenced by Fastcgipp::FcgiStreambuf< charT >::dump(), Fastcgipp::FcgiStreambuf< charT >::emptyBuffer(), and Fastcgipp::Transceiver::receive().

◆ size() [2/2]

void Fastcgipp::Block::size ( size_t  x)

Set the relevant data size.

Definition at line 88 of file block.cpp.

Member Data Documentation

◆ m_data

std::unique_ptr<char[]> Fastcgipp::Block::m_data
private

Point to allocated data.

Definition at line 54 of file block.hpp.

Referenced by begin(), Block(), end(), and reserve().

◆ m_reserve

size_t Fastcgipp::Block::m_reserve
private

Total bytes allocated.

Definition at line 48 of file block.hpp.

Referenced by operator=(), and reserve().

◆ m_size

size_t Fastcgipp::Block::m_size
private

Size of relevant part of data allocation.

Definition at line 51 of file block.hpp.

Referenced by end(), reserve(), and size().


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