summaryrefslogtreecommitdiffstats
path: root/private/unimodem/new/mic/sym.h
blob: 054fcb5691186170ebf4641ee92ff43efdac5bd5 (plain) (blame)
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
//
//		Copyright (c) 1996 Microsoft Corporation
//
//
//		SYM.H		-- Header for Classes:
//							CInfSymbolTable
//							CInfSymbol
//
//		History:
//			05/21/96	JosephJ		Created
//
//
#ifndef _SYM_H_
#define _SYM_H_

class CInfSymbolList;

///////////////////////////////////////////////////////////////////////////
//		CLASS CInfSymbol
///////////////////////////////////////////////////////////////////////////

//	Represents a symbol in the symbol table.
//	Note: Only CInfSymbolTable member functions can construct/destruct these
//	objects.
//
//  Empty string maps to NULL symbol. So a NULL pointer is perfectly valid for
//  all member functions.
//  GetText(NULL) returns the empty string, and Checksum returns 0x0.
//  Strcmpi treats NULL pointer as the empty string.

class CInfSymbol
{

public:

	//--------------	GetText			------------------
	// Return the text associated with this symbol as a null-terminated
	// string
	const TCHAR *	GetText(void) const;

	//--------------	GetTextLength	------------------
	// Return the length of the text associated with this symbol,
	// not counting terminating zero.
	UINT 			GetTextLength() const;

	//--------------	Strcmpi			------------------
	// Case-insensitive equal
	// -ve implies this is less-than pSym
	int				Strcmpi(const CInfSymbol *pSym) const
	{
		if (this && pSym)
		{
			return lstrcmpi(m_rgchText, pSym->m_rgchText);
		}
		else if (this && !pSym)
		{
			return 1;
		}
		else if (!this && pSym)
		{
			return -1;
		}
		else
		{
			return 0;
		}
	}

	//--------------	Release			------------------
	// Release (decrement ref-count) of this symbol
	void	Release(void) const;

	//--------------	Dump			------------------
	// Dump state
	void Dump(void) const;

	// ---------------	Checksum		------------------
	// Return checksum of contents
	DWORD	Checksum(void)	const	{return (this) ? m_dwChecksum : 0;}

	// ---------------	SetProp			------------------
	BOOL	SetProp(const CInfSymbol *pSymPropName, void *pvProp)	const;

	// ---------------	GetProp			------------------
	BOOL	GetProp(const CInfSymbol *pSymPropName, void **ppvProp)	const;

	// ---------------	GetOrCreatePropLoc	--------------
	BOOL
	GetOrCreatePropLoc(
		const CInfSymbol *pSymPropName,
		void ***ppvProp,
		BOOL *pfExists
		)
	const;

	// ---------------	DelProp			------------------
	BOOL	DelProp(const CInfSymbol *pSymPropName)	const;

private:

	friend class CInfSymbolTable;

	CInfSymbol
	(
		const TCHAR rgchName[],
		UINT cchName,
		DWORD dwChecksum,
		const CInfSymbol *pNext
	);

	~CInfSymbol();

	const CInfSymbol *Next(void) const {return m_pNext;}

	const TCHAR			*	m_rgchText;
	const UINT	 			m_cchText;
	const DWORD				m_dwChecksum;
	const CInfSymbol	*	m_pNext;
	CInfSymbolList		*	m_pPropList;

};


///////////////////////////////////////////////////////////////////////////
//		CLASS CInfSymbolTable
///////////////////////////////////////////////////////////////////////////

//	A symbol table.

static const UINT SYMTABSIZE		= 1000;
static const UINT TEXTSTORESIZE	= 1000*1000;


class CInfSymbolTable
{

public:

	CInfSymbolTable(void);
	~CInfSymbolTable();

	// TODO -- add "context" parameter to symbols -- symbols with different
	// context will be stored separately even if their name is the same.
	// Context is not interpreted by the symbol table, except to test for
	// equality. When implementing this, add a context parameter to
	// InfSymbols's constructor, and a member fn "GetContext()" to InfSymbol.

	//--------------	Lookup			------------------
	// Look up and return the symbol with the specified text
	// This symbol must be released by calling its Release function
	// when it is no longer needed.
	const CInfSymbol * Lookup(const TCHAR rgchName[], BOOL fInsert);

	//--------------	Dump			------------------
	// Dump state
	void Dump(void) const;

private:

	const CInfSymbol	*	m_rgpSym[SYMTABSIZE];
	TCHAR					m_rgchTextStore[TEXTSTORESIZE];
	TCHAR				*	m_pchFree;
	TCHAR				*	m_pchLastFree;

	CSync					m_sync;
	UINT					m_cSymbols;

	void mfn_EnterCrit(void)	const	{m_sync.EnterCrit();}
	void mfn_LeaveCrit(void)	const	{m_sync.LeaveCrit();}

};


class CInfSymbolList : private CInfList
{
	CInfSymbolList
	(
		const CInfSymbol *pSym,
		void *pvData,
		const CInfSymbolList *pNext
	)
	: CInfList(pvData, pNext), m_pSym(pSym)
	{
	}

	const CInfSymbolList	*
	Next		(void)
	const
	{
		return (const CInfSymbolList *) CInfList::Next();
	}

	const CInfSymbol * GetSym(void)	{return m_pSym;}

	~CInfSymbolList ()	{}

	// --------------------------- Find -----------------------------
	// Looks for the specified symbol, returns the list element with that
	// symbol.  If ppListPrev is non-NULL, sets it to the previous list element
	// (if no previous element, sets it to NULL). If the  symbol is not found,
	// *ppListPrev is not touched.
	static
	const CInfSymbolList *
	Find
	(
		const CInfSymbolList *pList,
		const CInfSymbol *pSym,
		const CInfSymbolList **ppListPrev
	);

private:
	const CInfSymbol *m_pSym;
};

#endif // _SYM_H_