Dmitigr Pgfe  1.1beta
The modern C++ API to PostgreSQL
Public Member Functions | Related Functions | List of all members
Data Class Referenceabstract

Represents an abstraction of a data. More...

#include <dmitigr/pgfe/data.hpp>

Public Member Functions

virtual ~Data ()=default
 
Observers and modifiers
virtual Data_format format () const noexcept=0
 
virtual std::size_t size () const noexcept=0
 
virtual bool is_empty () const noexcept=0
 
virtual const char * bytes () const noexcept=0
 
virtual void * memory () noexcept=0
 

Related Functions

(Note that these are not member functions.)

DMITIGR_PGFE_API std::unique_ptr< Data > APIENTRY to_binary_data (const Data *text_data)
 

Constructors

virtual std::unique_ptr< Dataclone () const =0
 
static DMITIGR_PGFE_API std::unique_ptr< Data > APIENTRY make (const char *bytes, std::size_t size, Data_format format=Data_format::text)
 
static DMITIGR_PGFE_API std::unique_ptr< Data > APIENTRY make (const char *bytes)
 
static DMITIGR_PGFE_API std::unique_ptr< Data > APIENTRY make (std::unique_ptr< void, void(*)(void *)> &&storage, std::size_t size, Data_format format=Data_format::binary)
 
static DMITIGR_PGFE_API std::unique_ptr< Data > APIENTRY make (std::string storage, Data_format format=Data_format::text)
 
static DMITIGR_PGFE_API std::unique_ptr< Data > APIENTRY make (std::vector< unsigned char > storage, Data_format format=Data_format::binary)
 

Detailed Description

Represents an abstraction of a data.

The data in such a representation can be sended to the PostgreSQL server (as the parameter value of the prepared statement), or received from such a server (in particular, as the data of the row field or as the asynchronous notification payload).

Constructor & Destructor Documentation

◆ ~Data()

virtual ~Data ( )
virtualdefault

The destructor.

Member Function Documentation

◆ bytes()

virtual const char* bytes ( ) const
pure virtualnoexcept
Returns
The pointer to the unmodifiable character array (which is the representation of the content in the format()). Iff (format() == Data_format::text) then this array is guaranteed to be zero-terminated.
Remarks
Any bits stored in the array shall not be altered!

◆ clone()

virtual std::unique_ptr<Data> clone ( ) const
pure virtual
Returns
The copy of this instance.

◆ format()

virtual Data_format format ( ) const
pure virtualnoexcept
Returns
The data format.

◆ is_empty()

virtual bool is_empty ( ) const
pure virtualnoexcept
Returns
(size() == 0)

◆ make() [1/5]

static DMITIGR_PGFE_API std::unique_ptr<Data> APIENTRY make ( const char *  bytes,
std::size_t  size,
Data_format  format = Data_format::text 
)
static
Returns
The data of the size size from specified bytes. The bytes will be copied into the modifiable internal storage.
Requires
‘(bytes && (format == Data_format::binary || bytes[size] == ’\0'))`

◆ make() [2/5]

static DMITIGR_PGFE_API std::unique_ptr<Data> APIENTRY make ( const char *  bytes)
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ make() [3/5]

static DMITIGR_PGFE_API std::unique_ptr<Data> APIENTRY make ( std::unique_ptr< void, void(*)(void *)> &&  storage,
std::size_t  size,
Data_format  format = Data_format::binary 
)
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns
The data of size size from specified storage. The storage will serve as the internal storage owned by the result data.
Requires
‘(storage && (format == Data_format::binary || static_cast<const char*>(storage.get())[size] == ’\0'))
Effects
(result->memory() == storage.get())

◆ make() [4/5]

static DMITIGR_PGFE_API std::unique_ptr<Data> APIENTRY make ( std::string  storage,
Data_format  format = Data_format::text 
)
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns
The data of size storage.size() from specified storage. The storage will serve as the internal storage owned by the result data.
Effects
(result->memory() == storage.get())

◆ make() [5/5]

static DMITIGR_PGFE_API std::unique_ptr<Data> APIENTRY make ( std::vector< unsigned char >  storage,
Data_format  format = Data_format::binary 
)
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns
The data from the specified storage. The storage will serve as the internal storage owned by the result data.
Requires
‘(format == Data_format::binary || !storage.empty() && storage.back() == ’\0')`
Effects
(result->memory() == reinterpret_cast<char*>(storage.get()))
Remarks
iff (format == Data_format::text) then the result->size() does not count the trailing zero.

◆ memory()

virtual void* memory ( )
pure virtualnoexcept
Returns
The pointer to the modifiable memory space within [0, size()), or nullptr if the content is unmodifiable.

◆ size()

virtual std::size_t size ( ) const
pure virtualnoexcept
Returns
The data size in bytes.

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