r7061: initial property settings
[ctsim.git] / include / hashtable.h
1 /* FILE IDENTIFICATION
2 **
3 **      File Name:      hashtable.h
4 **      Author:         Kevin Rosenberg
5 **      Purpose:        Header file for hash table library
6 **      Date Started:   Dec. 2000
7 **
8 **  This is part of the CTSim program
9 **  Copyright (c) 1983-2001 Kevin Rosenberg
10 **
11 **  $Id$
12 **
13 **
14 **  This program is free software; you can redistribute it and/or modify
15 **  it under the terms of the GNU General Public License (version 2) as
16 **  published by the Free Software Foundation.
17 **
18 **  This program is distributed in the hope that it will be useful,
19 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
20 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 **  GNU General Public License for more details.
22 **
23 **  You should have received a copy of the GNU General Public License
24 **  along with this program; if not, write to the Free Software
25 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 ******************************************************************************/
27
28 #ifndef HASHTABLE_H
29 #define HASHTABLE_H
30
31
32 class KeywordCodeEntry
33 {
34 private:
35   std::string m_strKeyword;
36   int m_iCode;
37   class KeywordCodeEntry *m_pNext;
38   
39   public:
40     
41     KeywordCodeEntry (const char* const pszKeyword, int iCode);
42     
43     const char* const getKeyword() const
44     { return m_strKeyword.c_str(); }
45
46     bool matchesKeyword (const char* const pszMatch) const;
47
48     int getCode () const
49     { return m_iCode; }
50     
51     void setCode (int iCode) 
52     { m_iCode = iCode; }
53     
54     void setNext (KeywordCodeEntry* pNext)
55     { m_pNext = pNext; }
56     
57     KeywordCodeEntry* getNext ()
58     { return m_pNext; }
59 };
60
61
62 class KeywordCodeHashTable {
63 public:
64   enum {
65     HASHSIZE = 100,
66   };
67   
68   KeywordCodeHashTable()
69   { initTable(); }
70   
71   ~KeywordCodeHashTable()
72   { freeTable(); }
73   
74   void installKeywordCode (const char* const pszKeyword, int iCode);
75   KeywordCodeEntry* lookup (const char* const pszKeyword);
76   
77 private:
78   KeywordCodeEntry* m_hashTable[HASHSIZE];
79   
80   int hash (const char* s);
81   void initTable ();
82   void freeTable ();
83 };
84
85 #endif
86
87