File indexing completed on 2025-02-16 04:48:44
0001 /* 0002 * autodeletelist.h - pointer list with auto-delete on destruction 0003 * Program: kalarm 0004 * SPDX-FileCopyrightText: 2008-2020 David Jarvie <djarvie@kde.org> 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #pragma once 0010 0011 #include <QList> 0012 0013 0014 /** 0015 * A list of pointers which are auto-deleted when the list is deleted. 0016 * 0017 * @author David Jarvie <djarvie@kde.org> 0018 */ 0019 template <class T> 0020 class AutoDeleteList : public QList<T*> 0021 { 0022 public: 0023 AutoDeleteList() = default; 0024 ~AutoDeleteList() 0025 { 0026 // Remove from list first before deleting the pointer, in 0027 // case the pointer's destructor removes it from the list. 0028 while (!this->isEmpty()) 0029 delete this->takeFirst(); 0030 } 0031 0032 // Prevent copying since that would create two owners of the pointers 0033 AutoDeleteList(const AutoDeleteList&) = delete; 0034 AutoDeleteList& operator=(const AutoDeleteList&) = delete; 0035 }; 0036 0037 // vim: et sw=4: