File: clone_ptr.hpp

package info (click to toggle)
aspell 0.60.6-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 10,000 kB
  • ctags: 4,862
  • sloc: sh: 48,145; cpp: 22,153; perl: 1,546; ansic: 1,535; makefile: 684; sed: 16
file content (54 lines) | stat: -rw-r--r-- 1,420 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) 2001
// 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__clone_ptr
#define autil__clone_ptr

#include "generic_copy_ptr.hpp"

namespace acommon {

  template <typename T>
  class ClonePtr 
  {
    struct Parms {
      T * clone(const T * ptr) const;
      void assign(T * & rhs, const T * lhs) const;
      void del(T * ptr);
    };
    GenericCopyPtr<T, Parms> impl;

  public:

    explicit ClonePtr(T * p = 0) : impl(p) {}
    ClonePtr(const ClonePtr & other) : impl(other.impl) {}

    ClonePtr & operator=(const ClonePtr & other) {
      impl = other.impl; 
      return *this;
    }

    void assign(const T * other) {impl.assign(other);}
    void reset(T * other = 0)    {impl.reset(other);}
    
    T & operator*  () const {return *impl;}
    T * operator-> () const {return impl;}
    T * get()         const {return impl;}
    operator T * ()   const {return impl;}

    T * release() {return impl.release();}
  };
  
}

#endif