PWLib
1.10.10
|
00001 /* 00002 * dict.h 00003 * 00004 * Dictionary (hash table) Container classes. 00005 * 00006 * Portable Windows Library 00007 * 00008 * Copyright (c) 1993-1998 Equivalence Pty. Ltd. 00009 * 00010 * The contents of this file are subject to the Mozilla Public License 00011 * Version 1.0 (the "License"); you may not use this file except in 00012 * compliance with the License. You may obtain a copy of the License at 00013 * http://www.mozilla.org/MPL/ 00014 * 00015 * Software distributed under the License is distributed on an "AS IS" 00016 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00017 * the License for the specific language governing rights and limitations 00018 * under the License. 00019 * 00020 * The Original Code is Portable Windows Library. 00021 * 00022 * The Initial Developer of the Original Code is Equivalence Pty. Ltd. 00023 * 00024 * Portions are Copyright (C) 1993 Free Software Foundation, Inc. 00025 * All Rights Reserved. 00026 * 00027 * Contributor(s): ______________________________________. 00028 * 00029 * $Log: dict.h,v $ 00030 * Revision 1.35 2005/11/25 03:43:47 csoutheren 00031 * Fixed function argument comments to be compatible with Doxygen 00032 * 00033 * Revision 1.34 2004/11/23 11:33:08 csoutheren 00034 * Fixed problem with RemoveAt returning invalid pointer in some cases, 00035 * and added extra documentation on this case. 00036 * Thanks to Diego Tartara for pointing out this potential problem 00037 * 00038 * Revision 1.33 2004/04/09 03:42:34 csoutheren 00039 * Removed all usages of "virtual inline" and "inline virtual" 00040 * 00041 * Revision 1.32 2004/04/03 23:53:09 csoutheren 00042 * Added various changes to improce compatibility with the Sun Forte compiler 00043 * Thanks to Brian Cameron 00044 * Added detection of readdir_r version 00045 * 00046 * Revision 1.31 2003/09/17 01:18:02 csoutheren 00047 * Removed recursive include file system and removed all references 00048 * to deprecated coooperative threading support 00049 * 00050 * Revision 1.30 2003/03/31 01:23:56 robertj 00051 * Added ReadFrom functions for standard container classes such as 00052 * PIntArray and PStringList etc 00053 * 00054 * Revision 1.29 2002/10/04 01:47:29 robertj 00055 * Added various increment and decrement operators to POrdinalKey. 00056 * 00057 * Revision 1.28 2002/09/16 01:08:59 robertj 00058 * Added #define so can select if #pragma interface/implementation is used on 00059 * platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan. 00060 * 00061 * Revision 1.27 2002/06/14 13:22:12 robertj 00062 * Fixed ability to remove elements from a PSet by value. 00063 * Added by value add and remove functions to a PSet. 00064 * Added a POrdinalSet class. 00065 * Fixed some documentation. 00066 * 00067 * Revision 1.26 2002/02/06 00:53:25 robertj 00068 * Fixed missing const on PSet::Contains and operator[], thanks Francisco Olarte Sanz 00069 * 00070 * Revision 1.25 1999/11/30 00:22:54 robertj 00071 * Updated documentation for doc++ 00072 * 00073 * Revision 1.24 1999/08/22 12:13:43 robertj 00074 * Fixed warning when using inlines on older GNU compiler 00075 * 00076 * Revision 1.23 1999/03/09 02:59:49 robertj 00077 * Changed comments to doc++ compatible documentation. 00078 * 00079 * Revision 1.22 1999/02/16 08:07:11 robertj 00080 * MSVC 6.0 compatibility changes. 00081 * 00082 * Revision 1.21 1998/09/23 06:20:27 robertj 00083 * Added open source copyright license. 00084 * 00085 * Revision 1.20 1998/01/05 10:39:34 robertj 00086 * Fixed "typesafe" templates/macros for dictionaries, especially on GNU. 00087 * 00088 * Revision 1.19 1997/12/11 10:27:16 robertj 00089 * Added type correct Contains() function to dictionaries. 00090 * 00091 * Revision 1.18 1997/07/08 13:15:05 robertj 00092 * DLL support. 00093 * 00094 * Revision 1.17 1997/06/08 04:49:11 robertj 00095 * Fixed non-template class descendent order. 00096 * 00097 * Revision 1.16 1996/08/17 10:00:22 robertj 00098 * Changes for Windows DLL support. 00099 * 00100 * Revision 1.15 1996/03/31 08:44:10 robertj 00101 * Added RemoveAt() function to remove entries from dictionaries. 00102 * 00103 * Revision 1.14 1996/02/08 11:50:01 robertj 00104 * Moved Contains function from PSet to PHashTable so available for dictionaries. 00105 * Added print for dictionaries key=data\n. 00106 * Added GetAt(PINDEX) to template classes to make identical to macro. 00107 * 00108 * Revision 1.13 1996/02/03 11:00:28 robertj 00109 * Temporary removal of SetAt() and GetAt() functions in dictionary macro. 00110 * 00111 * Revision 1.12 1996/01/24 14:43:11 robertj 00112 * Added initialisers to string dictionaries. 00113 * 00114 * Revision 1.11 1996/01/23 13:11:12 robertj 00115 * Mac Metrowerks compiler support. 00116 * 00117 * Revision 1.10 1995/06/17 11:12:29 robertj 00118 * Documentation update. 00119 * 00120 * Revision 1.9 1995/06/04 08:45:57 robertj 00121 * Better C++ compatibility (with BC++) 00122 * 00123 * Revision 1.8 1995/03/14 12:41:19 robertj 00124 * Updated documentation to use HTML codes. 00125 * 00126 * Revision 1.7 1995/02/22 10:50:29 robertj 00127 * Changes required for compiling release (optimised) version. 00128 * 00129 * Revision 1.6 1995/02/11 04:10:35 robertj 00130 * Fixed dictionary MACRO for templates. 00131 * 00132 * Revision 1.5 1995/02/05 00:48:03 robertj 00133 * Fixed template version. 00134 * 00135 * Revision 1.4 1995/01/09 12:35:31 robertj 00136 * Removed unnecesary return value from I/O functions. 00137 * Changes due to Mac port. 00138 * 00139 * Revision 1.3 1994/12/21 11:52:51 robertj 00140 * Documentation and variable normalisation. 00141 * 00142 * Revision 1.2 1994/12/17 01:36:57 robertj 00143 * Fixed memory leak in PStringSet 00144 * 00145 * Revision 1.1 1994/12/12 09:59:32 robertj 00146 * Initial revision 00147 * 00148 */ 00149 00150 #ifdef P_USE_PRAGMA 00151 #pragma interface 00152 #endif 00153 00154 00156 // PDictionary classes 00157 00161 class POrdinalKey : public PObject 00162 { 00163 PCLASSINFO(POrdinalKey, PObject); 00164 00165 public: 00170 PINLINE POrdinalKey( 00171 PINDEX newKey = 0 00172 ); 00173 00176 PINLINE POrdinalKey & operator=(PINDEX); 00178 00181 00182 virtual PObject * Clone() const; 00183 00184 /* Get the relative rank of the ordinal index. This is a simpel comparison 00185 of the objects PINDEX values. 00186 00187 @return 00188 comparison of the two objects, #EqualTo# for same, 00189 #LessThan# for #obj# logically less than the 00190 object and #GreaterThan# for #obj# logically 00191 greater than the object. 00192 */ 00193 virtual Comparison Compare(const PObject & obj) const; 00194 00201 virtual PINDEX HashFunction() const; 00202 00209 virtual void PrintOn(ostream & strm) const; 00211 00216 PINLINE operator PINDEX() const; 00217 00220 PINLINE PINDEX operator++(); 00221 00224 PINLINE PINDEX operator++(int); 00225 00228 PINLINE PINDEX operator--(); 00229 00232 PINLINE PINDEX operator--(int); 00233 00236 PINLINE POrdinalKey & operator+=(PINDEX); 00237 00240 PINLINE POrdinalKey & operator-=(PINDEX ); 00242 00243 private: 00244 PINDEX theKey; 00245 }; 00246 00247 00249 00260 class PHashTable : public PCollection 00261 { 00262 PCONTAINERINFO(PHashTable, PCollection); 00263 00264 public: 00267 00268 PHashTable(); 00270 00282 virtual Comparison Compare( 00283 const PObject & obj 00284 ) const; 00286 00287 00288 protected: 00298 virtual BOOL SetSize( 00299 PINDEX newSize 00300 ); 00302 00303 00314 PINLINE BOOL AbstractContains( 00315 const PObject & key 00316 ) const; 00317 00332 virtual const PObject & AbstractGetKeyAt( 00333 PINDEX index 00334 ) const; 00335 00350 virtual PObject & AbstractGetDataAt( 00351 PINDEX index 00352 ) const; 00354 00355 00356 // Member variables 00357 class Element { 00358 public: 00359 friend class Table; 00360 PObject * key; 00361 PObject * data; 00362 Element * next; 00363 Element * prev; 00364 }; 00365 00366 PDECLARE_BASEARRAY(Table, Element *) 00367 #ifdef DOC_PLUS_PLUS 00368 { 00369 #endif 00370 public: 00371 virtual ~Table() { Destruct(); } 00372 virtual void DestroyContents(); 00373 00374 PINDEX AppendElement(PObject * key, PObject * data); 00375 PObject * RemoveElement(const PObject & key); 00376 BOOL SetLastElementAt(PINDEX index); 00377 Element * GetElementAt(const PObject & key); 00378 PINDEX GetElementsIndex(const PObject*obj,BOOL byVal,BOOL keys) const; 00379 00380 PINDEX lastIndex; 00381 PINDEX lastBucket; 00382 Element * lastElement; 00383 00384 BOOL deleteKeys; 00385 00386 friend class PHashTable; 00387 friend class PAbstractSet; 00388 }; 00389 friend class Table; 00390 00391 00392 Table * hashTable; 00393 }; 00394 00395 00397 00400 class PAbstractSet : public PHashTable 00401 { 00402 PCONTAINERINFO(PAbstractSet, PHashTable); 00403 public: 00411 PINLINE PAbstractSet(); 00413 00424 virtual PINDEX Append( 00425 PObject * obj 00426 ); 00427 00440 virtual PINDEX Insert( 00441 const PObject & before, 00442 PObject * obj 00443 ); 00444 00457 virtual PINDEX InsertAt( 00458 PINDEX index, 00459 PObject * obj 00460 ); 00461 00472 virtual BOOL Remove( 00473 const PObject * obj 00474 ); 00475 00482 virtual PObject * RemoveAt( 00483 PINDEX index 00484 ); 00485 00491 virtual PObject * GetAt( 00492 PINDEX index 00493 ) const; 00494 00507 virtual BOOL SetAt( 00508 PINDEX index, 00509 PObject * val 00510 ); 00511 00523 virtual PINDEX GetObjectsIndex( 00524 const PObject * obj 00525 ) const; 00526 00535 virtual PINDEX GetValuesIndex( 00536 const PObject & obj 00537 ) const; 00539 }; 00540 00541 00542 #ifdef PHAS_TEMPLATES 00543 00554 template <class T> class PSet : public PAbstractSet 00555 { 00556 PCLASSINFO(PSet, PAbstractSet); 00557 00558 public: 00568 inline PSet(BOOL initialDeleteObjects = FALSE) 00569 : PAbstractSet() { AllowDeleteObjects(initialDeleteObjects); } 00571 00577 virtual PObject * Clone() const 00578 { return PNEW PSet(0, this); } 00580 00592 void Include( 00593 const T * obj // New object to include in the set. 00594 ) { Append((PObject *)obj); } 00595 00603 PSet & operator+=( 00604 const T & obj // New object to include in the set. 00605 ) { Append(obj.Clone()); return *this; } 00606 00614 void Exclude( 00615 const T * obj // New object to exclude in the set. 00616 ) { Remove(obj); } 00617 00625 PSet & operator-=( 00626 const T & obj // New object to exclude in the set. 00627 ) { RemoveAt(GetValuesIndex(obj)); return *this; } 00628 00637 BOOL Contains( 00638 const T & key 00639 ) const { return AbstractContains(key); } 00640 00649 BOOL operator[]( 00650 const T & key 00651 ) const { return AbstractContains(key); } 00652 00664 virtual const T & GetKeyAt( 00665 PINDEX index 00666 ) const 00667 { return (const T &)AbstractGetKeyAt(index); } 00669 00670 00671 protected: 00672 PSet(int dummy, const PSet * c) 00673 : PAbstractSet(dummy, c) 00674 { reference->deleteObjects = c->reference->deleteObjects; } 00675 }; 00676 00677 00689 #define PSET(cls, T) typedef PSet<T> cls 00690 00691 00703 #define PDECLARE_SET(cls, T, initDelObj) \ 00704 PSET(cls##_PTemplate, T); \ 00705 PDECLARE_CLASS(cls, cls##_PTemplate) \ 00706 protected: \ 00707 cls(int dummy, const cls * c) \ 00708 : cls##_PTemplate(dummy, c) { } \ 00709 public: \ 00710 cls(BOOL initialDeleteObjects = initDelObj) \ 00711 : cls##_PTemplate(initialDeleteObjects) { } \ 00712 virtual PObject * Clone() const \ 00713 { return PNEW cls(0, this); } \ 00714 00715 00716 #else // PHAS_TEMPLATES 00717 00718 00719 #define PSET(cls, K) \ 00720 class cls : public PAbstractSet { \ 00721 PCLASSINFO(cls, PAbstractSet); \ 00722 protected: \ 00723 inline cls(int dummy, const cls * c) \ 00724 : PAbstractSet(dummy, c) \ 00725 { reference->deleteObjects = c->reference->deleteObjects; } \ 00726 public: \ 00727 inline cls(BOOL initialDeleteObjects = FALSE) \ 00728 : PAbstractSet() { AllowDeleteObjects(initialDeleteObjects); } \ 00729 virtual PObject * Clone() const \ 00730 { return PNEW cls(0, this); } \ 00731 inline void Include(const PObject * key) \ 00732 { Append((PObject *)key); } \ 00733 inline void Exclude(const PObject * key) \ 00734 { Remove(key); } \ 00735 inline BOOL operator[](const K & key) const \ 00736 { return AbstractContains(key); } \ 00737 inline BOOL Contains(const K & key) const \ 00738 { return AbstractContains(key); } \ 00739 virtual const K & GetKeyAt(PINDEX index) const \ 00740 { return (const K &)AbstractGetKeyAt(index); } \ 00741 } 00742 00743 #define PDECLARE_SET(cls, K, initDelObj) \ 00744 PSET(cls##_PTemplate, K); \ 00745 PDECLARE_CLASS(cls, cls##_PTemplate) \ 00746 protected: \ 00747 inline cls(int dummy, const cls * c) \ 00748 : cls##_PTemplate(dummy, c) { } \ 00749 public: \ 00750 inline cls(BOOL initialDeleteObjects = initDelObj) \ 00751 : cls##_PTemplate() { AllowDeleteObjects(initialDeleteObjects); } \ 00752 virtual PObject * Clone() const \ 00753 { return PNEW cls(0, this); } \ 00754 00755 00756 #endif // PHAS_TEMPLATES 00757 00758 00759 PSET(POrdinalSet, POrdinalKey); 00760 00761 00763 00766 class PAbstractDictionary : public PHashTable 00767 { 00768 PCLASSINFO(PAbstractDictionary, PHashTable); 00769 public: 00777 PINLINE PAbstractDictionary(); 00779 00788 virtual void PrintOn( 00789 ostream &strm 00790 ) const; 00792 00803 virtual PINDEX Insert( 00804 const PObject & key, 00805 PObject * obj 00806 ); 00807 00814 virtual PINDEX InsertAt( 00815 PINDEX index, 00816 PObject * obj 00817 ); 00818 00828 virtual PObject * RemoveAt( 00829 PINDEX index 00830 ); 00831 00840 virtual BOOL SetAt( 00841 PINDEX index, 00842 PObject * val 00843 ); 00844 00852 virtual PObject * GetAt( 00853 PINDEX index 00854 ) const; 00855 00867 virtual PINDEX GetObjectsIndex( 00868 const PObject * obj 00869 ) const; 00870 00879 virtual PINDEX GetValuesIndex( 00880 const PObject & obj 00881 ) const; 00883 00884 00895 virtual BOOL SetDataAt( 00896 PINDEX index, 00897 PObject * obj 00898 ); 00899 00911 virtual BOOL AbstractSetAt( 00912 const PObject & key, 00913 PObject * obj 00914 ); 00915 00925 virtual PObject & GetRefAt( 00926 const PObject & key 00927 ) const; 00928 00935 virtual PObject * AbstractGetAt( 00936 const PObject & key 00937 ) const; 00939 00940 protected: 00941 PINLINE PAbstractDictionary(int dummy, const PAbstractDictionary * c); 00942 00943 private: 00944 virtual PINDEX Append( 00945 PObject * obj // New object to place into the collection. 00946 ); 00947 /* This function is meaningless and will assert. 00948 00949 @return 00950 Always zero. 00951 */ 00952 00953 virtual BOOL Remove( 00954 const PObject * obj // Existing object to remove from the collection. 00955 ); 00956 /* Remove the object from the collection. If the AllowDeleteObjects option 00957 is set then the object is also deleted. 00958 00959 Note that the comparison for searching for the object in collection is 00960 made by pointer, not by value. Thus the parameter must point to the 00961 same instance of the object that is in the collection. 00962 00963 @return 00964 TRUE if the object was in the collection. 00965 */ 00966 00967 }; 00968 00969 00970 #ifdef PHAS_TEMPLATES 00971 00979 template <class K, class D> class PDictionary : public PAbstractDictionary 00980 { 00981 PCLASSINFO(PDictionary, PAbstractDictionary); 00982 00983 public: 00992 PDictionary() 00993 : PAbstractDictionary() { } 00995 01002 virtual PObject * Clone() const 01003 { return PNEW PDictionary(0, this); } 01005 01018 D & operator[]( 01019 const K & key 01020 ) const 01021 { return (D &)GetRefAt(key); } 01022 01031 BOOL Contains( 01032 const K & key 01033 ) const { return AbstractContains(key); } 01034 01046 virtual D * RemoveAt( 01047 const K & key 01048 ) { 01049 D * obj = GetAt(key); AbstractSetAt(key, NULL); 01050 return reference->deleteObjects ? (obj ? (D *)-1 : NULL) : obj; 01051 } 01052 01064 virtual BOOL SetAt( 01065 const K & key, // Key for position in dictionary to add object. 01066 D * obj // New object to put into the dictionary. 01067 ) { return AbstractSetAt(key, obj); } 01068 01075 virtual D * GetAt( 01076 const K & key // Key for position in dictionary to get object. 01077 ) const { return (D *)AbstractGetAt(key); } 01078 01090 const K & GetKeyAt( 01091 PINDEX index 01092 ) const 01093 { return (const K &)AbstractGetKeyAt(index); } 01094 01106 D & GetDataAt( 01107 PINDEX index 01108 ) const 01109 { return (D &)AbstractGetDataAt(index); } 01111 01112 protected: 01113 PDictionary(int dummy, const PDictionary * c) 01114 : PAbstractDictionary(dummy, c) { } 01115 }; 01116 01117 01130 #define PDICTIONARY(cls, K, D) typedef PDictionary<K, D> cls 01131 01132 01145 #define PDECLARE_DICTIONARY(cls, K, D) \ 01146 PDICTIONARY(cls##_PTemplate, K, D); \ 01147 PDECLARE_CLASS(cls, cls##_PTemplate) \ 01148 protected: \ 01149 cls(int dummy, const cls * c) \ 01150 : cls##_PTemplate(dummy, c) { } \ 01151 public: \ 01152 cls() \ 01153 : cls##_PTemplate() { } \ 01154 virtual PObject * Clone() const \ 01155 { return PNEW cls(0, this); } \ 01156 01157 01165 template <class K> class POrdinalDictionary : public PAbstractDictionary 01166 { 01167 PCLASSINFO(POrdinalDictionary, PAbstractDictionary); 01168 01169 public: 01178 POrdinalDictionary() 01179 : PAbstractDictionary() { } 01181 01188 virtual PObject * Clone() const 01189 { return PNEW POrdinalDictionary(0, this); } 01191 01204 PINDEX operator[]( 01205 const K & key // Key to look for in the dictionary. 01206 ) const 01207 { return (POrdinalKey &)GetRefAt(key); } 01208 01217 BOOL Contains( 01218 const K & key 01219 ) const { return AbstractContains(key); } 01220 01221 virtual POrdinalKey * GetAt( 01222 const K & key 01223 ) const { return (POrdinalKey *)AbstractGetAt(key); } 01224 /* Get the object at the specified key position. If the key was not in the 01225 collection then NULL is returned. 01226 01227 @return 01228 pointer to object at the specified key. 01229 */ 01230 01239 virtual BOOL SetDataAt( 01240 PINDEX index, 01241 PINDEX ordinal 01242 ) { return PAbstractDictionary::SetDataAt(index, PNEW POrdinalKey(ordinal)); } 01243 01255 virtual BOOL SetAt( 01256 const K & key, 01257 PINDEX ordinal 01258 ) { return AbstractSetAt(key, PNEW POrdinalKey(ordinal)); } 01259 01268 virtual PINDEX RemoveAt( 01269 const K & key 01270 ) { PINDEX ord = *GetAt(key); AbstractSetAt(key, NULL); return ord; } 01271 01283 const K & GetKeyAt( 01284 PINDEX index 01285 ) const 01286 { return (const K &)AbstractGetKeyAt(index); } 01287 01299 PINDEX GetDataAt( 01300 PINDEX index 01301 ) const 01302 { return (POrdinalKey &)AbstractGetDataAt(index); } 01304 01305 protected: 01306 POrdinalDictionary(int dummy, const POrdinalDictionary * c) 01307 : PAbstractDictionary(dummy, c) { } 01308 }; 01309 01310 01323 #define PORDINAL_DICTIONARY(cls, K) typedef POrdinalDictionary<K> cls 01324 01325 01340 #define PDECLARE_ORDINAL_DICTIONARY(cls, K) \ 01341 PORDINAL_DICTIONARY(cls##_PTemplate, K); \ 01342 PDECLARE_CLASS(cls, POrdinalDictionary<K>) \ 01343 protected: \ 01344 cls(int dummy, const cls * c) \ 01345 : cls##_PTemplate(dummy, c) { } \ 01346 public: \ 01347 cls() \ 01348 : cls##_PTemplate() { } \ 01349 virtual PObject * Clone() const \ 01350 { return PNEW cls(0, this); } \ 01351 01352 01353 #else // PHAS_TEMPLATES 01354 01355 01356 #define PDICTIONARY(cls, K, D) \ 01357 class cls : public PAbstractDictionary { \ 01358 PCLASSINFO(cls, PAbstractDictionary); \ 01359 protected: \ 01360 inline cls(int dummy, const cls * c) \ 01361 : PAbstractDictionary(dummy, c) { } \ 01362 public: \ 01363 cls() \ 01364 : PAbstractDictionary() { } \ 01365 virtual PObject * Clone() const \ 01366 { return PNEW cls(0, this); } \ 01367 D & operator[](const K & key) const \ 01368 { return (D &)GetRefAt(key); } \ 01369 virtual BOOL Contains(const K & key) const \ 01370 { return AbstractContains(key); } \ 01371 virtual D * RemoveAt(const K & key) \ 01372 { D * obj = GetAt(key); AbstractSetAt(key, NULL); return obj; } \ 01373 virtual BOOL SetAt(const K & key, D * obj) \ 01374 { return AbstractSetAt(key, obj); } \ 01375 virtual D * GetAt(const K & key) const \ 01376 { return (D *)AbstractGetAt(key); } \ 01377 const K & GetKeyAt(PINDEX index) const \ 01378 { return (const K &)AbstractGetKeyAt(index); } \ 01379 D & GetDataAt(PINDEX index) const \ 01380 { return (D &)AbstractGetDataAt(index); } \ 01381 } 01382 01383 #define PDECLARE_DICTIONARY(cls, K, D) \ 01384 PDICTIONARY(cls##_PTemplate, K, D); \ 01385 PDECLARE_CLASS(cls, cls##_PTemplate) \ 01386 protected: \ 01387 cls(int dummy, const cls * c) \ 01388 : cls##_PTemplate(dummy, c) { } \ 01389 public: \ 01390 cls() \ 01391 : cls##_PTemplate() { } \ 01392 virtual PObject * Clone() const \ 01393 { return PNEW cls(0, this); } \ 01394 01395 01396 #define PORDINAL_DICTIONARY(cls, K) \ 01397 class cls : public PAbstractDictionary { \ 01398 PCLASSINFO(cls, PAbstractDictionary); \ 01399 protected: \ 01400 inline cls(int dummy, const cls * c) \ 01401 : PAbstractDictionary(dummy, c) { } \ 01402 public: \ 01403 inline cls() \ 01404 : PAbstractDictionary() { } \ 01405 virtual PObject * Clone() const \ 01406 { return PNEW cls(0, this); } \ 01407 inline PINDEX operator[](const K & key) const \ 01408 { return (POrdinalKey &)GetRefAt(key); } \ 01409 virtual BOOL Contains(const K & key) const \ 01410 { return AbstractContains(key); } \ 01411 virtual POrdinalKey * GetAt(const K & key) const \ 01412 { return (POrdinalKey *)AbstractGetAt(key); } \ 01413 virtual BOOL SetDataAt(PINDEX index, PINDEX ordinal) \ 01414 { return PAbstractDictionary::SetDataAt(index, PNEW POrdinalKey(ordinal)); } \ 01415 virtual BOOL SetAt(const K & key, PINDEX ordinal) \ 01416 { return AbstractSetAt(key, PNEW POrdinalKey(ordinal)); } \ 01417 virtual PINDEX RemoveAt(const K & key) \ 01418 { PINDEX ord = *GetAt(key); AbstractSetAt(key, NULL); return ord; } \ 01419 inline const K & GetKeyAt(PINDEX index) const \ 01420 { return (const K &)AbstractGetKeyAt(index); } \ 01421 inline PINDEX GetDataAt(PINDEX index) const \ 01422 { return (POrdinalKey &)AbstractGetDataAt(index); } \ 01423 } 01424 01425 #define PDECLARE_ORDINAL_DICTIONARY(cls, K) \ 01426 PORDINAL_DICTIONARY(cls##_PTemplate, K); \ 01427 PDECLARE_CLASS(cls, cls##_PTemplate) \ 01428 protected: \ 01429 cls(int dummy, const cls * c) \ 01430 : cls##_PTemplate(dummy, c) { } \ 01431 public: \ 01432 cls() \ 01433 : cls##_PTemplate() { } \ 01434 virtual PObject * Clone() const \ 01435 { return PNEW cls(0, this); } \ 01436 01437 01438 #endif // PHAS_TEMPLATES 01439 01440 // End Of File ///////////////////////////////////////////////////////////////