Main Page   Namespace List   Class Hierarchy   Compound List   File List   Header Files   Namespace Members   Compound Members   File Members  

arg_deep_copy.h

This is the verbatim text of the arg_deep_copy.h include file.

#ifndef ARG_DEEP_COPY_H
#define ARG_DEEP_COPY_H

#ifndef ARG_COMPILER_H
#include "arg_compiler.h"
#endif

#ifndef ARG_DEEP_COPY_UTILS_H
#include "arg_deep_copy_utils.h"
#endif

namespace arg
{
    template<class pointee_type>
    class deep_copy_ptr
    {
    public:
    
    // Construction

        deep_copy_ptr();
        
        explicit deep_copy_ptr(pointee_type* p) throw();
        
        deep_copy_ptr(const deep_copy_ptr& rhs);

        ~deep_copy_ptr() throw();

    
    // Accessors

        pointee_type* get() const;
    
        pointee_type* operator->() const;
    
        pointee_type& operator*() const;

    
    // Mutators

        deep_copy_ptr& operator=(const deep_copy_ptr& rhs);

        pointee_type* release();

        void reset(pointee_type* p) throw();
        
        void swap(deep_copy_ptr& with) throw();

        
    private:
        pointee_type*   pointee;
    };
    


    template<class pointee_type>
    class body_part_ptr
    {
    public:
    
    //  Construction & assignment

        body_part_ptr() : pointee() {}
        
        explicit body_part_ptr(pointee_type* p) throw() : pointee(p) {}
        
        // Default copy is OK

    
    //  Accessors - (overloaded on const)

        const pointee_type* get() const         { return pointee.get(); }
    
        pointee_type* get()                     { return pointee.get(); }
    
        const pointee_type* operator->() const  { return pointee.get(); }
    
        pointee_type* operator->()              { return pointee.get(); }
    
        const pointee_type& operator*() const   { return *pointee; }

        pointee_type& operator*()               { return *pointee; }

    
    //  Mutators

        pointee_type* release()                 { return pointee.release(); }

        void reset(pointee_type* p) throw()     { pointee.reset(p); }
        
        void swap(deep_copy_ptr<pointee_type>& with) throw()
            { pointee.swap(with); }
        
        operator deep_copy_ptr<pointee_type>&() { return pointee; }

        // Default assignment is OK

        
    private:
        deep_copy_ptr<pointee_type> pointee;
    };


    template<class pointee_type>
    inline deep_copy_ptr<pointee_type>::deep_copy_ptr() : pointee(0) {}
        
    template<class pointee_type>
    inline deep_copy_ptr<pointee_type>::deep_copy_ptr(pointee_type* p) throw() 
        : pointee(p) {}
        
    template<class pointee_type>
    inline deep_copy_ptr<pointee_type>::deep_copy_ptr(const deep_copy_ptr& rhs)
        : pointee(deep_copy(rhs.pointee)) {}
    
    template<class pointee_type>
    inline deep_copy_ptr<pointee_type>& deep_copy_ptr<pointee_type>::
    operator=(const deep_copy_ptr& rhs)
    {
        pointee_type* p = deep_copy(rhs.pointee);
            
        delete pointee, pointee = p;
        
        return *this;
    }           

    template<class pointee_type>
    inline deep_copy_ptr<pointee_type>::~deep_copy_ptr() throw()
        {
            delete pointee;
        }

    template<class pointee_type>
    pointee_type* deep_copy_ptr<pointee_type>::get() const
    {
        return pointee;
    }
    
    template<class pointee_type>
    inline pointee_type* deep_copy_ptr<pointee_type>::operator->() const
    {
        return pointee;
    }
    
    template<class pointee_type>
    inline pointee_type& deep_copy_ptr<pointee_type>::operator*() const
    {
        return *pointee;
    }

    template<class pointee_type>
    inline pointee_type* deep_copy_ptr<pointee_type>::release() 
    {
        pointee_type* temp = pointee;
        pointee = 0;
        return temp;
    }

    template<class pointee_type>
    inline void deep_copy_ptr<pointee_type>::reset(pointee_type* p) throw()
    {
        pointee_type* temp = pointee;
        pointee = p;
        delete temp;
    }
        
    template<class pointee_type>
    inline void deep_copy_ptr<pointee_type>::swap(deep_copy_ptr& with) throw()
    {
        pointee_type* temp = pointee;
        pointee = with.pointee;
        with.pointee = temp;
    }
}


namespace std
{
    template<class pointee_type>
    inline void swap(
        ::arg::deep_copy_ptr<pointee_type>& lhs, 
        ::arg::deep_copy_ptr<pointee_type>& rhs) throw()
    {
        lhs.swap(rhs);
    }

    template<class pointee_type>
    inline void swap(
        ::arg::body_part_ptr<pointee_type>& lhs, 
        ::arg::body_part_ptr<pointee_type>& rhs) throw()
    {
        lhs.swap(rhs);
    }
}

#endif

Copyright 1999-2000 Alan Griffiths