auto_ptr.h
Go to the documentation of this file.
1 // Copyright (C) 2001, 2002 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 2, or (at your option)
7 // any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING. If not, write to the Free
16 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 // USA.
18 
19 // As a special exception, you may use this file as part of a free software
20 // library without restriction. Specifically, if other files instantiate
21 // templates or use macros or inline functions from this file, or you compile
22 // this file and link it with other files to produce an executable, this
23 // file does not by itself cause the resulting executable to be covered by
24 // the GNU General Public License. This exception does not however
25 // invalidate any other reasons why the executable file might be covered by
26 // the GNU General Public License.
27 
28 /*
29  * Copyright (c) 1997-1999
30  * Silicon Graphics Computer Systems, Inc.
31  *
32  * Permission to use, copy, modify, distribute and sell this software
33  * and its documentation for any purpose is hereby granted without fee,
34  * provided that the above copyright notice appear in all copies and
35  * that both that copyright notice and this permission notice appear
36  * in supporting documentation. Silicon Graphics makes no
37  * representations about the suitability of this software for any
38  * purpose. It is provided "as is" without express or implied warranty.
39  *
40  */
41 
42 
43 
44 #ifndef LIBMESH_AUTO_PTR_H
45 #define LIBMESH_AUTO_PTR_H
46 
47 namespace libMesh
48 {
49 
57 template<typename Tp1>
58 struct AutoPtrRef
59 {
63  Tp1* _ptr;
64 
68  explicit
69  AutoPtrRef(Tp1* p)
70  : _ptr(p) {}
71 };
72 
73 
101 template<typename Tp>
102 class AutoPtr
103 {
104 private:
105 
109  Tp* _ptr;
110 
111 public:
115  typedef Tp element_type;
116 
123  explicit
125  : _ptr(p) {}
126 
135  : _ptr(a.release()) {}
136 
146  template<typename Tp1>
148  : _ptr(a.release()) {}
149 
158  AutoPtr&
160  {
161  reset(a.release());
162  return *this;
163  }
164 
175  template <typename Tp1>
176  AutoPtr&
178  {
179  reset(a.release());
180  return *this;
181  }
182 
195  ~AutoPtr() { delete _ptr; }
196 
205  element_type&
206  operator*() const { return *_ptr; }
207 
214  element_type*
215  operator->() const { return _ptr; }
216 
227  element_type*
228  get() const { return _ptr; }
229 
241  element_type*
243  {
244  element_type* tmp = _ptr;
245  _ptr = 0;
246  return tmp;
247  }
248 
256  void
258  {
259  if (p != _ptr)
260  {
261  delete _ptr;
262  _ptr = p;
263  }
264  }
265 
278  : _ptr(ref._ptr) {}
279 
286  AutoPtr&
288  {
289  if (ref._ptr != this->get())
290  {
291  delete _ptr;
292  _ptr = ref._ptr;
293  }
294  return *this;
295  }
296 
300  template<typename Tp1>
301  operator AutoPtrRef<Tp1>()
302  { return AutoPtrRef<Tp1>(this->release()); }
303 
307  template<typename Tp1>
308  operator AutoPtr<Tp1>()
309  { return AutoPtr<Tp1>(this->release()); }
310 };
311 
312 
313 
314 } // namespace libMesh
315 
316 #endif // LIBMESH_AUTO_PTR_H

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:04 UTC

Hosted By:
SourceForge.net Logo