1 /* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org>
2  * Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
3 
4 #ifndef __TRANSLITERATION_HH_INCLUDED__
5 #define __TRANSLITERATION_HH_INCLUDED__
6 
7 #include "dictionary.hh"
8 #include <map>
9 
10 namespace Transliteration {
11 
12 using std::map;
13 using gd::wstring;
14 using std::string;
15 using std::vector;
16 
17 
18 /// This is a base dictionary class for simple transliteratons
19 class BaseTransliterationDictionary: public Dictionary::Class
20 {
21   string name;
22 
23 protected:
24   bool caseSensitive;
25 
26 public:
27 
28   BaseTransliterationDictionary( string const & id, string const & name,
29                                  QIcon icon, bool caseSensitive = true );
30 
31   virtual string getName() throw();
32 
33   virtual map< Dictionary::Property, string > getProperties() throw();
34 
35   virtual unsigned long getArticleCount() throw();
36 
37   virtual unsigned long getWordCount() throw();
38 
39   virtual vector< wstring > getAlternateWritings( wstring const & )
40     throw() = 0;
41 
42   virtual sptr< Dictionary::WordSearchRequest > findHeadwordsForSynonym( wstring const & )
43     THROW_SPEC( std::exception );
44 
45   virtual sptr< Dictionary::WordSearchRequest > prefixMatch( wstring const &,
46                                                              unsigned long ) THROW_SPEC( std::exception );
47 
48   virtual sptr< Dictionary::DataRequest > getArticle( wstring const &,
49                                                       vector< wstring > const &,
50                                                       wstring const &, bool )
51     THROW_SPEC( std::exception );
52 };
53 
54 
55 class Table: public map< wstring, wstring >
56 {
57   unsigned maxEntrySize;
58 
59 public:
60 
Table()61   Table(): maxEntrySize( 0 )
62   {}
63 
getMaxEntrySize() const64   unsigned getMaxEntrySize() const
65   { return maxEntrySize; }
66 
67 protected:
68 
69   /// Inserts new entry into index. from and to are UTF8-encoded strings.
70   /// Also updates maxEntrySize.
71   void ins( char const * from, char const * to );
72 };
73 
74 
75 /// A base dictionary class for table based transliteratons
76 class TransliterationDictionary: public BaseTransliterationDictionary
77 {
78   Table const & table;
79 
80 public:
81 
82   TransliterationDictionary( string const & id, string const & name,
83                              QIcon icon,
84                              Table const & table,
85                              bool caseSensitive = true );
86 
87   virtual vector< wstring > getAlternateWritings( wstring const & )
88     throw();
89 };
90 
91 }
92 
93 #endif
94