2 * This file is part of the KHTML renderer for KDE.
4 * Copyright (C) 2006, 2007 Maksim Orlovich (maksim@kde.org)
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.
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.
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.
22 #ifndef KHTML_MISC_TRANSLATOR_H
23 #define KHTML_MISC_TRANSLATOR_H
25 #include <QtCore/QMap>
27 //---------------------------------------------------------------------------------------------
28 /* This class is used to do remapping between different encodings reasonably compactly.
29 It stores things as (L,R) tables, but reads left-side from memory as MemL */
30 template<typename L
, typename R
, typename MemL
>
39 IDTranslator(const Info
* table
) {
40 for (const Info
* cursor
= table
; cursor
->l
; ++cursor
) {
41 m_lToR
.insert(cursor
->l
, cursor
->r
);
42 m_rToL
.insert(cursor
->r
, cursor
->l
);
47 typename QMap
<L
,R
>::iterator i
= m_lToR
.find(l
);
48 return i
!= m_lToR
.end();
52 typename QMap
<R
,L
>::iterator
i( m_rToL
.find(r
) );
53 if (i
!= m_rToL
.end())
59 typename QMap
<L
,R
>::iterator i
= m_lToR
.find(l
);
60 if (i
!= m_lToR
.end())
70 #define MAKE_TRANSLATOR(name,L,R,MR,table) static IDTranslator<L,R,MR>* s_##name; \
71 static IDTranslator<L,R,MR>* name() { if (!s_##name) s_##name = new IDTranslator<L,R,MR>(table); \