Version: 9.16.0
SharedPtr.hxx
Go to the documentation of this file.
1// Copyright (C) 2006-2026 CEA, EDF
2//
3// This library is free software; you can redistribute it and/or
4// modify it under the terms of the GNU Lesser General Public
5// License as published by the Free Software Foundation; either
6// version 2.1 of the License, or (at your option) any later version.
7//
8// This library is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11// Lesser General Public License for more details.
12//
13// You should have received a copy of the GNU Lesser General Public
14// License along with this library; if not, write to the Free Software
15// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16//
17// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18//
19
20#ifndef __SHAREDPTR_HXX__
21#define __SHAREDPTR_HXX__
22
28template<class T>
30{
31private:
33public:
34 SharedPtr(T *ptr):_ptr(ptr) { }
35 SharedPtr(const SharedPtr<T>& other):_ptr(other._ptr) { _ptr->incrRef(); }
36 SharedPtr<T> &operator=(const SharedPtr<T>& other);
37 T &operator*() { return *_ptr; }
38 const T &operator*() const { return *_ptr; }
39 T *operator->() { return _ptr; }
40 const T *operator->() const { return _ptr; }
41 ~SharedPtr() { _ptr->decrRef(); }
42 operator T *() { return _ptr; }
43 operator const T *() const { return _ptr; }
44 operator T &() { return *_ptr; }
45 operator const T &() const { return *_ptr; }
46 SharedPtr<T> operator[](int i) const;
47 SharedPtr<T> operator[](const char *key) const;
48};
49
50template<class T>
52{
53 _ptr->decrRef();
54 _ptr=other._ptr;
55 _ptr->incrRef();
56 return *this;
57}
58
59template<class T>
61{
62 return (*_ptr)[i];
63}
64
65template<class T>
67{
68 return (*_ptr)[key];
69}
70
71#endif
: Allow to manage memory of instances of T. The only constraint on T is to have method incrRef and De...
Definition: SharedPtr.hxx:30
const T & operator*() const
Definition: SharedPtr.hxx:38
const T * operator->() const
Definition: SharedPtr.hxx:40
SharedPtr(const SharedPtr< T > &other)
Definition: SharedPtr.hxx:35
SharedPtr< T > operator[](int i) const
Definition: SharedPtr.hxx:60
SharedPtr(T *ptr)
Definition: SharedPtr.hxx:34
T * operator->()
Definition: SharedPtr.hxx:39
SharedPtr< T > & operator=(const SharedPtr< T > &other)
Definition: SharedPtr.hxx:51
T & operator*()
Definition: SharedPtr.hxx:37