File: clone_ptr-t.hpp

package info (click to toggle)
aspell 0.60.8.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,336 kB
  • sloc: cpp: 24,378; sh: 12,340; perl: 1,924; ansic: 1,661; makefile: 852; sed: 16
file content (45 lines) | stat: -rw-r--r-- 1,145 bytes parent folder | download | duplicates (13)
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
// 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_t
#define autil__clone_ptr_t

#include "clone_ptr.hpp"
#include <typeinfo>
#include "generic_copy_ptr-t.hpp"

namespace acommon {

  template <typename T>
  inline T * ClonePtr<T>::Parms::clone(const T * ptr) const {
    return ptr->clone();
  }

  template <typename T>
  void ClonePtr<T>::Parms::assign(T * & rhs, const T * lhs) const {
    if (typeid(*rhs) == typeid(*lhs)) {
      rhs->assign(lhs);
    } else {
      T * temp = rhs;
      rhs = lhs->clone();
      delete temp;
    }
  }

  template <typename T>
  inline void ClonePtr<T>::Parms::del(T * ptr) {
    delete ptr;
  }

}

#endif