File: symtab.h

package info (click to toggle)
tardy 1.12-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,620 kB
  • ctags: 1,014
  • sloc: cpp: 9,530; sh: 4,426; makefile: 723; awk: 44
file content (95 lines) | stat: -rw-r--r-- 2,543 bytes parent folder | download | duplicates (3)
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
/*
 *	tardy - a tar post-processor
 *	Copyright (C) 1998, 1999, 2002 Peter Miller;
 *	All rights reserved.
 *
 *	This program is free software; you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License as published by
 *	the Free Software Foundation; either version 2 of the License, or
 *	(at your option) any later version.
 *
 *	This program is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *
 *	You should have received a copy of the GNU General Public License
 *	along with this program; if not, write to the Free Software
 *	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
 *
 * MANIFEST: interface definition for common/symtab.cc
 */

#ifndef COMMON_SYMTAB_H
#define COMMON_SYMTAB_H

#include <rcstring.h>

class symtab
{
public:
	~symtab();
	symtab();

	void *query(const rcstring &) const;
	rcstring query_fuzzy(const rcstring &) const;
	void assign(const rcstring &, void *);
	void assign_push(const rcstring &, void *);
	void remove(const rcstring &);
	void dump(const char *) const;
	void walk(void (*func)(const symtab &st, const rcstring &key,
		void *data, void *arg), void *arg);
	void reap_set(void (*)(void *));

private:
	symtab(const symtab &);
	symtab &operator = (const symtab &);
	void split(void);

	struct row
	{
		rcstring	key;
		void	*data;
		row	*overflow;
	};

	symtab	*chain;
	void		(*reap)(void *);
	row	**hash_table;
	str_hash_ty	hash_modulus;
	str_hash_ty	hash_cutover;
	str_hash_ty	hash_cutover_mask;
	str_hash_ty	hash_cutover_split_mask;
	str_hash_ty	hash_split;
	str_hash_ty	hash_load;
};

#if 0

template <T>
class symbol_table<T>:
	private symtab
{
public:
	~symbol_table<T>() {}
	symbol_table<T> : symtab() { reap_set(reaper); }

	void assign(const rcstring &key, const T &value)
		{ symtab::assign(key, new T(arg)); }
	void remove(const rcstring &key)
		{ symtab::remove(key); }
	bool contains(const rcstring &key) { return !!symtab::query(key); }
	T *query(const rcstring &key) { return (T *)symtab::query(key); }
	T &operator[](const rcstring &key) { void *tp = query(key);
		if (!tp) { tp = new T(); symtab::assign(key, tp); }
		return *tp; }

private:
	symbol_table<T>(const symbol_table<T> &) { }
	symbol_table<T> &operator = (const symbol_table<T> &) { return *this; }
	static void reaper(void *p) { delete (T *)p; }
};

#endif

#endif /* COMMON_SYMTAB_H */