libkcal

listbase.h
1 /*
2  This file is part of libkcal.
3 
4  Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 #ifndef KCAL_LISTBASE_H
22 #define KCAL_LISTBASE_H
23 
24 #include <tqvaluelist.h>
25 
26 namespace KCal {
27 
32 template<class T>
33 class ListBase : public TQValueList<T *>
34 {
35  public:
36  ListBase()
37  : TQValueList<T *>(), mAutoDelete( false )
38  {
39  }
40 
41  ListBase( const ListBase &l )
42  : TQValueList<T *>( l ), mAutoDelete( false )
43  {
44  }
45 
46  ~ListBase()
47  {
48  if ( mAutoDelete ) {
49  TQValueListIterator<T *> it;
50  for( it = TQValueList<T*>::begin(); it != TQValueList<T*>::end(); ++it ) {
51  delete *it;
52  }
53  }
54  }
55 
56  ListBase &operator=( const ListBase &l )
57  {
58  if ( this == &l ) return *this;
59  TQValueList<T *>::operator=( l );
60  return *this;
61  }
62 
63  void setAutoDelete( bool autoDelete )
64  {
65  mAutoDelete = autoDelete;
66  }
67 
68  bool removeRef( T *t )
69  {
70  TQValueListIterator<T *> it = this->find( t );
71  if ( it == TQValueList<T*>::end() ) {
72  return false;
73  } else {
74  if ( mAutoDelete ) delete t;
75  this->remove( it );
76  return true;
77  }
78  }
79 
80  void clearAll()
81  {
82  if ( mAutoDelete ) {
83  for ( TQValueListIterator<T*> it = TQValueList<T*>::begin();
84  it != TQValueList<T*>::end(); ++it ) {
85  delete *it;
86  }
87  }
88  TQValueList<T*>::clear();
89  }
90 
91  private:
92  bool mAutoDelete;
93 };
94 
95 }
96 
97 #endif
This class provides a template for lists of pointers.
Definition: listbase.h:34
Attachment * find(TQWidget *parent, const TQString &attachmentName, Incidence *incidence)
Finds the attachment in the user's calendar, by attachmentName and incidence.
Namespace KCal is for global classes, objects and/or functions in libkcal.
Definition: alarm.h:38