eliot-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Eliot-dev] eliot dic/Makefile.am dic/dic.cpp dic/dic.h dic... [cppdic]


From: eliot-dev
Subject: [Eliot-dev] eliot dic/Makefile.am dic/dic.cpp dic/dic.h dic... [cppdic]
Date: Wed, 05 Dec 2007 10:36:01 +0000

CVSROOT:        /cvsroot/eliot
Module name:    eliot
Branch:         cppdic
Changes by:     Olivier Teulière <ipkiss>      07/12/05 10:36:01

Modified files:
        dic            : Makefile.am dic.cpp dic.h dic_search.cpp 
                         regexpmain.cpp 
        game           : game.cpp 
        utils          : eliottxt.cpp ncurses.cpp 
        wxwin          : auxframes.cc searchpanel.cc 
Removed files:
        dic            : dic_search.h 

Log message:
        All the dictionary searches (previously in DicSearch::search*) are now 
members of the Dictionary class. This allows removing most occurrences of 
reinterpret_cast.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/Makefile.am?cvsroot=eliot&only_with_tag=cppdic&r1=1.14.4.8&r2=1.14.4.9
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/dic.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.1.2.9&r2=1.1.2.10
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/dic.h?cvsroot=eliot&only_with_tag=cppdic&r1=1.13.2.7&r2=1.13.2.8
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/dic_search.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.1.2.6&r2=1.1.2.7
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/regexpmain.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.1.2.3&r2=1.1.2.4
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/dic_search.h?cvsroot=eliot&only_with_tag=cppdic&r1=1.12.2.1&r2=0
http://cvs.savannah.gnu.org/viewcvs/eliot/game/game.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.31.2.5&r2=1.31.2.6
http://cvs.savannah.gnu.org/viewcvs/eliot/utils/eliottxt.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.16.2.9&r2=1.16.2.10
http://cvs.savannah.gnu.org/viewcvs/eliot/utils/ncurses.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.22.2.4&r2=1.22.2.5
http://cvs.savannah.gnu.org/viewcvs/eliot/wxwin/auxframes.cc?cvsroot=eliot&only_with_tag=cppdic&r1=1.22.2.3&r2=1.22.2.4
http://cvs.savannah.gnu.org/viewcvs/eliot/wxwin/searchpanel.cc?cvsroot=eliot&only_with_tag=cppdic&r1=1.15.2.2&r2=1.15.2.3

Patches:
Index: dic/Makefile.am
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/Makefile.am,v
retrieving revision 1.14.4.8
retrieving revision 1.14.4.9
diff -u -b -r1.14.4.8 -r1.14.4.9
--- dic/Makefile.am     30 Nov 2007 17:09:28 -0000      1.14.4.8
+++ dic/Makefile.am     5 Dec 2007 10:35:59 -0000       1.14.4.9
@@ -31,8 +31,8 @@
        header.cpp header.h \
        dic_internals.h \
        tile.cpp tile.h \
-       dic_search.cpp dic_search.h \
        dic.cpp dic.h \
+       dic_search.cpp \
        encoding.cpp encoding.h \
        automaton.cpp automaton.h \
        regexp.cpp regexp.h

Index: dic/dic.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/Attic/dic.cpp,v
retrieving revision 1.1.2.9
retrieving revision 1.1.2.10
diff -u -b -r1.1.2.9 -r1.1.2.10
--- dic/dic.cpp 3 Dec 2007 17:27:33 -0000       1.1.2.9
+++ dic/dic.cpp 5 Dec 2007 10:36:00 -0000       1.1.2.10
@@ -195,6 +195,7 @@
         return reinterpret_cast<const Dawg_edge*>(m_dawg + e)->term;
 }
 
+
 unsigned int Dictionary::lookup(const dic_elt_t &root, const dic_code_t *s) 
const
 {
     unsigned int p;
@@ -223,6 +224,7 @@
     return 0;
 }
 
+
 unsigned int Dictionary::charLookup(const dic_elt_t &iRoot, const wchar_t *s) 
const
 {
     unsigned int p;
@@ -250,3 +252,4 @@
 
     return 0;
 }
+

Index: dic/dic.h
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/dic.h,v
retrieving revision 1.13.2.7
retrieving revision 1.13.2.8
diff -u -b -r1.13.2.7 -r1.13.2.8
--- dic/dic.h   4 Dec 2007 11:09:59 -0000       1.13.2.7
+++ dic/dic.h   5 Dec 2007 10:36:00 -0000       1.13.2.8
@@ -29,6 +29,7 @@
 
 #include <string>
 #include <vector>
+#include <map>
 
 #include "tile.h"
 
@@ -43,6 +44,10 @@
 class Header;
 typedef unsigned int dic_elt_t;
 typedef unsigned char dic_code_t;
