C++ Extensions (cppx) Documentation Internal Version
Main | Namespaces | Classes | NamespaceMembers | ClassMembers | Files

stdx::ImplPtr Class Template Reference

template<class T>
class stdx::ImplPtr< T >

The handle/body pattern is a useful idiom for truly separating a class interface from its implementation. With a traditional C++ class changes to the private data member type or adding new private members will require all users of the class to recompile - even though this is strictly an implementation change! The handle/body pattern stores just a pointer in an outer (handle) class and this pointer points to an inner (body) class. The body class contains all implemenation objects. This works well, but a programmer must be careful to correctly allocate/deallocate the body class and manage copy/assigment operators. The ImplPtr class helps with these issues. An example of its use is below:

 class ExampleClass {
 
  public:
   // public members here ...

  private:
   struct Impl;
   stdx::ImplPtr<Impl> impl;

 };

The programmer then defines the nested Impl struct in the source file. The ImplPtr class will automatically use the default Impl contstructor to dynamically allocate a new body object on construction and then correctly delete the body object no destruction. Additionally, copying the ImplPtr causes a _copy_ of the body class to be made as opposed to having two handle classes pointing to the same body class.

This is loosely based on a previously proposed impl_ptr class by Peter Dimov on the boost mailing lists. I've simplified things and included create functions so that classes which use the pimpl idiom do not need to explicitly allocate the impl class. http://groups.yahoo.com/group/boost/files/impl_ptr

Note that AllocFunctions are needed to avoid the situation where we need to constructor or destruct an incomplete type.

List of all members.

Public Methods

Pointer Operators

Detailed Documentation

Constructor & Destructor Documentation

template<class T>
stdx::ImplPtr< T >::ImplPtr  
 

template<class T>
stdx::ImplPtr< T >::ImplPtr T *    ptr,
AllocFunctions< T > *    fns = DefaultAllocFunctions<T>::instance()
 

template<class T>
stdx::ImplPtr< T >::~ImplPtr  
 

template<class T>
stdx::ImplPtr< T >::ImplPtr const ImplPtr< T > &    ptrToCopy
 

Member Function Documentation

template<class T>
ImplPtr& stdx::ImplPtr< T >::operator= const ImplPtr< T > &    ptrToCopy
 

template<class T>
T* stdx::ImplPtr< T >::copy   const
 

template<class T>
T* stdx::ImplPtr< T >::operator->  
 

template<class T>
const T* stdx::ImplPtr< T >::operator->   const
 

template<class T>
T& stdx::ImplPtr< T >::operator *  
 

template<class T>
const T& stdx::ImplPtr< T >::operator *   const
 



The documentation for this class was generated from the following file:
Generated on Mon Aug 15 21:43:10 2005 by Doxygen 1.2.13-20020210 written by Dimitri van Heesch © 1997-2002