Class Template manual_ptr

Description
Headers
Reference
Synopsis
Class Template manual_ptr

Description

The class template manual_ptr is a Smart Interface Pointer which supports manual resource management. Objects managed by instances of manual_ptr are never freed automatically; instead, manual_ptr allows the programmer to delete the bound object using the member function free.

It is recommended that programmers use the other Smart Interface Pointers and Smart References most of the time. Manual resource management is appropriate somtimes, however; for example, without something like manual_ptr it would not be possible to implement release() functions for unique_ptr and unique_obj.

Headers

<boost/interfaces/manual_ptr.hpp>

Reference

Synopsis

namespace boost { namespace interfaces {

template<typename Interface>
class manual_ptr {
public:
    typedef typename fixed_view<Interface> element_type;

        // Constructors

    manual_ptr();

    template<typename T>
    explicit manual_ptr(T* t);

    manual_ptr(const manual_ptr& ptr);

    template<typename Subinterface>
    manual_ptr(const manual_ptr<Subinterface>& ptr);

        // Assignment

    manual_ptr& operator=(manual_ptr ptr);

    template<typename Subinterface>    
    manual_ptr& operator=(manual_ptr<Subinterface> ptr);

        // Smart pointer interface

    element_type* get() const;

    element_type& operator*() const;

    element_type* operator->() const;

    void reset();

    template<typename T>
    void reset(T* t);

    operator unspecified-bool-type() const;

    void swap(manual_ptr& p);

    void free();
};

} } // End namespace boost::interfaces

Class Template manual_ptr

Template Parameters
Interface-

An interface defined using the Interface Definition Language (IDL).

manual_ptr::element_type

    typedef typename fixed_view<T> element_type;

Used by the dereferencing operators, in place of the template parameter Interface, to help prevent resource leaks and double deletes. See Example.

manual_ptr::manual_ptr

    manual_ptr();

Constructs an empty manual_ptr. Never throws.

manual_ptr::manual_ptr

    manual_ptr(const manual_ptr& ptr);

    template<typename Subinterface>
    manual_ptr(const manual_ptr<Subinterface>& ptr);

Constructs a manual_ptr bound to the same object as the given manual_ptr. Never throws.

manual_ptr::manual_ptr

    template<typename T>
    explicit manual_ptr(T* t);
Template Parameters
T-

A class implementing Interface. The type T must be complete and have an accessible destructor, but need not be complete at the point t is freed.

Constructs an instance of manual_ptr bound to the given object.

manual_ptr::operator=

    manual_ptr& operator=(manual_ptr ptr);

    template<typename Subinterface>    
    manual_ptr& operator=(manual_ptr<Subinterface> ptr);

Binds this instance of manual_ptr to the same object as the given manual_ptr. Never throws.

manual_ptr::get

    element_type* get() const;

Returns a pointer through which member functions of the bound object can be accessed. Never throws.

manual_ptr::operator*

    element_type& operator*() const;

Returns a reference through which member functions of the bound object can be accessed. Never throws.

manual_ptr::operator->

    element_type* operator->() const;

Returns a pointer through which member functions of the bound object can be accessed. Never throws.

manual_ptr::reset

    void reset();

If there is currently a bound object, this member causes it to become unbound.

manual_ptr::reset

    template<typename T>
    void reset(T* t);
Template Parameters
T-

A class implementing Interface. The type T must be complete and have an accessible destructor, but need not be complete at the point t is freed.

If there is currently a bound object, this member causes it to become unbound. Next, it binds this instance of manual_ptr to the given object. Never throws

manual_ptr::operator unspecified-bool-type()

    operator unspecified-bool-type() const;

Returns an unspecified value which, when used in boolean contexts, is equivalent to get() != 0. Never throws.

manual_ptr::swap

    void swap(manual_ptr& p);

Exchanges the content of this instance of manual_ptr with that of the given instance. Never throws.

manual_ptr::free

    void free();

Frees the bound object using delete. Throws only if the destructor of the bound object throws.


Sha'arei Tefila, an Orthodox Shul (Synagogue) in Salt Lake City, Utah Chabad Lubavitch of Utah