KVIrc  4.9.2
DeveloperAPIs
KviIrcConnectionAsyncData.h
Go to the documentation of this file.
1 #ifndef _KVI_IRCCONNECTIONASYNCTEMPLATEDATA_H_
2 #define _KVI_IRCCONNECTIONASYNCTEMPLATEDATA_H_
3 //=============================================================================
4 //
5 // File : KviIrcConnectionAsyncWhoisData.h
6 // Creation date : Sat 26 Jun 2004 19:40:20 by Szymon Stefanek
7 //
8 // This file is part of the KVIrc IRC client distribution
9 // Copyright (C) 2004-2010 Szymon Stefanek <pragma at kvirc dot net>
10 //
11 // This program is FREE software. You can redistribute it and/or
12 // modify it under the terms of the GNU General Public License
13 // as published by the Free Software Foundation; either version 2
14 // of the License, or (at your option) any later version.
15 //
16 // This program is distributed in the HOPE that it will be USEFUL,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 // See the GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, write to the Free Software Foundation,
23 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 //
25 //=============================================================================
26 
27 // This template class will be used to create some other classes for future commands
28 // KviIrcConnectionAsyncWhoData for creating an awho command
29 // KviIrcConnectionAsyncWhowasData for creating an awhowas command
30 // It is now also used by KviIrcConnectionAsyncWhoisData
31 
32 #ifndef __GNUC__
33 #define __attribute__(X)
34 #endif
35 
36 template <class T>
38 {
39 public:
41  {
42  m_pInfoList = 0;
43  }
44 
46  {
47  if(m_pInfoList)
48  delete m_pInfoList;
49  }
50 
51 protected:
52  KviPointerList<T> * m_pInfoList; // awhois pending stuff
53 public:
54  void add(T * i)
55  {
56  if(!m_pInfoList)
57  {
58  m_pInfoList = new KviPointerList<T>;
59  m_pInfoList->setAutoDelete(true);
60  }
61  m_pInfoList->append(i);
62  }
63 
64  T * lookup(const QString & nick)
65  {
66  if(!m_pInfoList)
67  return 0;
68  for(T * i = m_pInfoList->first(); i; i = m_pInfoList->next())
69  {
70  if(KviQString::equalCI(nick, i->szNick))
71  return i;
72  }
73  return 0;
74  }
75 
76  void remove(T * i)
77  {
78  if(!m_pInfoList)
79  return;
80  m_pInfoList->removeRef(i);
81  if(m_pInfoList->isEmpty())
82  {
83  delete m_pInfoList;
84  m_pInfoList = 0;
85  }
86  }
87 };
88 
89 #endif
Definition: KviIrcConnectionAsyncData.h:37
#define KVIRC_API
Definition: kvi_settings.h:128
void add(T *i)
Definition: KviIrcConnectionAsyncData.h:54
#define i
Definition: detector.cpp:73
void setAutoDelete(bool bAutoDelete)
Sets the autodelete flag.
Definition: KviPointerList.h:1090
T * lookup(const QString &nick)
Definition: KviIrcConnectionAsyncData.h:64
A template double linked list of pointers.
Definition: KviPointerList.h:55
KviIrcConnectionAsyncData()
Definition: KviIrcConnectionAsyncData.h:40
bool equalCI(const QString &sz1, const QString &sz2)
Compares two strings with case insensitive.
Definition: KviQString.cpp:285
KviPointerList< T > * m_pInfoList
Definition: KviIrcConnectionAsyncData.h:52
~KviIrcConnectionAsyncData()
Definition: KviIrcConnectionAsyncData.h:45