Imported version 0.2-1
[mstardict] / src / lib / data.hpp
1 #ifndef _DATA_HPP_
2 #define _DATA_HPP_
3
4 #include <glib.h>
5 #include <vector>
6 #include <string>
7 #include <memory>
8
9 #include "dictziplib.hpp"
10
11 struct cacheItem {
12   guint32 offset;
13         gchar *data;
14   //write code here to make it inline
15   cacheItem() {data= NULL;}
16   ~cacheItem() {g_free(data);}
17 };
18
19 const int WORDDATA_CACHE_NUM = 10;
20 const int UNSET_INDEX = -1;
21 const int INVALID_INDEX=-100;
22
23 class DictBase {
24 public:
25         DictBase();
26         ~DictBase();
27         gchar * GetWordData(guint32 idxitem_offset, guint32 idxitem_size);
28         bool containSearchData() {
29                 if (sametypesequence.empty())
30                         return true;
31
32                 return sametypesequence.find_first_of("mlgxtykwh") !=
33                         std::string::npos;
34         }
35         bool SearchData(std::vector<std::string> &SearchWords, guint32 idxitem_offset, guint32 idxitem_size, gchar *origin_data);
36 protected:
37         std::string sametypesequence;
38         FILE *dictfile;
39         std::auto_ptr<dictData> dictdzfile;
40 private:
41   cacheItem cache[WORDDATA_CACHE_NUM];
42         gint cache_cur;
43 };
44
45 #endif//!_DATA_HPP_