• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

KCal Library

  • sources
  • kde-4.12
  • kdepimlibs
  • kcal
listbase.h
Go to the documentation of this file.
1 /*
2  This file is part of the kcal library.
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 */
29 #ifndef KCAL_LISTBASE_H
30 #define KCAL_LISTBASE_H
31 
32 #include "kcal_export.h"
33 #include <QtCore/QList>
34 
35 namespace KCal {
36 
43 template<class T>
44 class ListBase : public QList<T *>
45 {
46  public:
50  ListBase()
51  : QList<T *>(), mAutoDelete( false )
52  {
53  }
54 
59  ListBase( const ListBase &other )
60  : QList<T *>( other ), mAutoDelete( false )
61  {
62  }
63 
67  ~ListBase()
68  {
69  if ( mAutoDelete ) {
70  qDeleteAll( *this );
71  }
72  }
73 
78  ListBase &operator=( const ListBase &l )
79  {
80  if ( this == &l ) {
81  return *this;
82  }
83  QList<T *>::operator=( l );
84  return *this;
85  }
86 
93  void setAutoDelete( bool autoDelete )
94  {
95  mAutoDelete = autoDelete;
96  }
97 
102  void clearAll()
103  {
104  if ( mAutoDelete ) {
105  qDeleteAll( *this );
106  }
107  QList<T*>::clear();
108  }
109 
116  bool removeRef( T *t )
117  {
118  if ( !this->contains( t ) ) {
119  return false;
120  } else {
121  if ( mAutoDelete ) {
122  delete t;
123  }
124  this->removeAll( t );
125  return true;
126  }
127  }
128 
134  void removeRef( typename QList<T*>::iterator it )
135  {
136  if ( mAutoDelete ) {
137  delete *it;
138  }
139  QList<T*>::erase( it );
140  }
141 
142  bool operator==( const ListBase &l2 )
143  {
144  int sz = QList<T*>::size();
145 
146  if ( sz != l2.size() ) {
147  return false;
148  } else {
149  for ( int i=0; i<sz; ++i ) {
150  if ( !( *QList<T*>::value( i ) == *l2.value( i ) ) ) {
151  return false;
152  }
153  }
154  }
155  return true;
156  }
157 
158  private:
159  //@cond PRIVATE
160  bool mAutoDelete;
161  //@endcond
162 };
163 
164 }
165 
166 #endif
KCal::ListBase::operator=
ListBase & operator=(const ListBase &l)
Assigns l to this listbase.
Definition: listbase.h:78
KCal::ListBase
This class provides a template for lists of pointers.
Definition: listbase.h:44
KCal::ListBase::removeRef
bool removeRef(T *t)
Removes all the members from the list with the specified address.
Definition: listbase.h:116
KCal::ListBase::ListBase
ListBase()
Constructor.
Definition: listbase.h:50
KCal::ListBase::removeRef
void removeRef(typename QList< T * >::iterator it)
Removes the specified member from the list.
Definition: listbase.h:134
KCal::ListBase::ListBase
ListBase(const ListBase &other)
Copy constructor.
Definition: listbase.h:59
KCal::ListBase::~ListBase
~ListBase()
Destructor.
Definition: listbase.h:67
KCal::ListBase::setAutoDelete
void setAutoDelete(bool autoDelete)
Sets this list to operate in "auto-delete" mode.
Definition: listbase.h:93
KCal::ListBase::clearAll
void clearAll()
Clears the list.
Definition: listbase.h:102
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:58 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KCal Library

Skip menu "KCal Library"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal