Fix for UBSan build
[platform/upstream/doxygen.git] / src / searchindex.h
1 /******************************************************************************
2  *
3  * $Id: searchindex.h,v 1.7 2001/03/19 19:27:41 root Exp $
4  *
5  * Copyright (C) 1997-2012 by Dimitri van Heesch.
6  *
7  * Permission to use, copy, modify, and distribute this software and its
8  * documentation under the terms of the GNU General Public License is hereby 
9  * granted. No representations are made about the suitability of this software 
10  * for any purpose. It is provided "as is" without express or implied warranty.
11  * See the GNU General Public License for more details.
12  *
13  * Documents produced by Doxygen are derivative works derived from the
14  * input used in their production; they are not affected by this license.
15  *
16  */
17
18 #ifndef _SEARCHINDEX_H
19 #define _SEARCHINDEX_H
20
21 #include "qtbc.h"
22 #include <qintdict.h>
23 #include <qlist.h>
24 #include <qdict.h>
25 #include <qintdict.h>
26 #include <qvector.h>
27
28 class FTextStream;
29 class Definition;
30 class MemberDef;
31
32 /*! Initialize the search indexer */
33 void initSearchIndexer();
34 /*! Cleanup the search indexer */
35 void finializeSearchIndexer();
36
37 //------- server side search index ----------------------
38
39 struct URL
40 {
41   URL(const char *n,const char *u) : name(n), url(u) {} 
42   QCString name;
43   QCString url;
44 };
45
46
47 struct URLInfo
48 {
49   URLInfo(int idx,int f) : urlIdx(idx), freq(f) {}
50   int urlIdx;
51   int freq;
52 };
53
54 class IndexWord
55 {
56   public:
57     IndexWord(const char *word);
58     void addUrlIndex(int,bool);
59     const QIntDict<URLInfo> &urls() const { return m_urls; }
60     QCString word() const { return m_word; }
61
62   private:
63     QCString    m_word;
64     QIntDict<URLInfo> m_urls;
65 };
66
67 class SearchIndexIntf
68 {
69   public:
70     enum Kind { Internal, External };
71     SearchIndexIntf(Kind k) : m_kind(k) {}
72     virtual ~SearchIndexIntf() {}
73     virtual void setCurrentDoc(Definition *ctx,const char *anchor,bool isSourceFile) = 0;
74     virtual void addWord(const char *word,bool hiPriority) = 0;
75     virtual void write(const char *file) = 0;
76     Kind kind() const { return m_kind; }
77   private:
78     Kind m_kind;
79 };
80
81 class SearchIndex : public SearchIndexIntf
82 {
83   public:
84     SearchIndex();
85     void setCurrentDoc(Definition *ctx,const char *anchor,bool isSourceFile);
86     void addWord(const char *word,bool hiPriority);
87     void write(const char *file);
88   private:
89     void addWord(const char *word,bool hiPrio,bool recurse);
90     QDict<IndexWord> m_words;
91     QVector< QList<IndexWord> > m_index;
92     QIntDict<URL>  m_urls;
93     int m_urlIndex;
94 };
95
96
97 class SearchIndexExternal : public SearchIndexIntf
98 {
99     struct Private;
100   public:
101     SearchIndexExternal();
102    ~SearchIndexExternal();
103     void setCurrentDoc(Definition *ctx,const char *anchor,bool isSourceFile);
104     void addWord(const char *word,bool hiPriority);
105     void write(const char *file);
106   private:
107     Private *p;
108 };
109
110 //------- client side search index ----------------------
111
112 void writeJavascriptSearchIndex();
113 void writeSearchCategories(FTextStream &t);
114
115 #endif