pstore2
Public Member Functions | Protected Member Functions | List of all members
pstore::transaction_base Class Reference

The database transaction class. More...

#include <transaction.hpp>

Inheritance diagram for pstore::transaction_base:
Inheritance graph
[legend]

Public Member Functions

 transaction_base (transaction_base const &)=delete
 
 transaction_base (transaction_base &&rhs) noexcept
 
transaction_baseoperator= (transaction_base const &)=delete
 
transaction_baseoperator= (transaction_base &&rhs) noexcept=delete
 
databasedb () noexcept
 
database const & db () const noexcept
 
bool is_open () const noexcept
 Returns true if data has been added to this transaction, but not yet committed. More...
 
transaction_basecommit ()
 Commits all modifications made to the data store as part of this transaction. More...
 
transaction_baserollback () noexcept
 Discards all modifications made to the data store as part of this transaction. More...
 
std::uint64_t size () const noexcept
 Returns the number of bytes allocated in this transaction.
 
std::shared_ptr< void const > getro (address const addr, std::size_t const size)
 
template<typename T , typename = typename std::enable_if<std::is_standard_layout<T>::value>::type>
std::shared_ptr< T const > getro (extent< T > const &ex)
 
template<typename T , typename = typename std::enable_if<std::is_standard_layout<T>::value>::type>
std::shared_ptr< T const > getro (typed_address< T > const addr, std::size_t const elements=1)
 
std::shared_ptr< void > getrw (address const addr, std::size_t const size)
 
template<typename T , typename = typename std::enable_if<std::is_standard_layout<T>::value>::type>
std::shared_ptr< T > getrw (extent< T > const &ex)
 
template<typename T , typename = typename std::enable_if<std::is_standard_layout<T>::value>::type>
std::shared_ptr< T > getrw (typed_address< T > const addr, std::size_t const elements=1)
 
virtual address allocate (std::uint64_t size, unsigned align)
 
template<typename Ty >
address allocate ()
 Extend the database store ensuring that there's enough room for an instance of the template type. More...
 
std::pair< std::shared_ptr< void >, addressalloc_rw (std::size_t size, unsigned align)
 Allocates sufficient space in the transaction for 'size' bytes at an alignment given by 'align' and returns both a writable pointer to the new space and its address. More...
 
template<typename Ty , typename = typename std::enable_if<std::is_standard_layout<Ty>::value>::type>
auto alloc_rw (std::size_t const num=1) -> std::pair< std::shared_ptr< Ty >, typed_address< Ty >>
 Allocates sufficient space in the transaction for one or more new instances of type 'Ty' and returns both a writable pointer to the new space and its address. More...
 

Protected Member Functions

 transaction_base (database &db)
 

Detailed Description

The database transaction class.

When a transaction object is instantiated, a transation begins. Every subsequent operation can be potentially undone if the rollback() method is called. The commit() method commits the work performed by all operations since the start of the transaction.

Similarly, the rollback() method command undoes all of the work performed by all operations since the start of the transaction. If neither the commit() nor rollback() methods are called before the object is destroyed, a commit() is performed by the destructor (unless an exception is being unwound). A transaction is a scope in which operations are performed together and committed, or completely reversed.

Constructor & Destructor Documentation

◆ transaction_base()

pstore::transaction_base::transaction_base ( transaction_base &&  rhs)
noexcept

OCLINT(PH - don't warn about the assert macro)

Member Function Documentation

◆ alloc_rw() [1/2]

std::pair< std::shared_ptr< void >, address > pstore::transaction_base::alloc_rw ( std::size_t  size,
unsigned  align 
)

Allocates sufficient space in the transaction for 'size' bytes at an alignment given by 'align' and returns both a writable pointer to the new space and its address.

Parameters
sizeThe number of bytes of storage to allocate.
alignThe alignment of the newly allocated storage. Must be a non-zero power of two.
Returns
A std::pair which contains a writable pointer to the newly allocated space and the address of that space.
Note
The newly allocated space is not initialized.

◆ alloc_rw() [2/2]

template<typename Ty , typename = typename std::enable_if<std::is_standard_layout<Ty>::value>::type>
auto pstore::transaction_base::alloc_rw ( std::size_t const  num = 1) -> std::pair<std::shared_ptr<Ty>, typed_address<Ty>>
inline

Allocates sufficient space in the transaction for one or more new instances of type 'Ty' and returns both a writable pointer to the new space and its address.

Ty must be a "standard layout" type.

Parameters
numThe number of instances of type Ty for which space should be allocated.
Returns
A std::pair which contains a writable pointer to the newly allocated space and the address of that space.
Note
The newly allocated space it not initialized.

◆ allocate() [1/2]

address pstore::transaction_base::allocate ( std::uint64_t  size,
unsigned  align 
)
virtual

Extend the database store ensuring that there's enough room for the requested number of bytes with any additional padding to statify the alignment requirement.

Parameters
sizeThe number of bytes of storages to be allocated.
alignThe alignment of the allocated storage. Must be a power of 2.
Returns
The database address of the new storage.
Note
The newly allocated space is not initialized.

◆ allocate() [2/2]

template<typename Ty >
address pstore::transaction_base::allocate ( )
inline

Extend the database store ensuring that there's enough room for an instance of the template type.

Returns
The database address of the new storage.
Note
The newly allocated space is not initialized.

◆ commit()

transaction_base & pstore::transaction_base::commit ( )

Commits all modifications made to the data store as part of this transaction.

Modifications are visible to other processes when the commit is complete.

OCLINT(PH - don't warn about the assert macro)

◆ is_open()

bool pstore::transaction_base::is_open ( ) const
inlinenoexcept

Returns true if data has been added to this transaction, but not yet committed.

In other words, if it returns false, calls to commit() or rollback() are noops.

◆ rollback()

transaction_base & pstore::transaction_base::rollback ( )
noexcept

Discards all modifications made to the data store as part of this transaction.

OCLINT(PH - don't warn about the assert macro)


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