KHtml

translator.h
1 /**
2  * This file is part of the KHTML renderer for KDE.
3  *
4  * Copyright (C) 2006, 2007 Maksim Orlovich ([email protected])
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 
22 #ifndef KHTML_MISC_TRANSLATOR_H
23 #define KHTML_MISC_TRANSLATOR_H
24 
25 #include <QMap>
26 
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>
32 {
33 public:
34  struct Info {
35  MemL l;
36  R r;
37  };
38 
39  IDTranslator(const Info *table)
40  {
41  for (const Info *cursor = table; cursor->l; ++cursor) {
42  m_lToR.insert(cursor->l, cursor->r);
43  m_rToL.insert(cursor->r, cursor->l);
44  }
45  }
46 
47  bool hasLeft(L l)
48  {
49  typename QMap<L, R>::iterator i = m_lToR.find(l);
50  return i != m_lToR.end();
51  }
52 
53  L toLeft(R r)
54  {
55  typename QMap<R, L>::iterator i(m_rToL.find(r));
56  if (i != m_rToL.end()) {
57  return *i;
58  }
59  return L();
60  }
61 
62  R toRight(L l)
63  {
64  typename QMap<L, R>::iterator i = m_lToR.find(l);
65  if (i != m_lToR.end()) {
66  return *i;
67  }
68  return R();
69  }
70 
71 private:
72  QMap<L, R> m_lToR;
73  QMap<R, L> m_rToL;
74 };
75 
76 #define MAKE_TRANSLATOR(name,L,R,MR,table) static IDTranslator<L,R,MR>* s_##name; \
77  static IDTranslator<L,R,MR>* name() { if (!s_##name) s_##name = new IDTranslator<L,R,MR>(table); \
78  return s_##name; }
79 
80 #endif
This file is part of the KHTML renderer for KDE.
Definition: translator.h:31
QMap::iterator end()
QMap::iterator find(const Key &key)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 26 2021 22:48:10 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.