File: dictionary.h.html

package info (click to toggle)
rudiments 0.31-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 7,516 kB
  • ctags: 3,248
  • sloc: asm: 23,776; cpp: 22,792; sh: 7,769; ansic: 1,769; makefile: 1,054; xml: 169; perl: 19
file content (230 lines) | stat: -rw-r--r-- 15,729 bytes parent folder | download | duplicates (2)
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<html>
<head>
<title>~/src/firstworks/rudiments-0.31/include/rudiments/dictionary.h.html</title>
<meta name="Generator" content="Vim/7.0">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#ffffff" text="#000000">
<pre>
<font color="#0000ff">// Copyright (c) 2003 David Muse</font>
<font color="#0000ff">// See the COPYING file for more information.</font>

<font color="#a020f0">#ifndef RUDIMENTS_DICTIONARY_H</font>
<font color="#a020f0">#define RUDIMENTS_DICTIONARY_H</font>

<font color="#a020f0">#include </font><font color="#ff00ff">&lt;rudiments/private/dictionaryincludes.h&gt;</font>

<font color="#0000ff">// The dictionary class allows you to store arbitrary numbers of key/value</font>
<font color="#0000ff">// pairs.  Since the dictionary class is template-based, you can store</font>
<font color="#0000ff">// arbitrary types of keys and values.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// Each dictionary is composed of a list of dictionarynode's.  Each</font>
<font color="#0000ff">// dictionarynode contains the key and value.</font>

