Back
1 //------------------------------------------------------------------------------
2 // Module WordList.cpp //
3 // //
4 // Simple class which encapsulates a (keyword-)word list //
5 // //
6 // Copyright (c) 2000-2004 by Lars Haendel //
7 // Home: http://www.newty.de //
8 // //
9 // This program is free software; you can redistribute it and/or modify //
10 // it under the terms of the GNU General Public License as published by //
11 // the Free Software Foundation as version 2 of the License. //
12 // //
13 // This program is distributed in the hope that it will be useful, //
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
16 // GNU General Public License for more details. //
17 // //
18 // You should have received a copy of the GNU General Public License //
19 // along with this program; if not, write to the Free Software //
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. //
21 // //
22 //------------------------------------------------------------------------------
23
24
25
26 #ifndef WordListH
27 #define WordListH
28
29 #include <iostream> // due to: ifstream
30 #include <fstream>
31
32 #include "defines.h" // general defines
33
34
35 #define MAX_WORD_LEN 64 // maximum length of a word in the list
36
37 //----------------------------------------------------------------------------------------------------------------------
38 // class which encapsulates a (keyword-)word list
39 class TWordList
40 {
41 private:
42
43 int _n; // number of words
44 char** words; // word list
45 int (*CmpFunc) (const void*, const void*); // pointer to comparison function
46
47 void Release(); // release memory
48
49 public:
50
51 // constructor/destructor
52 TWordList();
53 ~TWordList();
54
55 // return true, if 'szWord' is in word list
56 bool IsInList(const char*const& szWord) const;
57 void Load(ifstream& file, const char*const& szKey, const bool& f_CaseSensitive); // load words from file
58 void Save(ofstream& file, const char*const& szKey, const int& width) const; // save words to file
59 int nWords() const { return _n; }; // # of words
60
61 const char* GetRandom() const;
62 };
63 #endif
Top |