Boost logo

Boost :

From: Kevin Atkinson (kevinatk_at_[hidden])
Date: 2000-03-06 15:01:36


Here is a better CopyPtr. Changes so that it will comply better
with boost coding standards and naming conventions will not be well tested
by me because they won't be used in my library. I am a string believer
that all types should be in mixed case with the first letter upper and
which the C++ standards committee felt the same way.

A better ClonePtr should come latter today.

// Copyright (c) 2000
// Kevin Atkinson
//
// Permission to use, copy, modify, distribute and sell this software
// and its documentation for any purpose is hereby granted without
// fee, provided that the above copyright notice appear in all copies
// and that both that copyright notice and this permission notice
// appear in supporting documentation. Kevin Atkinson makes no
// representations about the suitability of this software for any
// purpose. It is provided "as is" without express or implied
// warranty.

#ifndef autil__copy_ptr
#define autil__copy_ptr

namespace autil {

  template <typename T>
  class CopyPtr {
  public:
    T * ptr;

    explicit CopyPtr(T * p = 0) : ptr(p) {}

    CopyPtr(const CopyPtr & other);
    CopyPtr & operator= (const CopyPtr & other);
    void reset(T * other = 0);
    ~CopyPtr();

    T & operator* () const {return *ptr;}
    T * operator-> () const {return ptr;}
    T * get() const {return ptr;}
    operator T * () const {return ptr;}
  };

}

#endif

// Copyright (c) 2000
// Kevin Atkinson
//
// Permission to use, copy, modify, distribute and sell this software
// and its documentation for any purpose is hereby granted without
// fee, provided that the above copyright notice appear in all copies
// and that both that copyright notice and this permission notice
// appear in supporting documentation. Kevin Atkinson makes no
// representations about the suitability of this software for any
// purpose. It is provided "as is" without express or implied
// warranty.

#ifndef autil__copy_ptr_t
#define autil__copy_ptr_t

#include "copy_ptr.hh"

namespace autil {

  template <typename T>
  CopyPtr<T>::CopyPtr(const CopyPtr<T> &other) {
    if (other.ptr != 0)
      ptr = new T(*other.ptr);
    else
      ptr = 0;
  }

  template <typename T>
  CopyPtr<T> & CopyPtr<T>::operator= (const CopyPtr<T> & other)
  {
    delete ptr;
    if (other.ptr != 0)
      ptr = new T(*other.ptr);
    else
      ptr = 0;
    return *this;
  }

  template <typename T>
  void CopyPtr<T>::reset (T * other) {
    delete ptr;
    ptr = other;
  }

  template <typename T>
  CopyPtr<T>::~CopyPtr() {
    delete ptr;
  }

}

#endif

---
Kevin Atkinson
kevinatk_at_[hidden]
http://metalab.unc.edu/kevina/

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk