cartobase 6.0.6
weakobject.h
Go to the documentation of this file.
1/* This software and supporting documentation are distributed by
2 * Institut Federatif de Recherche 49
3 * CEA/NeuroSpin, Batiment 145,
4 * 91191 Gif-sur-Yvette cedex
5 * France
6 *
7 * This software is governed by the CeCILL-B license under
8 * French law and abiding by the rules of distribution of free software.
9 * You can use, modify and/or redistribute the software under the
10 * terms of the CeCILL-B license as circulated by CEA, CNRS
11 * and INRIA at the following URL "http://www.cecill.info".
12 *
13 * As a counterpart to the access to the source code and rights to copy,
14 * modify and redistribute granted by the license, users are provided only
15 * with a limited warranty and the software's author, the holder of the
16 * economic rights, and the successive licensors have only limited
17 * liability.
18 *
19 * In this respect, the user's attention is drawn to the risks associated
20 * with loading, using, modifying and/or developing or reproducing the
21 * software by the user in light of its specific status of free software,
22 * that may mean that it is complicated to manipulate, and that also
23 * therefore means that it is reserved for developers and experienced
24 * professionals having in-depth computer knowledge. Users are therefore
25 * encouraged to load and test the software's suitability as regards their
26 * requirements in conditions enabling the security of their systems and/or
27 * data to be ensured and, more generally, to use and operate it in the
28 * same conditions as regards security.
29 *
30 * The fact that you are presently reading this means that you have had
31 * knowledge of the CeCILL-B license and that you accept its terms.
32 */
33
34#ifndef CARTOBASE_SMART_WEAKOBJECT_H
35#define CARTOBASE_SMART_WEAKOBJECT_H
36
37
40#include <map>
41
42
43namespace carto
44{
45
46 template <typename T> class weak_shared_ptr;
47
49{
50
51 typedef weak_ptr<WeakObject> WeakPtr;
52 typedef weak_shared_ptr<WeakObject> WeakSharedPtr;
53
54 public:
55
56 template <typename T> void attachWeakPtr( weak_ptr<T>& ) const;
57 template <typename T> void detachWeakPtr( weak_ptr<T>& ) const;
58 template <typename T> void attachWeakPtr( weak_shared_ptr<T>& ) const;
59 template <typename T> void detachWeakPtr( weak_shared_ptr<T>& ) const;
60 virtual ~WeakObject();
61
62 protected:
63
67
68 private:
69
70 void attachWeakPtr( WeakPtr* ) const;
71 void detachWeakPtr( WeakPtr* ) const;
72 void attachWeakPtr( WeakSharedPtr* ) const;
73 void detachWeakPtr( WeakSharedPtr* ) const;
74 void notifyObervers() const;
75
76 mutable std::map<WeakPtr*, bool> observers;
77
78};
79
80
81template <typename T>
82inline
84{
85 attachWeakPtr( reinterpret_cast<WeakPtr*>( &ptr ) );
86}
87
88
89template <typename T>
90inline
92{
93 detachWeakPtr( reinterpret_cast<WeakPtr*>( &ptr ) );
94}
95
96
97template <typename T>
98inline
100{
101 attachWeakPtr( reinterpret_cast<WeakSharedPtr*>( &ptr ) );
102}
103
104
105template <typename T>
106inline
108{
109 detachWeakPtr( reinterpret_cast<WeakSharedPtr*>( &ptr ) );
110}
111
112
113} // namespace carto
114
115
116#endif
void attachWeakPtr(weak_ptr< T > &) const
Definition weakobject.h:83
void detachWeakPtr(weak_ptr< T > &) const
Definition weakobject.h:91
virtual ~WeakObject()
WeakObject & operator=(const WeakObject &)
WeakObject(const WeakObject &)
Observer pointer, observing a shfj::WeakObject.
Definition weakptr.h:69
weak_shared_ptr: increments a reference count, is told and becomes null whenever the shared object is...
Definition sharedptr.h:95