<font color="#a020f0">#ifdef RUDIMENTS_NAMESPACE</font>
<font color="#2e8b57"><b>namespace</b></font> rudiments {
<font color="#a020f0">#endif</font>

<font color="#2e8b57"><b>template</b></font> &lt;<font color="#2e8b57"><b>class</b></font> keytype, <font color="#2e8b57"><b>class</b></font> datatype&gt;
<font color="#2e8b57"><b>class</b></font> dictionarynode {
        <font color="#a52a2a"><b>public</b></font>:
                        dictionarynode();
                        <font color="#0000ff">// Creates a new dictionary node, initializing the</font>
                        <font color="#0000ff">// key and data to 0.</font>
                <font color="#2e8b57"><b>virtual</b></font>       ~dictionarynode();

                <font color="#2e8b57"><b>void</b></font>  setKey(keytype key);
                        <font color="#0000ff">// Sets the key stored in the node to &quot;key&quot;.</font>
                <font color="#2e8b57"><b>void</b></font>  setData(datatype data);
                        <font color="#0000ff">// Sets the data stored in the node to &quot;data&quot;.</font>

                keytype         getKey() <font color="#2e8b57"><b>const</b></font>;
                                <font color="#0000ff">// Returns the key stored in the node.</font>
                datatype        getData() <font color="#2e8b57"><b>const</b></font>;
                                <font color="#0000ff">// Returns the data stored in the node.</font>

                <font color="#2e8b57"><b>int</b></font>   compare(keytype testkey) <font color="#2e8b57"><b>const</b></font>;
                        <font color="#0000ff">// Returns -1,0 or 1 if the key stored in the</font>
                        <font color="#0000ff">// node is less than, equal to or greater than</font>
                        <font color="#0000ff">// &quot;testkey&quot;.</font>

                <font color="#2e8b57"><b>void</b></font>  print() <font color="#2e8b57"><b>const</b></font>;
                        <font color="#0000ff">// Prints the key and data stored in the node.</font>

<font color="#a020f0">        #include </font><font color="#ff00ff">&lt;rudiments/private/dictionarynode.h&gt;</font>
};

<font color="#2e8b57"><b>template</b></font> &lt;<font color="#2e8b57"><b>class</b></font> keytype, <font color="#2e8b57"><b>class</b></font> datatype&gt;
<font color="#2e8b57"><b>class</b></font> dictionarylistnode :
                <font color="#a52a2a"><b>public</b></font> linkedlistnode&lt; dictionarynode&lt;keytype,datatype&gt; * &gt; {};

<font color="#2e8b57"><b>template</b></font> &lt;<font color="#2e8b57"><b>class</b></font> keytype, <font color="#2e8b57"><b>class</b></font> datatype&gt;
<font color="#2e8b57"><b>class</b></font> dictionarylist :
                <font color="#a52a2a"><b>public</b></font> linkedlist&lt; dictionarynode&lt;keytype,datatype&gt; *,
                                dictionarylistnode&lt;keytype,datatype&gt; &gt; {};

<font color="#2e8b57"><b>template</b></font> &lt;<font color="#2e8b57"><b>class</b></font> keytype, <font color="#2e8b57"><b>class</b></font> datatype,
        <font color="#2e8b57"><b>class</b></font> dictionarynodetype=dictionarynode&lt;keytype,datatype&gt;,
        <font color="#2e8b57"><b>class</b></font> dictionarylistnodetype=dictionarylistnode&lt;keytype,datatype&gt;,
        <font color="#2e8b57"><b>class</b></font> dictionarylisttype=dictionarylist&lt;keytype,datatype&gt; &gt;
<font color="#2e8b57"><b>class</b></font> dictionary {
        <font color="#a52a2a"><b>public</b></font>:
                        dictionary();
                        <font color="#0000ff">// Creates an empty dictionary</font>
                <font color="#2e8b57"><b>virtual</b></font> ~dictionary();
                        <font color="#0000ff">// Deletes the dictionary and all of it's</font>
                        <font color="#0000ff">// dictionarynodes.</font>

                <font color="#2e8b57"><b>void</b></font>  setData(keytype key, datatype data);
                        <font color="#0000ff">// Sets the data associated with &quot;key&quot; to &quot;data&quot;.</font>
                        <font color="#0000ff">// If &quot;key&quot; already exists, the data currently</font>
                        <font color="#0000ff">// accociated with it is replaced with &quot;data&quot;.</font>
                <font color="#2e8b57"><b>bool</b></font>  getData(keytype key, datatype *data);
                        <font color="#0000ff">// Sets &quot;data&quot; to the data associated with &quot;key&quot;.</font>
                        <font color="#0000ff">// Returns true on success or false if &quot;key&quot; wasn't</font>
                        <font color="#0000ff">// found.</font>
                <font color="#2e8b57"><b>bool</b></font>  removeData(keytype key);
                        <font color="#0000ff">// Removes the dictionarynode with &quot;key&quot;.</font>
                        <font color="#0000ff">// Returns true on success or false if &quot;key&quot; wasn't</font>
                        <font color="#0000ff">// found.</font>

                dictionarylisttype      *getList();
                                        <font color="#0000ff">// Returns the list used internally.</font>

                <font color="#2e8b57"><b>void</b></font>  clear();
                        <font color="#0000ff">// Deletes all dictionarynodes currently in the</font>
                        <font color="#0000ff">// dictionary.</font>

                <font color="#2e8b57"><b>void</b></font>  print();
                        <font color="#0000ff">// Prints out a representation of the dictionary.</font>

<font color="#a020f0">        #include </font><font color="#ff00ff">&lt;rudiments/private/dictionary.h&gt;</font>
};



<font color="#0000ff">// A set of classes for storing dictionaries who's keys are strings are</font>
<font color="#0000ff">// provided here for convenience.</font>
<font color="#2e8b57"><b>template</b></font> &lt;<font color="#2e8b57"><b>class</b></font> datatype&gt;
<font color="#2e8b57"><b>class</b></font> stringdictionarynode :
                <font color="#a52a2a"><b>public</b></font> dictionarynode&lt; <font color="#2e8b57"><b>char</b></font> *,datatype &gt; {
        <font color="#a52a2a"><b>public</b></font>:
                <font color="#2e8b57"><b>virtual</b></font>       ~stringdictionarynode();
};

<font color="#2e8b57"><b>template</b></font> &lt;<font color="#2e8b57"><b>class</b></font> datatype&gt;
<font color="#2e8b57"><b>class</b></font> stringdictionarylistnode :
                <font color="#a52a2a"><b>public</b></font> dictionarylistnode&lt; <font color="#2e8b57"><b>char</b></font> *, datatype &gt; {
        <font color="#a52a2a"><b>public</b></font>:
                <font color="#2e8b57"><b>virtual</b></font>       ~stringdictionarylistnode();
};

<font color="#2e8b57"><b>template</b></font> &lt;<font color="#2e8b57"><b>class</b></font> datatype&gt;
<font color="#2e8b57"><b>class</b></font> stringdictionarylist : <font color="#a52a2a"><b>public</b></font> dictionarylist&lt; <font color="#2e8b57"><b>char</b></font> *, datatype &gt; {
        <font color="#a52a2a"><b>public</b></font>:
                <font color="#2e8b57"><b>virtual</b></font>       ~stringdictionarylist();
};

<font color="#2e8b57"><b>template</b></font> &lt;<font color="#2e8b57"><b>class</b></font> datatype&gt;
<font color="#2e8b57"><b>class</b></font> stringdictionary : <font color="#a52a2a"><b>public</b></font> dictionary&lt; <font color="#2e8b57"><b>char</b></font> *, datatype,
                                stringdictionarynode&lt;datatype&gt;,
                                stringdictionarylistnode&lt;datatype&gt;,
                                stringdictionarylist&lt;datatype&gt; &gt; {
        <font color="#a52a2a"><b>public</b></font>:
                <font color="#2e8b57"><b>virtual</b></font>       ~stringdictionary();
};

<font color="#0000ff">// A set of classes for storing dictionaries who's keys are const strings are</font>
<font color="#0000ff">// provided here for convenience.</font>
<font color="#2e8b57"><b>template</b></font> &lt;<font color="#2e8b57"><b>class</b></font> datatype&gt;
<font color="#2e8b57"><b>class</b></font> conststringdictionarynode :
                <font color="#a52a2a"><b>public</b></font> dictionarynode&lt; <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *,datatype &gt; {
        <font color="#a52a2a"><b>public</b></font>:
                <font color="#2e8b57"><b>virtual</b></font>       ~conststringdictionarynode();
};

<font color="#2e8b57"><b>template</b></font> &lt;<font color="#2e8b57"><b>class</b></font> datatype&gt;
<font color="#2e8b57"><b>class</b></font> conststringdictionarylistnode :
                <font color="#a52a2a"><b>public</b></font> dictionarylistnode&lt; <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *, datatype &gt; {
        <font color="#a52a2a"><b>public</b></font>:
                <font color="#2e8b57"><b>virtual</b></font>       ~conststringdictionarylistnode();
};

<font color="#2e8b57"><b>template</b></font> &lt;<font color="#2e8b57"><b>class</b></font> datatype&gt;
<font color="#2e8b57"><b>class</b></font> conststringdictionarylist :
                <font color="#a52a2a"><b>public</b></font> dictionarylist&lt; <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *, datatype &gt; {
        <font color="#a52a2a"><b>public</b></font>:
                <font color="#2e8b57"><b>virtual</b></font>       ~conststringdictionarylist();
};

<font color="#2e8b57"><b>template</b></font> &lt;<font color="#2e8b57"><b>class</b></font> datatype&gt;
<font color="#2e8b57"><b>class</b></font> conststringdictionary : <font color="#a52a2a"><b>public</b></font> dictionary&lt; <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *, datatype,
                                conststringdictionarynode&lt;datatype&gt;,
                                conststringdictionarylistnode&lt;datatype&gt;,
                                conststringdictionarylist&lt;datatype&gt; &gt; {
        <font color="#a52a2a"><b>public</b></font>:
                <font color="#2e8b57"><b>virtual</b></font>       ~conststringdictionary();
};



<font color="#0000ff">// A set of classes for storing dictionaries who's keys are int32_t integers are</font>
<font color="#0000ff">// provided here for convenience.</font>
<font color="#2e8b57"><b>template</b></font> &lt;<font color="#2e8b57"><b>class</b></font> datatype&gt;
<font color="#2e8b57"><b>class</b></font> numericdictionarynode :
                <font color="#a52a2a"><b>public</b></font> dictionarynode&lt; <font color="#2e8b57"><b>int32_t</b></font>, datatype &gt; {
        <font color="#a52a2a"><b>public</b></font>:
                <font color="#2e8b57"><b>virtual</b></font>       ~numericdictionarynode();
};

<font color="#2e8b57"><b>template</b></font> &lt;<font color="#2e8b57"><b>class</b></font> datatype&gt;
<font color="#2e8b57"><b>class</b></font> numericdictionarylistnode :
                <font color="#a52a2a"><b>public</b></font> dictionarylistnode&lt; <font color="#2e8b57"><b>int32_t</b></font>, datatype &gt; {
        <font color="#a52a2a"><b>public</b></font>:
                <font color="#2e8b57"><b>virtual</b></font>       ~numericdictionarylistnode();
};

<font color="#2e8b57"><b>template</b></font> &lt;<font color="#2e8b57"><b>class</b></font> datatype&gt;
<font color="#2e8b57"><b>class</b></font> numericdictionarylist : <font color="#a52a2a"><b>public</b></font> dictionarylist&lt; <font color="#2e8b57"><b>int32_t</b></font>, datatype &gt; {
        <font color="#a52a2a"><b>public</b></font>:
                <font color="#2e8b57"><b>virtual</b></font>       ~numericdictionarylist();
};

<font color="#2e8b57"><b>template</b></font> &lt;<font color="#2e8b57"><b>class</b></font> datatype&gt;
<font color="#2e8b57"><b>class</b></font> numericdictionary : <font color="#a52a2a"><b>public</b></font> dictionary&lt; <font color="#2e8b57"><b>int32_t</b></font>, datatype,
                                numericdictionarynode&lt;datatype&gt;,
                                numericdictionarylistnode&lt;datatype&gt;,
                                numericdictionarylist&lt;datatype&gt; &gt; {
        <font color="#a52a2a"><b>public</b></font>:
                <font color="#2e8b57"><b>virtual</b></font>       ~numericdictionary();
};



<font color="#0000ff">// A set of classes for storing dictionaries who's keys and values are both</font>
<font color="#0000ff">// strings are provided here for convenience.</font>
<font color="#2e8b57"><b>typedef</b></font> stringdictionarynode&lt; <font color="#2e8b57"><b>char</b></font> * &gt;          namevaluepairsnode;
<font color="#2e8b57"><b>typedef</b></font> stringdictionarylistnode&lt; <font color="#2e8b57"><b>char</b></font> * &gt;      namevaluepairslistnode;
<font color="#2e8b57"><b>typedef</b></font> stringdictionarylist&lt; <font color="#2e8b57"><b>char</b></font> * &gt;          namevaluepairslist;
<font color="#2e8b57"><b>typedef</b></font> stringdictionary&lt; <font color="#2e8b57"><b>char</b></font> * &gt;              namevaluepairs;

<font color="#2e8b57"><b>typedef</b></font> conststringdictionarynode&lt; <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> * &gt;
                                constnamevaluepairsnode;
<font color="#2e8b57"><b>typedef</b></font> conststringdictionarylistnode&lt; <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> * &gt;
                                constnamevaluepairslistnode;
<font color="#2e8b57"><b>typedef</b></font> conststringdictionarylist&lt; <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> * &gt;
                                constnamevaluepairslist;
<font color="#2e8b57"><b>typedef</b></font> conststringdictionary&lt; <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> * &gt;
                                constnamevaluepairs;

<font color="#a020f0">#ifdef RUDIMENTS_NAMESPACE</font>
}
<font color="#a020f0">#endif</font>

<font color="#a020f0">#include </font><font color="#ff00ff">&lt;rudiments/private/dictionarynodeinlines.h&gt;</font>
<font color="#a020f0">#include </font><font color="#ff00ff">&lt;rudiments/private/dictionaryinlines.h&gt;</font>

<font color="#a020f0">#endif</font>
</pre>
</body>
</html>