1 #ifndef _KVI_KVS_SWITCHLIST_H_
2 #define _KVI_KVS_SWITCHLIST_H_
3 //=============================================================================
4 //
5 //   File : KviKvsSwitchList.h
6 //   Creation date : Mon 27 Oct 2003 03:47:48 by Szymon Stefanek
7 //
8 //   This file is part of the KVIrc IRC client distribution
9 //   Copyright (C) 2003-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 #include "kvi_settings.h"
28 #include "KviQString.h"
29 #include "KviKvsVariant.h"
30 
31 #include "KviPointerHashTable.h"
32 
33 class KVIRC_API KviKvsSwitchList
34 {
35 public:
36 	KviKvsSwitchList();
37 	~KviKvsSwitchList();
38 
39 protected:
40 	KviPointerHashTable<unsigned short, KviKvsVariant> * m_pShortSwitchDict;
41 	KviPointerHashTable<QString, KviKvsVariant> * m_pLongSwitchDict;
42 
43 public:
44 	void clear();
45 	void addShort(unsigned short uShortKey, KviKvsVariant * pVariant);
46 	void addLong(const QString & szLongKey, KviKvsVariant * pVariant);
47 
isEmpty()48 	bool isEmpty() { return ((m_pShortSwitchDict == 0) && (m_pLongSwitchDict == 0)); };
49 
find(const QChar & c)50 	KviKvsVariant * find(const QChar & c)
51 	{
52 		return m_pShortSwitchDict ? m_pShortSwitchDict->find(c.unicode()) : 0;
53 	};
54 
find(unsigned short uShortKey)55 	KviKvsVariant * find(unsigned short uShortKey)
56 	{
57 		return m_pShortSwitchDict ? m_pShortSwitchDict->find((int)uShortKey) : 0;
58 	};
59 
find(const QString & szLongKey)60 	KviKvsVariant * find(const QString & szLongKey)
61 	{
62 		return m_pLongSwitchDict ? m_pLongSwitchDict->find(szLongKey) : 0;
63 	};
64 
find(unsigned short uShortKey,const QString & szLongKey)65 	KviKvsVariant * find(unsigned short uShortKey, const QString & szLongKey)
66 	{
67 		if(m_pLongSwitchDict)
68 		{
69 			KviKvsVariant * t;
70 			t = m_pLongSwitchDict->find(szLongKey);
71 			if(t)
72 				return t;
73 		}
74 		return m_pShortSwitchDict ? m_pShortSwitchDict->find((int)uShortKey) : 0;
75 	};
76 
getAsStringIfExisting(unsigned short uShortKey,const QString & szLongKey,QString & szBuffer)77 	bool getAsStringIfExisting(unsigned short uShortKey, const QString & szLongKey, QString & szBuffer)
78 	{
79 		KviKvsVariant * v = find(uShortKey, szLongKey);
80 		if(v)
81 		{
82 			v->asString(szBuffer);
83 			return true;
84 		}
85 		return false;
86 	};
87 };
88 
89 #endif //!_KVI_KVS_SWITCHLIST_H_
90