Debian Codegraph @

data/0.12-dev/impl/WordsFile.h

raw
1 /*
2 * Aiksaurus - An open source thesaurus library
3 * Copyright (C) 2001 by Jared Davis
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18 * 02111-1307, USA.
19 *
20 */
21
22 #ifndef INCLUDED_WORDSFILE_H
23 #define INCLUDED_WORDSFILE_H
24
25 //
26 // WordsFile Class
27 //
28 // This class is a low level interface to the Words File itself.
29 //
30 // It provides a convenient interface to the FileArray class that
31 // it is implemented through, and all the error checking that a
32 // nuclear engineer could want.
33 //
34 // Basic operations are:
35 //
36 // loadWord(i) - load a particular word by index.
37 // getWord() - figure out what word was just loaded.
38 // getLinks() - get the links that the word had.
39 // findWord(str) - binary search file to find the word.
40 //
41
42 #include "AiksaurusErrors.h" // Error reporting mechanism.
43
44 namespace AiksaurusImpl
45 {
46 // Forward Declarations
47 class FileArray;
48 class AiksaurusError;
49
50 class WordsFile
51 {
52 private:
53
54 // No copying or assignment allowed.
55 WordsFile(const WordsFile& rhs);
56 WordsFile& operator=(const WordsFile& rhs);
57
58 // Information about maximum word size, link size.
59 static const int s_maxwords;
60 static const int s_maxlinks;
61 static const int s_structsize;
62
63 // Reference to Errors object.
64 AiksaurusError d_error;
65
66 // Pointer to a file array, accesses the data.
67 FileArray* d_data_ptr;
68
69 // Number of words that are in the Words file.
70 int d_size;
71
72 // Storage for arrays when doing word lookups.
73 char *d_word;
74 int *d_links;
75
76
77 public:
78
79 // Creation and Destruction
80 WordsFile(const char* fname);
81 ~WordsFile();
82
83 // Word Lookup
84 bool loadWord(int id);
85 int findWord(const char* str);
86
87 // Inspection
88 int getSize() const;
89 const char* getWord() const;
90 const int* getLinks() const;
91 const AiksaurusError& getError() const;
92
93 // Constants
94 static int maxWordLength();
95 };
96
97 }
98
99 #endif // INCLUDED_WORDSFILE_H
100