+struct params_cross_t;
+struct params_7plus1_t;
+struct params_regexp_t;
+struct search_RegE_list_t;
 
 class Dictionary
 {
@@ -136,6 +141,56 @@
     /// Getter for the edge at the given position
     const uint32_t *getEdgeAt(const dic_elt_t &iElt) const { return m_dawg + 
iElt; }
 
+    /**
+     * Search for a word in the dictionary
+     * @param iWord: lookup word
+     * @return true if the word is valid, false otherwise
+     */
+    bool searchWord(const wstring &iWord) const;
+
+    /**
+     * Search for benjamins
+     * @param iWord: letters
+     * @param oWordList: results
+     */
+    void searchBenj(const wstring &iWord, list<wstring> &oWordList) const;
+
+    /**
+     * Search for all words feasible by adding a letter in front or at the end
+     * @param iWord: word
+     * @param oWordList: results
+     */
+    void searchRacc(const wstring &iWord, list<wstring> &oWordList) const;
+
+    /**
+     * Search for crosswords
+     * @param iMask: letters
+     * @param oWordList: results
+     */
+    void searchCross(const wstring &iMask, list<wstring> &oWordList) const;
+
+    /**
+     * Search for all feasible word with "rack" plus one letter
+     * @param iRack: letters
+     * @param oWordlist: results
+     * @param joker: true if the search must be performed when a joker is in 
the rack
+     */
+    void search7pl1(const wstring &iRack,
+                    map<wchar_t, list<wstring> > &oWordList,
+                    bool joker) const;
+
+    /**
+     * Search for words matching a regular expression
+     * @param iRegexp: regular expression
+     * @param oWordList: results
+     * @param iList: parameters for the search (?)
+     */
+    void searchRegExp(const wstring &iRegexp,
+                      list<wstring> &oWordList,
+                      struct search_RegE_list_t *iList) const;
+
+
+
 private:
     // Prevent from copying the dictionary!
     Dictionary &operator=(const Dictionary&);
@@ -149,6 +204,61 @@
 
     void convertDataToArch();
     void initializeTiles();
+
+    /// Template getter for the edge at the given position
+    template <typename DAWG_EDGE>
+    const DAWG_EDGE * getEdgeAt(const dic_elt_t &iElt) const
+    {
+        return reinterpret_cast<const DAWG_EDGE*>(m_dawg + iElt);
+    }
+
+    /**
+     * Walk the dictionary until the end of the word
+     * @param s: current pointer to letters
+     * @param eptr: current edge in the dawg
+     */
+    template <typename DAWG_EDGE>
+    const DAWG_EDGE * seekEdgePtr(const wchar_t *s, const DAWG_EDGE *eptr) 
const;
+
+    /// Helper for searchBenj()
+    template <typename DAWG_EDGE>
+    void searchBenjTempl(const wstring &iWord, list<wstring> &oWordList) const;
+
+    /// Helper for searchRacc()
+    template <typename DAWG_EDGE>
+    void searchRaccTempl(const wstring &iWord, list<wstring> &oWordList) const;
+
+    /// Helper for searchCross()
+    template <typename DAWG_EDGE>
+    void searchCrossRecTempl(struct params_cross_t *params,
+                             list<wstring> &oWordList,
+                             const DAWG_EDGE *edgeptr) const;
+
+    /// Helper for search7pl1()
+    template <typename DAWG_EDGE>
+    void search7pl1Templ(const wstring &iRack,
+                         map<wchar_t, list<wstring> > &oWordList,
+                         bool joker) const;
+
+    /// Second helper for search7pl1()
+    template <typename DAWG_EDGE>
+    void searchWordByLen(struct params_7plus1_t *params,
+                         int i, const DAWG_EDGE *edgeptr) const;
+
+    /**
+     * Internal version of searchRegExp, needed until
+     * wide chars are supported by our regexp engine.
+     */
+    void searchRegExpInner(const string &iRegexp,
+                           list<string> &oWordList,
+                           struct search_RegE_list_t *iList) const;
+
+    /// Helper for searchRegExp()
+    template <typename DAWG_EDGE>
+    void searchRegexpRecTempl(struct params_regexp_t *params,
+                              int state,
+                              const DAWG_EDGE *edgeptr,
+                              list<string> &oWordList) const;
 };
 
 #endif /* _DIC_H_ */

Index: dic/dic_search.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/Attic/dic_search.cpp,v
retrieving revision 1.1.2.6
retrieving revision 1.1.2.7
diff -u -b -r1.1.2.6 -r1.1.2.7
--- dic/dic_search.cpp  4 Dec 2007 16:07:24 -0000       1.1.2.6
+++ dic/dic_search.cpp  5 Dec 2007 10:36:00 -0000       1.1.2.7
@@ -34,7 +34,6 @@
 #include "header.h"
 #include "encoding.h"
 #include "regexp.h"
-#include "dic_search.h"
 #include "libdic_a-ery.h"   /* generated by bison */
 #include "libdic_a-erl.h"   /* generated by flex  */
 #include "automaton.h"
@@ -48,63 +47,45 @@
                 struct regexp_error_report_t *err);
 
 
-/**
- * Dic_seel_edgeptr
- * walk the dictionary until the end of the word
- * @param iDic: dictionnary
- * @param s: current pointer to letters
- * @param eptr: current edge in the dawg
- */
 template <typename DAWG_EDGE>
-static const DAWG_EDGE* Dic_seek_edgeptr(const Dictionary &iDic, const 
wchar_t* s, const DAWG_EDGE *eptr)
+const DAWG_EDGE* Dictionary::seekEdgePtr(const wchar_t* s, const DAWG_EDGE 
*eptr) const
 {
     if (*s)
     {
-        const DAWG_EDGE *p = reinterpret_cast<const 
DAWG_EDGE*>(iDic.getEdgeAt(eptr->ptr));
+        const DAWG_EDGE *p = getEdgeAt<DAWG_EDGE>(eptr->ptr);
         do
         {
-            if (p->chr == iDic.getHeader().getCodeFromChar(*s))
-                return Dic_seek_edgeptr(iDic, s + 1, p);
+            if (p->chr == getHeader().getCodeFromChar(*s))
+                return seekEdgePtr(s + 1, p);
         } while (!(*p++).last);
-        return reinterpret_cast<const DAWG_EDGE*>(iDic.getEdgeAt(0));
+        return getEdgeAt<DAWG_EDGE>(0);
     }
     else
         return eptr;
 }
 
 
-/**
- * searchWord: direct application of Dic_seek_edgeptr
- * @param iDic: dictionary
- * @param iWord: word to lookup
- * @result 0 not a valid word, 1 ok
- */
-template <typename DAWG_EDGE>
-static int searchWordTempl(const Dictionary &iDic, const wstring &iWord)
+bool Dictionary::searchWord(const wstring &iWord) const
 {
-    const DAWG_EDGE *e =
-        Dic_seek_edgeptr(iDic, iWord.c_str(), reinterpret_cast<const 
DAWG_EDGE*>(iDic.getEdgeAt(iDic.getRoot())));
+    if (getHeader().getVersion() == 0)
+    {
+        const Dawg_edge_old *e =
+            seekEdgePtr(iWord.c_str(), getEdgeAt<Dawg_edge_old>(getRoot()));
     return e->term;
-}
-
-
-/**
- * XXX: Wrapper around the template method, until the dictionary
- * completely hides Dawg_edge
- */
-int DicSearch::searchWord(const Dictionary &iDic, const wstring &iWord)
-{
-    if (iDic.getHeader().getVersion() == 0)
-        return searchWordTempl<Dawg_edge_old>(iDic, iWord);
+    }
     else
-        return searchWordTempl<Dawg_edge>(iDic, iWord);
+    {
+        const Dawg_edge *e =
+            seekEdgePtr(iWord.c_str(), getEdgeAt<Dawg_edge>(getRoot()));
+        return e->term;
+    }
 }
 
 
 /**
- * global variables for Dic_search_word_by_len:
+ * Global variables for searchWordByLen:
  *
- * a pointer to the structure is passed as a parameter
+ * A pointer to the structure is passed as a parameter
  * so that all the search_* variables appear to the functions
  * as global but the code remains re-entrant.
  * Should be better to change the algorithm ...
@@ -120,8 +101,8 @@
 };
 
 template <typename DAWG_EDGE>
-static void Dic_search_word_by_len(const Dictionary &iDic, struct 
params_7plus1_t *params,
-                                   int i, const DAWG_EDGE *edgeptr)
+void Dictionary::searchWordByLen(struct params_7plus1_t *params,
+                                 int i, const DAWG_EDGE *edgeptr) const
 {
     /* depth first search in the dictionary */
     do
@@ -132,7 +113,7 @@
             /* is the letter available in search_letters */
             if (params->search_letters[edgeptr->chr])
             {
-                params->search_wordtst[i] = 
iDic.getHeader().getCharFromCode(edgeptr->chr);
+                params->search_wordtst[i] = 
getHeader().getCharFromCode(edgeptr->chr);
                 params->search_letters[edgeptr->chr] --;
                 if (i == params->search_len)
                 {
@@ -143,8 +124,7 @@
                 }
                 else
                 {
-                    Dic_search_word_by_len(iDic, params, i + 1,
-                                           reinterpret_cast<const 
DAWG_EDGE*>(iDic.getEdgeAt(edgeptr->ptr)));
+                    searchWordByLen(params, i + 1, 
getEdgeAt<DAWG_EDGE>(edgeptr->ptr));
                 }
                 params->search_letters[edgeptr->chr] ++;
                 params->search_wordtst[i] = L'\0';
@@ -153,7 +133,7 @@
             /* the letter is of course available if we have a joker available 
*/
             if (params->search_letters[0])
             {
-                params->search_wordtst[i] = 
iDic.getHeader().getCharFromCode(edgeptr->chr);
+                params->search_wordtst[i] = 
getHeader().getCharFromCode(edgeptr->chr);
                 params->search_letters[0] --;
                 if (i == params->search_len)
                 {
@@ -164,8 +144,7 @@
                 }
                 else
                 {
-                    Dic_search_word_by_len(iDic, params, i + 1,
-                                           reinterpret_cast<const 
DAWG_EDGE*>(iDic.getEdgeAt(edgeptr->ptr)));
+                    searchWordByLen(params, i + 1, 
getEdgeAt<DAWG_EDGE>(edgeptr->ptr));
                 }
                 params->search_letters[0] ++;
                 params->search_wordtst[i] = L'\0';
@@ -176,9 +155,9 @@
 
 
 template <typename DAWG_EDGE>
-static void search7pl1Templ(const Dictionary &iDic, const wstring &iRack,
+void Dictionary::search7pl1Templ(const wstring &iRack,
                             map<wchar_t, list<wstring> > &oWordList,
-                            bool joker)
+                                 bool joker) const
 {
     if (iRack == L"" || iRack.size() > DIC_WORD_MAX)
         return;
@@ -197,7 +176,7 @@
     {
         if (iswalpha(*r))
         {
-            params.search_letters[iDic.getHeader().getCodeFromChar(*r)]++;
+            params.search_letters[getHeader().getCodeFromChar(*r)]++;
             wordlen++;
         }
         else if (*r == L'?')
@@ -218,10 +197,8 @@
     if (wordlen < 1)
         return;
 
-    const DAWG_EDGE *root_edge =
-        reinterpret_cast<const DAWG_EDGE*>(iDic.getEdgeAt(iDic.getRoot()));
-    root_edge =
-        reinterpret_cast<const DAWG_EDGE*>(iDic.getEdgeAt(root_edge->ptr));
+    const DAWG_EDGE *root_edge = getEdgeAt<DAWG_EDGE>(getRoot());
+    root_edge = getEdgeAt<DAWG_EDGE>(root_edge->ptr);
 
     params.results = &oWordList;
 
@@ -229,45 +206,40 @@
     params.added_char = L'\0';
     params.search_len = wordlen - 1;
     params.search_wordtst[wordlen] = L'\0';
-    Dic_search_word_by_len(iDic, &params, 0, root_edge);
+    searchWordByLen(&params, 0, root_edge);
 
     /* search for all the words that can be done with the letters +1 */
     params.search_len = wordlen;
     params.search_wordtst[wordlen + 1] = L'\0';
-    const wstring &letters = iDic.getHeader().getLetters();
+    const wstring &letters = getHeader().getLetters();
     for (unsigned int i = 0; i < letters.size(); i++)
     {
         params.added_char = letters[i];
-        unsigned int code = iDic.getHeader().getCodeFromChar(letters[i]);
+        unsigned int code = getHeader().getCodeFromChar(letters[i]);
         params.search_letters[code]++;
 
-        Dic_search_word_by_len(iDic, &params, 0, root_edge);
+        searchWordByLen(&params, 0, root_edge);
 
         params.search_letters[code]--;
     }
 }
 
 
-/**
- * XXX: Wrapper around the template method, until the dictionary
- * completely hides Dawg_edge
- */
-void DicSearch::search7pl1(const Dictionary &iDic, const wstring &iRack,
+void Dictionary::search7pl1(const wstring &iRack,
                            map<wchar_t, list<wstring> > &oWordList,
-                           bool joker)
+                            bool joker) const
 {
-    if (iDic.getHeader().getVersion() == 0)
-        search7pl1Templ<Dawg_edge_old>(iDic, iRack, oWordList, joker);
+    if (getHeader().getVersion() == 0)
+        search7pl1Templ<Dawg_edge_old>(iRack, oWordList, joker);
     else
-        search7pl1Templ<Dawg_edge>(iDic, iRack, oWordList, joker);
+        search7pl1Templ<Dawg_edge>(iRack, oWordList, joker);
 }
 
 /****************************************/
 /****************************************/
 
 template <typename DAWG_EDGE>
-static void searchRaccTempl(const Dictionary &iDic, const wstring &iWord,
-                            list<wstring> &oWordList)
+void Dictionary::searchRaccTempl(const wstring &iWord, list<wstring> 
&oWordList) const
 {
     if (iWord == L"")
         return;
@@ -277,11 +249,11 @@
     /* let's try for the front */
     wchar_t wordtst[DIC_WORD_MAX];
     wcscpy(wordtst + 1, iWord.c_str());
-    const wstring &letters = iDic.getHeader().getLetters();
+    const wstring &letters = getHeader().getLetters();
     for (unsigned int i = 0; i <= letters.size(); i++)
     {
         wordtst[0] = letters[i];
-        if (searchWordTempl<DAWG_EDGE>(iDic, wordtst))
+        if (searchWord(wordtst))
             oWordList.push_back(wordtst);
     }
 
@@ -293,19 +265,19 @@
     wordtst[i  ] = '\0';
     wordtst[i+1] = '\0';
 
-    const DAWG_EDGE *edge_seek = Dic_seek_edgeptr(iDic, iWord.c_str(),
-                                                  reinterpret_cast<const 
DAWG_EDGE*>(iDic.getEdgeAt(iDic.getRoot())));
+    const DAWG_EDGE *edge_seek =
+        seekEdgePtr(iWord.c_str(), getEdgeAt<DAWG_EDGE>(getRoot()));
 
     /* points to what the next letter can be */
-    const DAWG_EDGE *edge = reinterpret_cast<const 
DAWG_EDGE*>(iDic.getEdgeAt(edge_seek->ptr));
+    const DAWG_EDGE *edge = getEdgeAt<DAWG_EDGE>(edge_seek->ptr);
 
-    if (edge != reinterpret_cast<const DAWG_EDGE*>(iDic.getEdgeAt(0)))
+    if (edge != getEdgeAt<DAWG_EDGE>(0))
     {
         do
         {
             if (edge->term)
             {
-                wordtst[i] = iDic.getHeader().getCharFromCode(edge->chr);
+                wordtst[i] = getHeader().getCharFromCode(edge->chr);
                 oWordList.push_back(wordtst);
             }
         } while (!(*edge++).last);
@@ -313,25 +285,19 @@
 }
 
 
-/**
- * XXX: Wrapper around the template method, until the dictionary
- * completely hides Dawg_edge
- */
-void DicSearch::searchRacc(const Dictionary &iDic, const wstring &iWord,
-                           list<wstring> &oWordList)
+void Dictionary::searchRacc(const wstring &iWord, list<wstring> &oWordList) 
const
 {
-    if (iDic.getHeader().getVersion() == 0)
-        searchRaccTempl<Dawg_edge_old>(iDic, iWord, oWordList);
+    if (getHeader().getVersion() == 0)
+        searchRaccTempl<Dawg_edge_old>(iWord, oWordList);
     else
-        searchRaccTempl<Dawg_edge>(iDic, iWord, oWordList);
+        searchRaccTempl<Dawg_edge>(iWord, oWordList);
 }
 
 /****************************************/
 /****************************************/
 
 template <typename DAWG_EDGE>
-static void searchBenjTempl(const Dictionary &iDic, const wstring &iWord,
-                            list<wstring> &oWordList)
+void Dictionary::searchBenjTempl(const wstring &iWord, list<wstring> 
&oWordList) const
 {
     if (iWord == L"")
         return;
@@ -339,22 +305,22 @@
     wchar_t wordtst[DIC_WORD_MAX];
     wcscpy(wordtst + 3, iWord.c_str());
     const DAWG_EDGE *edge0, *edge1, *edge2, *edgetst;
-    edge0 = reinterpret_cast<const DAWG_EDGE*>(iDic.getEdgeAt(iDic.getRoot()));
-    edge0 = reinterpret_cast<const DAWG_EDGE*>(iDic.getEdgeAt(edge0->ptr));
+    edge0 = getEdgeAt<DAWG_EDGE>(getRoot());
+    edge0 = getEdgeAt<DAWG_EDGE>(edge0->ptr);
     do
     {
-        wordtst[0] = iDic.getHeader().getCharFromCode(edge0->chr);
-        edge1 = reinterpret_cast<const DAWG_EDGE*>(iDic.getEdgeAt(edge0->ptr));
+        wordtst[0] = getHeader().getCharFromCode(edge0->chr);
+        edge1 = getEdgeAt<DAWG_EDGE>(edge0->ptr);
         do
         {
-            wordtst[1] = iDic.getHeader().getCharFromCode(edge1->chr);
-            edge2 = reinterpret_cast<const 
DAWG_EDGE*>(iDic.getEdgeAt(edge1->ptr));
+            wordtst[1] = getHeader().getCharFromCode(edge1->chr);
+            edge2 = getEdgeAt<DAWG_EDGE>(edge1->ptr);
             do
             {
-                edgetst = Dic_seek_edgeptr(iDic, iWord.c_str(), edge2);
+                edgetst = seekEdgePtr(iWord.c_str(), edge2);
                 if (edgetst->term)
                 {
-                    wordtst[2] = iDic.getHeader().getCharFromCode(edge2->chr);
+                    wordtst[2] = getHeader().getCharFromCode(edge2->chr);
                     oWordList.push_back(wordtst);
                 }
             } while (!(*edge2++).last);
@@ -363,17 +329,12 @@
 }
 
 
-/**
- * XXX: Wrapper around the template method, until the dictionary
- * completely hides Dawg_edge
- */
-void DicSearch::searchBenj(const Dictionary &iDic, const wstring &iWord,
-                           list<wstring> &oWordList)
+void Dictionary::searchBenj(const wstring &iWord, list<wstring> &oWordList) 
const
 {
-    if (iDic.getHeader().getVersion() == 0)
-        searchBenjTempl<Dawg_edge_old>(iDic, iWord, oWordList);
+    if (getHeader().getVersion() == 0)
+        searchBenjTempl<Dawg_edge_old>(iWord, oWordList);
     else
-        searchBenjTempl<Dawg_edge>(iDic, iWord, oWordList);
+        searchBenjTempl<Dawg_edge>(iWord, oWordList);
 }
 
 /****************************************/
@@ -387,12 +348,11 @@
 
 
 template <typename DAWG_EDGE>
-static void Dic_search_cross_rec(const Dictionary &iDic,
-                                 struct params_cross_t *params,
+void Dictionary::searchCrossRecTempl(struct params_cross_t *params,
                                  list<wstring> &oWordList,
-                                 const DAWG_EDGE *edgeptr)
+                                     const DAWG_EDGE *edgeptr) const
 {
-    const DAWG_EDGE *current = reinterpret_cast<const 
DAWG_EDGE*>(iDic.getEdgeAt(edgeptr->ptr));
+    const DAWG_EDGE *current = getEdgeAt<DAWG_EDGE>(edgeptr->ptr);
 
     if (params->mask[params->wordlen] == '\0' && edgeptr->term)
     {
@@ -402,9 +362,9 @@
     {
         do
         {
-            params->mask[params->wordlen] = 
iDic.getHeader().getCharFromCode(current->chr);
+            params->mask[params->wordlen] = 
getHeader().getCharFromCode(current->chr);
             params->wordlen ++;
-            Dic_search_cross_rec(iDic, params, oWordList, current);
+            searchCrossRecTempl(params, oWordList, current);
             params->wordlen --;
             params->mask[params->wordlen] = '.';
         }
@@ -414,10 +374,10 @@
     {
         do
         {
-            if (current->chr == 
iDic.getHeader().getCodeFromChar(params->mask[params->wordlen]))
+            if (current->chr == 
getHeader().getCodeFromChar(params->mask[params->wordlen]))
             {
                 params->wordlen ++;
-                Dic_search_cross_rec(iDic, params, oWordList, current);
+                searchCrossRecTempl(params, oWordList, current);
                 params->wordlen --;
                 break;
             }
@@ -427,8 +387,7 @@
 }
 
 
-void DicSearch::searchCros(const Dictionary &iDic, const wstring &iMask,
-                           list<wstring> &oWordList)
+void Dictionary::searchCross(const wstring &iMask, list<wstring> &oWordList) 
const
 {
     if (iMask == L"")
         return;
@@ -446,15 +405,15 @@
     params.mask[i] = '\0';
 
     params.wordlen = 0;
-    if (iDic.getHeader().getVersion() == 0)
+    if (getHeader().getVersion() == 0)
     {
-        Dic_search_cross_rec(iDic, &params, oWordList,
-                             reinterpret_cast<const 
Dawg_edge_old*>(iDic.getEdgeAt(iDic.getRoot())));
+        searchCrossRecTempl(&params, oWordList,
+                            getEdgeAt<Dawg_edge_old>(getRoot()));
     }
     else
     {
-        Dic_search_cross_rec(iDic, &params, oWordList,
-                             reinterpret_cast<const 
Dawg_edge*>(iDic.getEdgeAt(iDic.getRoot())));
+        searchCrossRecTempl(&params, oWordList,
+                            getEdgeAt<Dawg_edge>(getRoot()));
     }
 }
 
@@ -463,7 +422,6 @@
 
 struct params_regexp_t
 {
-    const Dictionary *dic;
     int minlength;
     int maxlength;
     Automaton *automaton_field;
@@ -474,10 +432,10 @@
 
 
 template <typename DAWG_EDGE>
-static void Dic_search_regexp_rec(struct params_regexp_t *params,
+void Dictionary::searchRegexpRecTempl(struct params_regexp_t *params,
                                   int state,
                                   const DAWG_EDGE *edgeptr,
-                                  list<string> &oWordList)
+                                      list<string> &oWordList) const
 {
     int next_state;
     /* if we have a valid word we store it */
@@ -491,7 +449,7 @@
         }
     }
     /* we now drive the search by exploring the dictionary */
-    const DAWG_EDGE *current = reinterpret_cast<const 
DAWG_EDGE*>(params->dic->getEdgeAt(edgeptr->ptr));
+    const DAWG_EDGE *current = getEdgeAt<DAWG_EDGE>(edgeptr->ptr);
     do
     {
         /* the current letter is current->chr */
@@ -501,7 +459,7 @@
         {
             params->word[params->wordlen] = current->chr + 'a' - 1;
             params->wordlen ++;
-            Dic_search_regexp_rec(params, next_state, current, oWordList);
+            searchRegexpRecTempl(params, next_state, current, oWordList);
             params->wordlen --;
             params->word[params->wordlen] = '\0';
         }
@@ -509,9 +467,9 @@
 }
 
 
-void DicSearch::searchRegExpInner(const Dictionary &iDic, const string 
&iRegexp,
+void Dictionary::searchRegExpInner(const string &iRegexp,
                                   list<string> &oWordList,
-                                  struct search_RegE_list_t *iList)
+                                   struct search_RegE_list_t *iList) const
 {
     int ptl[REGEXP_MAX+1];
     int PS [REGEXP_MAX+1];
@@ -561,22 +519,21 @@
     if (a)
     {
         struct params_regexp_t params;
-        params.dic            = &iDic;
         params.minlength      = iList->minlength;
         params.maxlength      = iList->maxlength;
         params.automaton_field = a;
         params.charlist       = iList;
         memset(params.word, '\0', sizeof(params.word));
         params.wordlen        = 0;
-        if (iDic.getHeader().getVersion() == 0)
+        if (getHeader().getVersion() == 0)
         {
-            Dic_search_regexp_rec(&params, a->getInitId(),
-                                  reinterpret_cast<const 
Dawg_edge_old*>(iDic.getEdgeAt(iDic.getRoot())), oWordList);
+            searchRegexpRecTempl(&params, a->getInitId(),
+                                 getEdgeAt<Dawg_edge_old>(getRoot()), 
oWordList);
         }
         else
         {
-            Dic_search_regexp_rec(&params, a->getInitId(),
-                                  reinterpret_cast<const 
Dawg_edge*>(iDic.getEdgeAt(iDic.getRoot())), oWordList);
+            searchRegexpRecTempl(&params, a->getInitId(),
+                                 getEdgeAt<Dawg_edge>(getRoot()), oWordList);
         }
 
         delete a;
@@ -584,20 +541,17 @@
     regexp_delete_tree(root);
 }
 
-/**
- * Wrapper around searchRegExpInner, until we have multibyte support in
- * the dictionary
- */
-void DicSearch::searchRegExp(const Dictionary &iDic, const wstring &iRegexp,
+
+void Dictionary::searchRegExp(const wstring &iRegexp,
                              list<wstring> &oWordList,
-                             struct search_RegE_list_t *iList)
+                              struct search_RegE_list_t *iList) const
 {
     if (iRegexp == L"")
         return;
 
     list<string> tmpWordList;
     // Do the actual work
-    searchRegExpInner(iDic, convertToMb(iRegexp), tmpWordList, iList);
+    searchRegExpInner(convertToMb(iRegexp), tmpWordList, iList);
 
     list<string>::const_iterator it;
     for (it = tmpWordList.begin(); it != tmpWordList.end(); it++)
@@ -606,6 +560,3 @@
     }
 }
 
-/****************************************/
-/****************************************/
-

Index: dic/regexpmain.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/Attic/regexpmain.cpp,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -b -r1.1.2.3 -r1.1.2.4
--- dic/regexpmain.cpp  21 Nov 2007 16:25:44 -0000      1.1.2.3
+++ dic/regexpmain.cpp  5 Dec 2007 10:36:00 -0000       1.1.2.4
@@ -34,7 +34,7 @@
 
 #include "dic.h"
 #include "regexp.h"
-#include "dic_search.h"
+#include "encoding.h"
 
 
 #define __UNUSED__ __attribute__((unused))
@@ -125,14 +125,14 @@
 
             /* automaton */
             init_letter_lists(&regList);
-            list<string> wordList;
-            DicSearch::searchRegExpInner(dic, er, wordList, &regList);
+            list<wstring> wordList;
+            dic.searchRegExp(convertToWc(er), wordList, &regList);
 
             fprintf(stdout, "résultat:\n");
-            list<string>::const_iterator it;
+            list<wstring>::const_iterator it;
             for (it = wordList.begin(); it != wordList.end(); it++)
             {
-                fprintf(stderr, "%s\n", it->c_str());
+                fprintf(stderr, "%ls\n", it->c_str());
             }
         }
 

Index: game/game.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/game.cpp,v
retrieving revision 1.31.2.5
retrieving revision 1.31.2.6
diff -u -b -r1.31.2.5 -r1.31.2.6
--- game/game.cpp       4 Dec 2007 16:07:25 -0000       1.31.2.5
+++ game/game.cpp       5 Dec 2007 10:36:00 -0000       1.31.2.6
@@ -19,7 +19,6 @@
  *****************************************************************************/
 
 #include "dic.h"
-#include "dic_search.h"
 #include "tile.h"
 #include "rack.h"
 #include "round.h"
@@ -537,7 +536,7 @@
     }
 
     /* Check the existence of the word */
-    if (DicSearch::searchWord(m_dic, iWord) == 0)
+    if (!m_dic.searchWord(iWord))
     {
         return 3;
     }

Index: utils/eliottxt.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/utils/eliottxt.cpp,v
retrieving revision 1.16.2.9
retrieving revision 1.16.2.10
diff -u -b -r1.16.2.9 -r1.16.2.10
--- utils/eliottxt.cpp  4 Dec 2007 16:07:26 -0000       1.16.2.9
+++ utils/eliottxt.cpp  5 Dec 2007 10:36:00 -0000       1.16.2.10
@@ -35,7 +35,6 @@
 #endif
 
 #include "dic.h"
-#include "dic_search.h"
 #include "regexp.h"
 #include "game_io.h"
 #include "game_factory.h"
@@ -192,7 +191,7 @@
 void eliottxt_get_cross(const Dictionary &iDic, const wstring &iCros)
 {
     list<wstring> wordList;
-    DicSearch::searchCros(iDic, iCros, wordList);
+    iDic.searchCross(iCros, wordList);
 
     list<wstring>::const_iterator it;
     for (it = wordList.begin(); it != wordList.end(); it++)
@@ -429,7 +428,7 @@
                                 case L'b':
                                 {
                                     list<wstring> wordList;
-                                    DicSearch::searchBenj(iGame.getDic(), 
word, wordList);
+                                    iGame.getDic().searchBenj(word, wordList);
                                     list<wstring>::const_iterator it;
                                     for (it = wordList.begin(); it != 
wordList.end(); ++it)
                                         cout << convertToMb(*it) << endl;
@@ -438,7 +437,7 @@
                                 case L'p':
                                 {
                                     map<wchar_t, list<wstring> > wordMap;
-                                    DicSearch::search7pl1(iGame.getDic(), 
word, wordMap, false);
+                                    iGame.getDic().search7pl1(word, wordMap, 
false);
                                     map<wchar_t, list<wstring> 
>::const_iterator it;
                                     for (it = wordMap.begin(); it != 
wordMap.end(); ++it)
                                     {
@@ -455,7 +454,7 @@
                                 case L'r':
                                 {
                                     list<wstring> wordList;
-                                    DicSearch::searchRacc(iGame.getDic(), 
word, wordList);
+                                    iGame.getDic().searchRacc(word, wordList);
                                     list<wstring>::const_iterator it;
                                     for (it = wordList.begin(); it != 
wordList.end(); ++it)
                                         cout << convertToMb(*it) << endl;
@@ -471,7 +470,7 @@
                         help_training();
                     else
                     {
-                        if (DicSearch::searchWord(iGame.getDic(), token))
+                        if (iGame.getDic().searchWord(token))
                         {
                             printf("le mot -%s- existe\n",
                                    convertToMb(token).c_str());
@@ -605,7 +604,7 @@
                         help_freegame();
                     else
                     {
-                        if (DicSearch::searchWord(iGame.getDic(), token))
+                        if (iGame.getDic().searchWord(token))
                         {
                             printf("le mot -%s- existe\n",
                                    convertToMb(token).c_str());
@@ -706,7 +705,7 @@
                         help_duplicate();
                     else
                     {
-                        if (DicSearch::searchWord(iGame.getDic(), token))
+                        if (iGame.getDic().searchWord(token))
                         {
                             printf("le mot -%s- existe\n",
                                    convertToMb(token).c_str());
@@ -872,7 +871,7 @@
            nres, lmin, lmax);
 
     list<wstring> wordList;
-    DicSearch::searchRegExp(iDic, regexp, wordList, &llist);
+    iDic.searchRegExp(regexp, wordList, &llist);
 
     int nresult = 0;
     list<wstring>::const_iterator it;

Index: utils/ncurses.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/utils/ncurses.cpp,v
retrieving revision 1.22.2.4
retrieving revision 1.22.2.5
diff -u -b -r1.22.2.4 -r1.22.2.5
--- utils/ncurses.cpp   4 Dec 2007 19:12:25 -0000       1.22.2.4
+++ utils/ncurses.cpp   5 Dec 2007 10:36:00 -0000       1.22.2.5
@@ -30,7 +30,6 @@
 
 #include "ncurses.h"
 #include "dic.h"
-#include "dic_search.h"
 #include "game_factory.h"
 #include "training.h"
 #include "duplicate.h"
@@ -389,7 +388,7 @@
     wstring word;
     if (readString(win, y + 2, x + 2, 15, word))
     {
-        int res = DicSearch::searchWord(m_game->getDic(), word);
+        bool res = m_game->getDic().searchWord(word);
         char s[100];
         if (res)
             snprintf(s, 100, _("The word '%ls' exists"), word.c_str());

Index: wxwin/auxframes.cc
===================================================================
RCS file: /cvsroot/eliot/eliot/wxwin/auxframes.cc,v
retrieving revision 1.22.2.3
retrieving revision 1.22.2.4
diff -u -b -r1.22.2.3 -r1.22.2.4
--- wxwin/auxframes.cc  27 Nov 2007 18:01:07 -0000      1.22.2.3
+++ wxwin/auxframes.cc  5 Dec 2007 10:36:01 -0000       1.22.2.4
@@ -39,7 +39,6 @@
 #include "ewx.h"
 
 #include "dic.h"
-#include "dic_search.h"
 #include "training.h"
 #include "player.h"
 #include "game.h"
@@ -258,7 +257,7 @@
         result->SetLabel(_("pas de dictionnaire"));
         return;
     }
-    if (DicSearch::searchWord(*dic, word->GetValue().wc_str()))
+    if (dic->searchWord(word->GetValue().wc_str()))
         result->SetLabel(_("existe"));
     else
         result->SetLabel(_("n'existe pas"));
@@ -396,7 +395,7 @@
     savedword = rack;
 
     map<wchar_t, list<wstring> > wordList;
-    DicSearch::search7pl1(game->getDic(), rack, wordList, 
config.getJokerPlus1());
+    game->getDic().search7pl1(rack, wordList, config.getJokerPlus1());
 
     // Count the results
     int sum = 0;
@@ -452,7 +451,7 @@
     savedword = word;
     //debug("   BenjFrame::refresh : %s\n",word.c_str());
     list<wstring> wordList;
-    DicSearch::searchBenj(game->getDic(), word, wordList);
+    game->getDic().searchBenj(word, wordList);
 
     wxString *res = new wxString[wordList.size()];
     int resnum = 0;
@@ -487,7 +486,7 @@
     savedword = word;
     //debug("   RaccFrame::refresh : %s\n",word.c_str());
     list<wstring> wordList;
-    DicSearch::searchRacc(game->getDic(), word, wordList);
+    game->getDic().searchRacc(word, wordList);
 
     wxString *res = new wxString[wordList.size()];
     int resnum = 0;

Index: wxwin/searchpanel.cc
===================================================================
RCS file: /cvsroot/eliot/eliot/wxwin/searchpanel.cc,v
retrieving revision 1.15.2.2
retrieving revision 1.15.2.3
diff -u -b -r1.15.2.2 -r1.15.2.3
--- wxwin/searchpanel.cc        27 Nov 2007 18:01:07 -0000      1.15.2.2
+++ wxwin/searchpanel.cc        5 Dec 2007 10:36:01 -0000       1.15.2.3
@@ -29,7 +29,6 @@
 
 #include "ewx.h"
 #include "dic.h"
-#include "dic_search.h"
 #include "regexp.h"
 #include "searchpanel.h"
 #include "tile.h"
@@ -154,7 +153,7 @@
     wcsncpy(rack, t->GetValue().wc_str(), DIC_WORD_MAX);
 
     list<wstring> wordList;
-    DicSearch::searchCros(*dic, rack, wordList);
+    dic->searchCross(rack, wordList);
 
     int resnum = 0;
     wxString *res = new wxString[wordList.size()];
@@ -197,7 +196,7 @@
 
     wstring rack = t->GetValue().wc_str();
     map<wchar_t, list<wstring> > wordList;
-    DicSearch::search7pl1(*dic, rack, wordList, true);
+    dic->search7pl1(rack, wordList, true);
 
     // Count the results
     int sum = 0;
@@ -345,7 +344,7 @@
     debug("\n");
 
     list<wstring> wordList;
-    DicSearch::searchRegExp(*dic, regexp, wordList, &llist);
+    dic->searchRegExp(regexp, wordList, &llist);
 
     wxString *res = new wxString[wordList.size()];
     int resnum = 0;

Index: dic/dic_search.h
===================================================================
RCS file: dic/dic_search.h
diff -N dic/dic_search.h
--- dic/dic_search.h    15 Oct 2006 11:07:55 -0000      1.12.2.1
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,111 +0,0 @@
-/* Eliot                                                                     */
-/* Copyright (C) 1999  Antoine Fraboulet                                     */
-/*                                                                           */
-/* This file is part of Eliot.                                               */
-/*                                                                           */
-/* Eliot is free software; you can redistribute it and/or modify             */
-/* it under the terms of the GNU General Public License as published by      */
-/* the Free Software Foundation; either version 2 of the License, or         */
-/* (at your option) any later version.                                       */
-/*                                                                           */
-/* Eliot is distributed in the hope that it will be useful,                  */
-/* but WITHOUT ANY WARRANTY; without even the implied warranty of            */
-/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             */
-/* GNU General Public License for more details.                              */
-/*                                                                           */
-/* You should have received a copy of the GNU General Public License         */
-/* along with this program; if not, write to the Free Software               */
-/* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
*/
-
-/**
- *  \file   dic_search.h
- *  \brief  Dictionary lookup functions
- *  \author Antoine Fraboulet
- *  \date   2002
- */
-
-#ifndef _DIC_SEARCH_H_
-#define _DIC_SEARCH_H_
-
-#include <string>
-#include <list>
-#include <map>
-
-using namespace std;
-
-
-class DicSearch
-{
-public:
-
-    /**
-     * Search for a word in the dictionnary
-     * @param iDic: dictionary
-     * @param path: lookup word
-     * @return 1 present, 0 error
-     */
-    static int searchWord(const Dictionary &iDic,
-                          const wstring &path);
-
-    /**
-     * Search for all feasible word with "rack" plus one letter
-     * @param iDic: dictionary
-     * @param rack: letters
-     * @param wordlist: results
-     */
-    static void search7pl1(const Dictionary &iDic,
-                           const wstring &iRack,
-                           map<wchar_t, list<wstring> > &oWordList,
-                           bool joker);
-
-    /**
-     * Search for all feasible word adding a letter in front or at the end
-     * @param iDic: dictionary
-     * @param iWord: word
-     * @param oWordList: results
-     */
-    static void searchRacc(const Dictionary &iDic,
-                           const wstring &iWord,
-                           list<wstring> &oWordList);
-
-    /**
-     * Search for benjamins
-     * @param iDic: dictionary
-     * @param iWord: letters
-     * @param oWordList: results
-     */
-    static void searchBenj(const Dictionary &iDic,
-                           const wstring &iWord,
-                           list<wstring> &oWordList);
-
-    /**
-     * Search for crosswords
-     * @param iDic: dictionary
-     * @param iMask: letters
-     * @param oWordList: results
-     */
-    static void searchCros(const Dictionary &iDic,
-                           const wstring &iMask,
-                           list<wstring> &oWordList);
-
-    /**
-     * Search for words matching a regular expression
-     * @param iDic: dictionary
-     * @param iRegexp: regular expression
-     * @param oWordList: results
-     */
-    static void searchRegExp(const Dictionary &iDic,
-                             const wstring &iRegexp,
-                             list<wstring> &oWordList,
-                             struct search_RegE_list_t *iList);
-
-    /**
-     * Internal version of searchRegExp, used inside the dictionary until
-     * wide chars are supported internally.
-     */
-    static void searchRegExpInner(const Dictionary &iDic, const string 
&iRegexp,
-                                  list<string> &oWordList,
-                                  struct search_RegE_list_t *iList);
-};
-
-#endif /* _DIC_SEARCH_H_ */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]