Gromacs  2016.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Public Member Functions
gmx::PrivateImplPointer< Impl > Class Template Reference

#include <gromacs/utility/classhelpers.h>

Description

template<class Impl>
class gmx::PrivateImplPointer< Impl >

Helper class to manage a pointer to a private implementation class.

This helper provides the following benefits (all but the last could also be achieved with std::unique_ptr):

Move construction and assignment are also disallowed, but can be enabled by providing explicit move constructor and/or assignment.

Intended use:

// In exampleclass.h
class ExampleClass
{
public:
ExampleClass();
~ExampleClass(); // Must not be defined inline
// <...>
private:
class Impl;
PrivateImplPointer<Impl> impl_;
};
// In exampleclass.cpp
// <definition of ExampleClass::Impl>
ExampleClass::ExampleClass()
: impl_(new Impl)
{
}
ExampleClass::~ExampleClass()
{
}

Public Member Functions

 PrivateImplPointer (std::nullptr_t)
 Allow implicit initialization from nullptr to support comparison.
 
 PrivateImplPointer (Impl *ptr)
 Initialize with the given implementation class.
 
void reset (Impl *ptr)
 Sets a new implementation class and destructs the previous one. More...
 
Impl * get ()
 Access the raw pointer.
 
Impl * operator-> ()
 Access the implementation class as with a raw pointer.
 
Impl & operator* ()
 Access the implementation class as with a raw pointer.
 
const Impl * operator-> () const
 Access the implementation class as with a raw pointer.
 
const Impl & operator* () const
 Access the implementation class as with a raw pointer.
 
 operator bool () const
 Allows testing whether the implementation is initialized.
 
bool operator== (const PrivateImplPointer &other) const
 Tests for equality (mainly useful against nullptr).
 
bool operator!= (const PrivateImplPointer &other) const
 Tests for inequality (mainly useful against nullptr).
 

Member Function Documentation

template<class Impl>
void gmx::PrivateImplPointer< Impl >::reset ( Impl *  ptr)
inline

Sets a new implementation class and destructs the previous one.

Needed, e.g., to implement lazily initializable or copy-assignable classes.


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