libpqxx  v4.0-1
C++ library for PostgreSQL
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pqxx::internal::PQAlloc< T, DELETER > Class Template Reference

Reference-counted smart pointer to libpq-allocated object. More...

#include <util.hxx>

Collaboration diagram for pqxx::internal::PQAlloc< T, DELETER >:

Public Types

typedef T content_type
 

Public Member Functions

 PQAlloc () throw ()
 
 PQAlloc (const PQAlloc &rhs) throw ()
 
 PQAlloc (T *obj) throw ()
 Assume ownership of a pointer. More...
 
 ~PQAlloc () throw ()
 
T * get () const throw ()
 Obtain underlying pointer. More...
 
 operator bool () const throw ()
 Is this pointer non-null? More...
 
bool operator! () const throw ()
 Is this pointer null? More...
 
T & operator* () const throw (PGSTD::logic_error)
 Dereference pointer. More...
 
T * operator-> () const throw (PGSTD::logic_error)
 Dereference pointer. More...
 
PQAllocoperator= (const PQAlloc &rhs) throw ()
 
void reset () throw ()
 
void swap (PQAlloc &rhs) throw ()
 

Private Member Functions

void loseref () throw ()
 Free and reset current pointer (if any) More...
 
void makeref (T *p) throw ()
 
void makeref (const PQAlloc &rhs) throw ()
 
void redoref (const PQAlloc &rhs) throw ()
 
void redoref (T *obj) throw ()
 

Private Attributes

T * m_Obj
 
refcount m_rc
 

Detailed Description

template<typename T, void(*)(T *) DELETER = freepqmem_templated<T>>
class pqxx::internal::PQAlloc< T, DELETER >

Reference-counted smart pointer to libpq-allocated object.

Keep track of a libpq-allocated object, and free it once all references to it have died.

The memory is freed with PQfreemem() by default. This matters on Windows, where apparently under some circumstances, memory allocated by a DLL must be freed by the same DLL.

Warning
Copying, swapping, and destroying PQAlloc objects that refer to the same underlying libpq-allocated block is not thread-safe. If you wish to pass reference-counted objects around between threads, make sure that each of these operations is protected against concurrency with similar operations on the same object–or other copies of the same object.

Member Typedef Documentation

template<typename T, void(*)(T *) DELETER = freepqmem_templated<T>>
typedef T pqxx::internal::PQAlloc< T, DELETER >::content_type

Constructor & Destructor Documentation

template<typename T, void(*)(T *) DELETER = freepqmem_templated<T>>
pqxx::internal::PQAlloc< T, DELETER >::PQAlloc ( ) throw ()
inline
template<typename T, void(*)(T *) DELETER = freepqmem_templated<T>>
pqxx::internal::PQAlloc< T, DELETER >::PQAlloc ( const PQAlloc< T, DELETER > &  rhs) throw ()
inline
template<typename T, void(*)(T *) DELETER = freepqmem_templated<T>>
pqxx::internal::PQAlloc< T, DELETER >::~PQAlloc ( ) throw ()
inline
template<typename T, void(*)(T *) DELETER = freepqmem_templated<T>>
pqxx::internal::PQAlloc< T, DELETER >::PQAlloc ( T *  obj) throw ()
inlineexplicit

Assume ownership of a pointer.

Warning
Don't to this more than once for a given object!

Member Function Documentation

template<typename T, void(*)(T *) DELETER = freepqmem_templated<T>>
T* pqxx::internal::PQAlloc< T, DELETER >::get ( ) const throw ()
inline

Obtain underlying pointer.

Ownership of the pointer's memory remains with the PQAlloc object

template<typename T, void(*)(T *) DELETER = freepqmem_templated<T>>
void pqxx::internal::PQAlloc< T, DELETER >::loseref ( ) throw ()
inlineprivate

Free and reset current pointer (if any)

template<typename T, void(*)(T *) DELETER = freepqmem_templated<T>>
void pqxx::internal::PQAlloc< T, DELETER >::makeref ( T *  p) throw ()
inlineprivate
template<typename T, void(*)(T *) DELETER = freepqmem_templated<T>>
void pqxx::internal::PQAlloc< T, DELETER >::makeref ( const PQAlloc< T, DELETER > &  rhs) throw ()
inlineprivate
template<typename T, void(*)(T *) DELETER = freepqmem_templated<T>>
pqxx::internal::PQAlloc< T, DELETER >::operator bool ( ) const throw ()
inline

Is this pointer non-null?

template<typename T, void(*)(T *) DELETER = freepqmem_templated<T>>
bool pqxx::internal::PQAlloc< T, DELETER >::operator! ( ) const throw ()
inline

Is this pointer null?

template<typename T, void(*)(T *) DELETER = freepqmem_templated<T>>
T& pqxx::internal::PQAlloc< T, DELETER >::operator* ( ) const throw (PGSTD::logic_error)
inline

Dereference pointer.

Throws a logic_error if the pointer is null.

template<typename T, void(*)(T *) DELETER = freepqmem_templated<T>>
T* pqxx::internal::PQAlloc< T, DELETER >::operator-> ( ) const throw (PGSTD::logic_error)
inline

Dereference pointer.

Throws a logic_error if the pointer is null.

template<typename T, void(*)(T *) DELETER = freepqmem_templated<T>>
PQAlloc& pqxx::internal::PQAlloc< T, DELETER >::operator= ( const PQAlloc< T, DELETER > &  rhs) throw ()
inline
template<typename T, void(*)(T *) DELETER = freepqmem_templated<T>>
void pqxx::internal::PQAlloc< T, DELETER >::redoref ( const PQAlloc< T, DELETER > &  rhs) throw ()
inlineprivate
template<typename T, void(*)(T *) DELETER = freepqmem_templated<T>>
void pqxx::internal::PQAlloc< T, DELETER >::redoref ( T *  obj) throw ()
inlineprivate
template<typename T, void(*)(T *) DELETER = freepqmem_templated<T>>
void pqxx::internal::PQAlloc< T, DELETER >::reset ( ) throw ()
inline
template<typename T, void(*)(T *) DELETER = freepqmem_templated<T>>
void pqxx::internal::PQAlloc< T, DELETER >::swap ( PQAlloc< T, DELETER > &  rhs) throw ()
inline

Member Data Documentation

template<typename T, void(*)(T *) DELETER = freepqmem_templated<T>>
T* pqxx::internal::PQAlloc< T, DELETER >::m_Obj
private
template<typename T, void(*)(T *) DELETER = freepqmem_templated<T>>
refcount pqxx::internal::PQAlloc< T, DELETER >::m_rc
mutableprivate

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