~bhill/epics-gateway/epics-gateway-preempt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 Berliner Speicherring-Gesellschaft fuer Synchrotron-
* Strahlung mbH (BESSY).
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* This file is distributed subject to a Software License Agreement found
* in the file LICENSE that is included with this distribution. 
\*************************************************************************/
/* Author: Jim Kowalkowski
 * Date: 7/96 */

#ifndef tsDLHashList_H
#define tsDLHashList_H

extern "C" {
#include "gpHash.h"
}

#include "tsDLList.h"

template <class T>
class tsHash
{
private:
	gphPvt * hash_table;
	// friend class tsDLHashIter<T>;

public:
    tsHash(void)
	{
		hash_table=0;
		gphInitPvt(&hash_table,2048); // 2048 is a guess
	}

	~tsHash(void)
	{
		gphFreeMem(hash_table);
	}
		 
	int add(const char* key, T& item)
	{
		GPHENTRY* entry;
		int rc;

		entry=gphAdd(hash_table,(char*)key,hash_table);

		if(entry==0)
			rc=-1;
		else
		{
			entry->userPvt=(void*)&item;
			rc=0;
		}
		return rc;
	}

	int remove(const char* key,T*& item)
	{
		int rc;

		if(find(key,item)<0)
			rc=-1;
		else
		{
			gphDelete(hash_table,(char*)key,hash_table);
			rc=0;
		}
		return rc;
	}

	int find(const char* key, T*& item)
	{
		GPHENTRY* entry;
		int rc;

		entry=gphFind(hash_table,(char*)key,hash_table);

		if(entry==0)
			rc=-1;
		else
		{
			item=(T*)entry->userPvt;
			rc=0;
		}
		return rc;
	}
};

template <class T>
class tsDLHashList : public tsDLList<T>
{
private:
	tsHash<T> h;
	// friend class tsDLHashIter<T>;

public:
	tsDLHashList(void) { }
	~tsDLHashList(void) { }

	int add(const char* key, T& item)
	{
		int rc;
		rc=h.add(key,item);
		tsDLList<T>::add(item);
		return rc;
	}

	int find(const char* key, T*& item)
	{
		int rc=0;
		if(h.find(key,item)!=0)
			rc=-1;
		return rc;
	}

	int remove(const char* key,T*& item)
	{
		int rc=0;
		if(h.find(key,item)==0)
		{
			h.remove(key,item);
			tsDLList<T>::remove(*item);
		}
		else
			rc=-1;
		return rc;
	}
};

template <class T>
class tsDLHashNode : public tsDLNode<T>
{
public:
#if 0
  // These are now private
    T* getNext(void) { return tsDLNode<T>::getNext(); }
    T* getPrev(void) { return tsDLNode<T>::getPrev(); }
#endif
};

#endif