<html> <head> <link rel="stylesheet" href="page.css" type="text/css"> <title>fox-toolkit.org - Documentation</title> </head> <body bgcolor=#ffffff link=#990033 vlink=#990033 alink=#990033 text=#000000> <font face='verdana,sans-serif' size=2 > <!---- TOPIC TITLE WITH LOGO---> <table border=0 cellpadding= cellspacing=2 width=100% ><tr><td><a href='http://www.fox-toolkit.org/doc.html'><img src='../art/foxlogo_small.jpg' border=0></a></td><td width=100% valign=bottom><font face='verdana,sans-serif' size=2 ><b> <a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Compound Members</a> <br><img src='../art/line.gif' width=100% height=1></b></font></td></tr></table> <p> <!--- TOPIC TITLE WITH LOGO ---> <!-- Generated by Doxygen 1.3.3 --> <h1>FXDict.h</h1><div class="fragment"><pre>00001 <span class="comment">/********************************************************************************</span> 00002 <span class="comment">* *</span> 00003 <span class="comment">* S t r i n g D i c t i o n a r y C l a s s *</span> 00004 <span class="comment">* *</span> 00005 <span class="comment">*********************************************************************************</span> 00006 <span class="comment">* Copyright (C) 1998,2004 by Jeroen van der Zijp. All Rights Reserved. *</span> 00007 <span class="comment">*********************************************************************************</span> 00008 <span class="comment">* This library is free software; you can redistribute it and/or *</span> 00009 <span class="comment">* modify it under the terms of the GNU Lesser General Public *</span> 00010 <span class="comment">* License as published by the Free Software Foundation; either *</span> 00011 <span class="comment">* version 2.1 of the License, or (at your option) any later version. *</span> 00012 <span class="comment">* *</span> 00013 <span class="comment">* This library is distributed in the hope that it will be useful, *</span> 00014 <span class="comment">* but WITHOUT ANY WARRANTY; without even the implied warranty of *</span> 00015 <span class="comment">* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *</span> 00016 <span class="comment">* Lesser General Public License for more details. *</span> 00017 <span class="comment">* *</span> 00018 <span class="comment">* You should have received a copy of the GNU Lesser General Public *</span> 00019 <span class="comment">* License along with this library; if not, write to the Free Software *</span> 00020 <span class="comment">* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *</span> 00021 <span class="comment">*********************************************************************************</span> 00022 <span class="comment">* $Id: FXDict.h,v 1.19 2004/02/08 17:17:33 fox Exp $ *</span> 00023 <span class="comment">********************************************************************************/</span> 00024 <span class="preprocessor">#ifndef FXDICT_H</span> 00025 <span class="preprocessor"></span><span class="preprocessor">#define FXDICT_H</span> 00026 <span class="preprocessor"></span> 00027 <span class="preprocessor">#ifndef FXOBJECT_H</span> 00028 <span class="preprocessor"></span><span class="preprocessor">#include "FXObject.h"</span> 00029 <span class="preprocessor">#endif</span> 00030 <span class="preprocessor"></span> 00031 <span class="keyword">namespace </span>FX { 00032 00033 <span class="comment"></span> 00034 <span class="comment">/**</span> 00035 <span class="comment">* The dictionary class maintains a fast-access hash table of entities</span> 00036 <span class="comment">* indexed by a character string.</span> 00037 <span class="comment">* It is typically used to map strings to pointers; however, overloading</span> 00038 <span class="comment">* the createData() and deleteData() members allows any type of data to</span> 00039 <span class="comment">* be indexed by strings.</span> 00040 <span class="comment">*/</span> <a name="l00041"></a><a class="code" href="classFX_1_1FXDict.html">00041</a> <span class="keyword">class </span>FXAPI FXDict : <span class="keyword">public</span> <a class="code" href="classFX_1_1FXObject.html">FXObject</a> { 00042 FXDECLARE(FXDict) 00043 <span class="keyword">protected</span>: 00044 <span class="keyword">struct </span>FXDictEntry { 00045 FXchar *key; <span class="comment">// Key string</span> 00046 <span class="keywordtype">void</span> *data; <span class="comment">// Data</span> 00047 FXint hash; <span class="comment">// Hash value of key</span> 00048 FXbool mark; <span class="comment">// Entry is marked</span> 00049 }; 00050 <span class="keyword">protected</span>: 00051 FXDictEntry *dict; <span class="comment">// Dictionary</span> 00052 FXint total; <span class="comment">// Dictionary size</span> <a name="l00053"></a><a class="code" href="classFX_1_1FXDict.html#a1">00053</a> FXint number; <span class="comment">// Number of entries</span> 00054 <span class="keyword">protected</span>: 00055 <span class="comment"></span> 00056 <span class="comment"> /**</span> 00057 <span class="comment"> * Overload this function in a derived class to return the</span> 00058 <span class="comment"> * data pointer given an input pointer; the default implementation</span> 00059 <span class="comment"> * just returns the input pointer.</span> 00060 <span class="comment"> */</span> 00061 <span class="keyword">virtual</span> <span class="keywordtype">void</span> *createData(<span class="keyword">const</span> <span class="keywordtype">void</span>*); 00062 <span class="comment"></span> <a name="l00063"></a><a class="code" href="classFX_1_1FXDict.html#a3">00063</a> <span class="comment"> /**</span> 00064 <span class="comment"> * Overload this function in a derived class to delete the pointer</span> 00065 <span class="comment"> * previously returned by createData(); the default implementation</span> 00066 <span class="comment"> * does nothing.</span> 00067 <span class="comment"> */</span> 00068 <span class="keyword">virtual</span> <span class="keywordtype">void</span> deleteData(<span class="keywordtype">void</span>*); 00069 <span class="keyword">private</span>: 00070 FXDict(<span class="keyword">const</span> FXDict&); 00071 FXDict &operator=(<span class="keyword">const</span> FXDict&); 00072 <span class="keyword">public</span>: 00073 <span class="comment"></span> 00074 <span class="comment"> /**</span> 00075 <span class="comment"> * Construct an empty dictionary.</span> 00076 <span class="comment"> */</span> 00077 FXDict(); 00078 <span class="comment"></span> 00079 <span class="comment"> /**</span> 00080 <span class="comment"> * Return the size of the table, including the empty slots.</span> 00081 <span class="comment"> */</span> 00082 FXint size()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> total; } 00083 <span class="comment"></span> 00084 <span class="comment"> /**</span> 00085 <span class="comment"> * Resize the table to the given size.</span> 00086 <span class="comment"> */</span> 00087 <span class="keywordtype">void</span> size(FXint m); 00088 <span class="comment"></span> 00089 <span class="comment"> /**</span> 00090 <span class="comment"> * Return the total number of entries in the table.</span> 00091 <span class="comment"> */</span> <a name="l00092"></a><a class="code" href="classFX_1_1FXDict.html#a8">00092</a> FXint no()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> number; } 00093 <span class="comment"></span> 00094 <span class="comment"> /**</span> 00095 <span class="comment"> * Insert a new entry into the table given key and mark.</span> 00096 <span class="comment"> * If there is already an entry with that key, leave it unchanged,</span> <a name="l00097"></a><a class="code" href="classFX_1_1FXDict.html#a9">00097</a> <span class="comment"> * otherwise insert the new entry.</span> 00098 <span class="comment"> */</span> 00099 <span class="keywordtype">void</span>* insert(<span class="keyword">const</span> FXchar* ky,<span class="keyword">const</span> <span class="keywordtype">void</span>* ptr,FXbool mrk=FALSE); 00100 <span class="comment"></span> 00101 <span class="comment"> /**</span> <a name="l00102"></a><a class="code" href="classFX_1_1FXDict.html#a10">00102</a> <span class="comment"> * Replace data at key, if the entry's mark is less than</span> 00103 <span class="comment"> * or equal to the given mark. If there was no existing entry,</span> 00104 <span class="comment"> * a new entry is inserted with the given mark.</span> 00105 <span class="comment"> */</span> 00106 <span class="keywordtype">void</span>* replace(<span class="keyword">const</span> FXchar* ky,<span class="keyword">const</span> <span class="keywordtype">void</span>* ptr,FXbool mrk=FALSE); 00107 <span class="comment"></span> 00108 <span class="comment"> /**</span> 00109 <span class="comment"> * Remove data given key.</span> 00110 <span class="comment"> */</span> 00111 <span class="keywordtype">void</span>* remove(<span class="keyword">const</span> FXchar* ky); 00112 <span class="comment"></span> 00113 <span class="comment"> /**</span> 00114 <span class="comment"> * Find data pointer given key.</span> 00115 <span class="comment"> */</span> 00116 <span class="keywordtype">void</span>* find(<span class="keyword">const</span> FXchar* ky) <span class="keyword">const</span>; 00117 <span class="comment"></span> 00118 <span class="comment"> /**</span> 00119 <span class="comment"> * Return key at position pos.</span> 00120 <span class="comment"> */</span> 00121 <span class="keyword">const</span> FXchar* key(FXuint pos)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> dict[pos].key; } 00122 <span class="comment"></span> 00123 <span class="comment"> /**</span> 00124 <span class="comment"> * return data pointer at position pos.</span> 00125 <span class="comment"> */</span> 00126 <span class="keywordtype">void</span>* data(FXuint pos)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> dict[pos].data; } 00127 <span class="comment"></span> 00128 <span class="comment"> /**</span> 00129 <span class="comment"> * Return mark flag of entry at position pos.</span> 00130 <span class="comment"> */</span> 00131 FXbool mark(FXuint pos)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> dict[pos].mark; } 00132 <span class="comment"></span> 00133 <span class="comment"> /**</span> 00134 <span class="comment"> * Return position of first filled slot, or >= total</span> 00135 <span class="comment"> */</span> 00136 FXint first() <span class="keyword">const</span>; 00137 <span class="comment"></span> 00138 <span class="comment"> /**</span> 00139 <span class="comment"> * Return position of last filled slot or -1</span> 00140 <span class="comment"> */</span> 00141 FXint last() <span class="keyword">const</span>; 00142 00143 <span class="comment"></span> 00144 <span class="comment"> /**</span> 00145 <span class="comment"> * Return position of next filled slot in hash table</span> 00146 <span class="comment"> * or a value greater than or equal to total if no filled</span> 00147 <span class="comment"> * slot was found</span> 00148 <span class="comment"> */</span> 00149 FXint next(FXint pos) <span class="keyword">const</span>; 00150 <span class="comment"></span> 00151 <span class="comment"> /**</span> 00152 <span class="comment"> * Return position of previous filled slot in hash table</span> 00153 <span class="comment"> * or a -1 if no filled slot was found</span> 00154 <span class="comment"> */</span> 00155 FXint prev(FXint pos) <span class="keyword">const</span>; 00156 <span class="comment"></span> 00157 <span class="comment"> /// Clear all entries</span> 00158 <span class="comment"></span> <span class="keywordtype">void</span> clear(); 00159 <span class="comment"></span> 00160 <span class="comment"> /// Destructor</span> 00161 <span class="comment"></span> <span class="keyword">virtual</span> ~FXDict(); 00162 }; 00163 00164 } 00165 00166 <span class="preprocessor">#endif</span> </pre></div></font> <!--- COPYRIGHT --> <p> <table width=100% cellpadding=0 cellspacing=0><tr><td width=100% valign=top id=HEADLINE align=right> <img src='../art/line.gif' width=100% height=1><font size=-1> Copyright © 1997-2004 Jeroen van der Zijp</font> </td></tr></table> </p> <!--- COPYRIGHT --> </body> </html>