Fix typo in license headers
[oweals/cde.git] / cde / programs / dtmail / include / DtMail / HashTable.hh
1 /*
2  *+SNOTICE
3  *
4  *
5  *      $XConsortium: HashTable.hh /main/4 1996/04/21 19:45:12 drk $
6  *
7  *      RESTRICTED CONFIDENTIAL INFORMATION:
8  *      
9  *      The information in this document is subject to special
10  *      restrictions in a confidential disclosure agreement bertween
11  *      HP, IBM, Sun, USL, SCO and Univel.  Do not distribute this
12  *      document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
13  *      Sun's specific written approval.  This documment and all copies
14  *      and derivative works thereof must be returned or destroyed at
15  *      Sun's request.
16  *
17  *      Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
18  *
19  *+ENOTICE
20  */
21
22 #ifndef _HASHTABLE_HH
23 #define _HASHTABLE_HH
24
25 #include <DtMail/ObjectKey.hh>
26
27 class HashTableImpl : public DtCPlusPlusAllocator {
28   public:
29     HashTableImpl(int table_size);
30     virtual ~HashTableImpl(void);
31
32     virtual void * lookup(ObjectKey &);
33     virtual void set(ObjectKey & key, void * value);
34     virtual void * remove(ObjectKey & key);
35
36 // HP can not support this construct.
37 // UXP/DS can not support this construct either.
38 //
39 #if !defined(HPUX) && !defined(__uxp__)
40 //
41 #define HASHTABLE_HASFOREACH
42
43     typedef int (*HashImplIterator)(ObjectKey &, void * value, void * client_data);
44     virtual void forEach(HashImplIterator, void * client_data);
45
46 #endif
47
48   protected:
49     struct HashEntry : public DtCPlusPlusAllocator {
50         ObjectKey *     key;
51         void *          value;
52         HashEntry       *next;
53     };
54
55     HashEntry *         _hash_table;
56     int                 _table_size;
57 };
58
59 template <class Object>
60 class HashTable : public DtCPlusPlusAllocator {
61   public:
62     HashTable(int table_size) : _table(table_size) { }
63
64     Object lookup(ObjectKey & key) { return( (Object)((long)_table.lookup(key)) ); }
65
66     void set(ObjectKey & key, Object obj) {
67         _table.set(key, (void *)obj);
68     }
69
70     Object remove(ObjectKey & key) { return( (Object)((long)_table.remove(key)) ); }
71
72 #if !defined(HPUX) && !defined(__uxp__)
73     typedef int (*HashIterator)(ObjectKey &, Object, void * client_data);
74     void forEach(HashTableImpl::HashImplIterator iterator, void * client_data) {
75         _table.forEach((HashTableImpl::HashImplIterator)iterator, client_data);
76     }
77 #endif
78
79   protected:
80     HashTableImpl       _table;
81 };
82
83 #endif