apt 3.2.0 commandline package manager

weakptr.h
1/* weakptr.h - An object which supports weak pointers.
2 *
3 * Copyright (C) 2010 Software Freedom Conservancy
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 * MA 02110-1301, USA.
19 */
20
21#ifndef WEAK_POINTER_H
22#define WEAK_POINTER_H
23
24#include <cstddef>
25#include <set>
26
34 class WeakPointable {
35 private:
36 std::set<WeakPointable**> pointers;
37
38 public:
39
43 inline void AddWeakPointer(WeakPointable** weakptr) {
44 pointers.insert(weakptr);
45 }
46
50 inline void RemoveWeakPointer(WeakPointable **weakptr) {
51 pointers.erase(weakptr);
52 }
53
57 ~WeakPointable() {
58 for (auto pointer : pointers)
59 *pointer = nullptr;
60 }
61};
62
63#endif // WEAK_POINTER_H
WeakPointable
Definition weakptr.h:34
WeakPointable::AddWeakPointer
void AddWeakPointer(WeakPointable **weakptr)
Definition weakptr.h:43
WeakPointable::RemoveWeakPointer
void RemoveWeakPointer(WeakPointable **weakptr)
Definition weakptr.h:50
WeakPointable::~WeakPointable
~WeakPointable()
Definition weakptr.h:57