Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

dict.h

Go to the documentation of this file.
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.34  2004/11/23 11:33:08  csoutheren
00031  * Fixed problem with RemoveAt returning invalid pointer in some cases,
00032  * and added extra documentation on this case.
00033  * Thanks to Diego Tartara for pointing out this potential problem
00034  *
00035  * Revision 1.33  2004/04/09 03:42:34  csoutheren
00036  * Removed all usages of "virtual inline" and "inline virtual"
00037  *
00038  * Revision 1.32  2004/04/03 23:53:09  csoutheren
00039  * Added various changes to improce compatibility with the Sun Forte compiler
00040  *   Thanks to Brian Cameron
00041  * Added detection of readdir_r version
00042  *
00043  * Revision 1.31  2003/09/17 01:18:02  csoutheren
00044  * Removed recursive include file system and removed all references
00045  * to deprecated coooperative threading support
00046  *
00047  * Revision 1.30  2003/03/31 01:23:56  robertj
00048  * Added ReadFrom functions for standard container classes such as
00049  *   PIntArray and PStringList etc
00050  *
00051  * Revision 1.29  2002/10/04 01:47:29  robertj
00052  * Added various increment and decrement operators to POrdinalKey.
00053  *
00054  * Revision 1.28  2002/09/16 01:08:59  robertj
00055  * Added #define so can select if #pragma interface/implementation is used on
00056  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00057  *
00058  * Revision 1.27  2002/06/14 13:22:12  robertj
00059  * Fixed ability to remove elements from a PSet by value.
00060  * Added by value add and remove functions to a PSet.
00061  * Added a POrdinalSet class.
00062  * Fixed some documentation.
00063  *
00064  * Revision 1.26  2002/02/06 00:53:25  robertj
00065  * Fixed missing const on PSet::Contains and operator[], thanks Francisco Olarte Sanz
00066  *
00067  * Revision 1.25  1999/11/30 00:22:54  robertj
00068  * Updated documentation for doc++
00069  *
00070  * Revision 1.24  1999/08/22 12:13:43  robertj
00071  * Fixed warning when using inlines on older GNU compiler
00072  *
00073  * Revision 1.23  1999/03/09 02:59:49  robertj
00074  * Changed comments to doc++ compatible documentation.
00075  *
00076  * Revision 1.22  1999/02/16 08:07:11  robertj
00077  * MSVC 6.0 compatibility changes.
00078  *
00079  * Revision 1.21  1998/09/23 06:20:27  robertj
00080  * Added open source copyright license.
00081  *
00082  * Revision 1.20  1998/01/05 10:39:34  robertj
00083  * Fixed "typesafe" templates/macros for dictionaries, especially on GNU.
00084  *
00085  * Revision 1.19  1997/12/11 10:27:16  robertj
00086  * Added type correct Contains() function to dictionaries.
00087  *
00088  * Revision 1.18  1997/07/08 13:15:05  robertj
00089  * DLL support.
00090  *
00091  * Revision 1.17  1997/06/08 04:49:11  robertj
00092  * Fixed non-template class descendent order.
00093  *
00094  * Revision 1.16  1996/08/17 10:00:22  robertj
00095  * Changes for Windows DLL support.
00096  *
00097  * Revision 1.15  1996/03/31 08:44:10  robertj
00098  * Added RemoveAt() function to remove entries from dictionaries.
00099  *
00100  * Revision 1.14  1996/02/08 11:50:01  robertj
00101  * Moved Contains function from PSet to PHashTable so available for dictionaries.
00102  * Added print for dictionaries key=data\n.
00103  * Added GetAt(PINDEX) to template classes to make identical to macro.
00104  *
00105  * Revision 1.13  1996/02/03 11:00:28  robertj
00106  * Temporary removal of SetAt() and GetAt() functions in dictionary macro.
00107  *
00108  * Revision 1.12  1996/01/24 14:43:11  robertj
00109  * Added initialisers to string dictionaries.
00110  *
00111  * Revision 1.11  1996/01/23 13:11:12  robertj
00112  * Mac Metrowerks compiler support.
00113  *
00114  * Revision 1.10  1995/06/17 11:12:29  robertj
00115  * Documentation update.
00116  *
00117  * Revision 1.9  1995/06/04 08:45:57  robertj
00118  * Better C++ compatibility (with BC++)
00119  *
00120  * Revision 1.8  1995/03/14 12:41:19  robertj
00121  * Updated documentation to use HTML codes.
00122  *
00123  * Revision 1.7  1995/02/22  10:50:29  robertj
00124  * Changes required for compiling release (optimised) version.
00125  *
00126  * Revision 1.6  1995/02/11  04:10:35  robertj
00127  * Fixed dictionary MACRO for templates.
00128  *
00129  * Revision 1.5  1995/02/05  00:48:03  robertj
00130  * Fixed template version.
00131  *
00132  * Revision 1.4  1995/01/09  12:35:31  robertj
00133  * Removed unnecesary return value from I/O functions.
00134  * Changes due to Mac port.
00135  *
00136  * Revision 1.3  1994/12/21  11:52:51  robertj
00137  * Documentation and variable normalisation.
00138  *
00139  * Revision 1.2  1994/12/17  01:36:57  robertj
00140  * Fixed memory leak in PStringSet
00141  *
00142  * Revision 1.1  1994/12/12  09:59:32  robertj
00143  * Initial revision
00144  *
00145  */
00146 
00147 #ifdef P_USE_PRAGMA
00148 #pragma interface
00149 #endif
00150 
00151 
00153 // PDictionary classes
00154 
00158 class POrdinalKey : public PObject
00159 {
00160   PCLASSINFO(POrdinalKey, PObject);
00161 
00162   public:
00167     PINLINE POrdinalKey(
00168       PINDEX newKey = 0   
00169     );
00170 
00173     PINLINE POrdinalKey & operator=(PINDEX);
00175 
00178 
00179     virtual PObject * Clone() const;
00180 
00181     /* Get the relative rank of the ordinal index. This is a simpel comparison
00182        of the objects PINDEX values.
00183 
00184        @return
00185        comparison of the two objects, #EqualTo# for same,
00186        #LessThan# for #obj# logically less than the
00187        object and #GreaterThan# for #obj# logically
00188        greater than the object.
00189      */
00190     virtual Comparison Compare(const PObject & obj) const;
00191 
00198     virtual PINDEX HashFunction() const;
00199 
00206     virtual void PrintOn(ostream & strm) const;
00208 
00213     PINLINE operator PINDEX() const;
00214 
00217     PINLINE PINDEX operator++();
00218 
00221     PINLINE PINDEX operator++(int);
00222 
00225     PINLINE PINDEX operator--();
00226 
00229     PINLINE PINDEX operator--(int);
00230 
00233     PINLINE POrdinalKey & operator+=(PINDEX);
00234 
00237     PINLINE POrdinalKey & operator-=(PINDEX );
00239 
00240   private:
00241     PINDEX theKey;
00242 };
00243 
00244 
00246 
00257 class PHashTable : public PCollection
00258 {
00259   PCONTAINERINFO(PHashTable, PCollection);
00260 
00261   public:
00264 
00265     PHashTable();
00267 
00279     virtual Comparison Compare(
00280       const PObject & obj   
00281     ) const;
00283 
00284 
00285   protected:
00295     virtual BOOL SetSize(
00296       PINDEX newSize  
00297     );
00299 
00300 
00311     PINLINE BOOL AbstractContains(
00312       const PObject & key   
00313     ) const;
00314 
00329     virtual const PObject & AbstractGetKeyAt(
00330       PINDEX index  
00331     ) const;
00332 
00347     virtual PObject & AbstractGetDataAt(
00348       PINDEX index  
00349     ) const;
00351 
00352 
00353     // Member variables
00354     class Element {
00355       public:
00356         friend class Table;
00357         PObject * key;
00358         PObject * data;
00359         Element * next;
00360         Element * prev;
00361     };
00362 
00363     PDECLARE_BASEARRAY(Table, Element *)
00364 #ifdef DOC_PLUS_PLUS
00365     {
00366 #endif
00367       public:
00368         virtual ~Table() { Destruct(); }
00369         virtual void DestroyContents();
00370 
00371         PINDEX AppendElement(PObject * key, PObject * data);
00372         PObject * RemoveElement(const PObject & key);
00373         BOOL SetLastElementAt(PINDEX index);
00374         Element * GetElementAt(const PObject & key);
00375         PINDEX GetElementsIndex(const PObject*obj,BOOL byVal,BOOL keys) const;
00376 
00377         PINDEX    lastIndex;
00378         PINDEX    lastBucket;
00379         Element * lastElement;
00380 
00381         BOOL deleteKeys;
00382 
00383       friend class PHashTable;
00384       friend class PAbstractSet;
00385     };
00386     friend class Table;
00387 
00388 
00389     Table * hashTable;
00390 };
00391 
00392 
00394 
00397 class PAbstractSet : public PHashTable
00398 {
00399   PCONTAINERINFO(PAbstractSet, PHashTable);
00400   public:
00408     PINLINE PAbstractSet();
00410 
00421     virtual PINDEX Append(
00422       PObject * obj   
00423     );
00424 
00437     virtual PINDEX Insert(
00438       const PObject & before,   
00439       PObject * obj             
00440     );
00441 
00454     virtual PINDEX InsertAt(
00455       PINDEX index,   
00456       PObject * obj   
00457     );
00458 
00469     virtual BOOL Remove(
00470       const PObject * obj   
00471     );
00472 
00479     virtual PObject * RemoveAt(
00480       PINDEX index   
00481     );
00482 
00488     virtual PObject * GetAt(
00489       PINDEX index  
00490     ) const;
00491 
00504     virtual BOOL SetAt(
00505       PINDEX index,   
00506       PObject * val   
00507     );
00508 
00520     virtual PINDEX GetObjectsIndex(
00521       const PObject * obj   
00522     ) const;
00523 
00532     virtual PINDEX GetValuesIndex(
00533       const PObject & obj   
00534     ) const;
00536 };
00537 
00538 
00539 #ifdef PHAS_TEMPLATES
00540 
00551 template <class T> class PSet : public PAbstractSet
00552 {
00553   PCLASSINFO(PSet, PAbstractSet);
00554 
00555   public:
00565     inline PSet(BOOL initialDeleteObjects = FALSE)
00566       : PAbstractSet() { AllowDeleteObjects(initialDeleteObjects); }
00568 
00574     virtual PObject * Clone() const
00575       { return PNEW PSet(0, this); }
00577 
00589     void Include(
00590       const T * obj   // New object to include in the set.
00591     ) { Append((PObject *)obj); }
00592 
00600     PSet & operator+=(
00601       const T & obj   // New object to include in the set.
00602     ) { Append(obj.Clone()); return *this; }
00603 
00611     void Exclude(
00612       const T * obj   // New object to exclude in the set.
00613     ) { Remove(obj); }
00614 
00622     PSet & operator-=(
00623       const T & obj   // New object to exclude in the set.
00624     ) { RemoveAt(GetValuesIndex(obj)); return *this; }
00625 
00634     BOOL Contains(
00635       const T & key  
00636     ) const { return AbstractContains(key); }
00637 
00646     BOOL operator[](
00647       const T & key  
00648     ) const { return AbstractContains(key); }
00649 
00661     virtual const T & GetKeyAt(
00662       PINDEX index    
00663     ) const
00664       { return (const T &)AbstractGetKeyAt(index); }
00666 
00667 
00668   protected:
00669     PSet(int dummy, const PSet * c)
00670       : PAbstractSet(dummy, c)
00671       { reference->deleteObjects = c->reference->deleteObjects; }
00672 };
00673 
00674 
00686 #define PSET(cls, T) typedef PSet<T> cls
00687 
00688 
00700 #define PDECLARE_SET(cls, T, initDelObj) \
00701   PSET(cls##_PTemplate, T); \
00702   PDECLARE_CLASS(cls, cls##_PTemplate) \
00703   protected: \
00704     cls(int dummy, const cls * c) \
00705       : cls##_PTemplate(dummy, c) { } \
00706   public: \
00707     cls(BOOL initialDeleteObjects = initDelObj) \
00708       : cls##_PTemplate(initialDeleteObjects) { } \
00709     virtual PObject * Clone() const \
00710       { return PNEW cls(0, this); } \
00711 
00712 
00713 #else // PHAS_TEMPLATES
00714 
00715 
00716 #define PSET(cls, K) \
00717   class cls : public PAbstractSet { \
00718   PCLASSINFO(cls, PAbstractSet); \
00719   protected: \
00720     inline cls(int dummy, const cls * c) \
00721       : PAbstractSet(dummy, c) \
00722       { reference->deleteObjects = c->reference->deleteObjects; } \
00723   public: \
00724     inline cls(BOOL initialDeleteObjects = FALSE) \
00725       : PAbstractSet() { AllowDeleteObjects(initialDeleteObjects); } \
00726     virtual PObject * Clone() const \
00727       { return PNEW cls(0, this); } \
00728     inline void Include(const PObject * key) \
00729       { Append((PObject *)key); } \
00730     inline void Exclude(const PObject * key) \
00731       { Remove(key); } \
00732     inline BOOL operator[](const K & key) const \
00733         { return AbstractContains(key); } \
00734     inline BOOL Contains(const K & key) const \
00735         { return AbstractContains(key); } \
00736     virtual const K & GetKeyAt(PINDEX index) const \
00737       { return (const K &)AbstractGetKeyAt(index); } \
00738   }
00739 
00740 #define PDECLARE_SET(cls, K, initDelObj) \
00741  PSET(cls##_PTemplate, K); \
00742  PDECLARE_CLASS(cls, cls##_PTemplate) \
00743   protected: \
00744     inline cls(int dummy, const cls * c) \
00745       : cls##_PTemplate(dummy, c) { } \
00746   public: \
00747     inline cls(BOOL initialDeleteObjects = initDelObj) \
00748       : cls##_PTemplate() { AllowDeleteObjects(initialDeleteObjects); } \
00749     virtual PObject * Clone() const \
00750       { return PNEW cls(0, this); } \
00751 
00752 
00753 #endif  // PHAS_TEMPLATES
00754 
00755 
00756 PSET(POrdinalSet, POrdinalKey);
00757 
00758 
00760 
00763 class PAbstractDictionary : public PHashTable
00764 {
00765   PCLASSINFO(PAbstractDictionary, PHashTable);
00766   public:
00774     PINLINE PAbstractDictionary();
00776 
00785     virtual void PrintOn(
00786       ostream &strm   
00787     ) const;
00789 
00800     virtual PINDEX Insert(
00801       const PObject & key,   
00802       PObject * obj          
00803     );
00804 
00811     virtual PINDEX InsertAt(
00812       PINDEX index,   
00813       PObject * obj   
00814     );
00815 
00825     virtual PObject * RemoveAt(
00826       PINDEX index   
00827     );
00828 
00837     virtual BOOL SetAt(
00838       PINDEX index,   
00839       PObject * val   
00840     );
00841 
00849     virtual PObject * GetAt(
00850       PINDEX index  
00851     ) const;
00852 
00864     virtual PINDEX GetObjectsIndex(
00865       const PObject * obj  
00866     ) const;
00867 
00876     virtual PINDEX GetValuesIndex(
00877       const PObject & obj  
00878     ) const;
00880 
00881 
00892     virtual BOOL SetDataAt(
00893       PINDEX index,   
00894       PObject * obj   
00895     );
00896 
00908     virtual BOOL AbstractSetAt(
00909       const PObject & key,  
00910       PObject * obj         
00911     );
00912 
00922     virtual PObject & GetRefAt(
00923       const PObject & key   
00924     ) const;
00925 
00932     virtual PObject * AbstractGetAt(
00933       const PObject & key   
00934     ) const;
00936 
00937   protected:
00938     PINLINE PAbstractDictionary(int dummy, const PAbstractDictionary * c);
00939 
00940   private:
00941     virtual PINDEX Append(
00942       PObject * obj   // New object to place into the collection.
00943     );
00944     /* This function is meaningless and will assert.
00945 
00946        @return
00947        Always zero.
00948      */
00949 
00950     virtual BOOL Remove(
00951       const PObject * obj   // Existing object to remove from the collection.
00952     );
00953     /* Remove the object from the collection. If the AllowDeleteObjects option
00954        is set then the object is also deleted.
00955 
00956        Note that the comparison for searching for the object in collection is
00957        made by pointer, not by value. Thus the parameter must point to the
00958        same instance of the object that is in the collection.
00959 
00960        @return
00961        TRUE if the object was in the collection.
00962      */
00963 
00964 };
00965 
00966 
00967 #ifdef PHAS_TEMPLATES
00968 
00976 template <class K, class D> class PDictionary : public PAbstractDictionary
00977 {
00978   PCLASSINFO(PDictionary, PAbstractDictionary);
00979 
00980   public:
00989     PDictionary()
00990       : PAbstractDictionary() { }
00992 
00999     virtual PObject * Clone() const
01000       { return PNEW PDictionary(0, this); }
01002 
01015     D & operator[](
01016       const K & key   
01017     ) const
01018       { return (D &)GetRefAt(key); }
01019 
01028     BOOL Contains(
01029       const K & key   
01030     ) const { return AbstractContains(key); }
01031 
01043     virtual D * RemoveAt(
01044       const K & key   
01045     ) {
01046         D * obj = GetAt(key); AbstractSetAt(key, NULL); 
01047         return reference->deleteObjects ? (obj ? (D *)-1 : NULL) : obj;
01048       }
01049 
01061     virtual BOOL SetAt(
01062       const K & key,  // Key for position in dictionary to add object.
01063       D * obj         // New object to put into the dictionary.
01064     ) { return AbstractSetAt(key, obj); }
01065 
01072     virtual D * GetAt(
01073       const K & key   // Key for position in dictionary to get object.
01074     ) const { return (D *)AbstractGetAt(key); }
01075 
01087     const K & GetKeyAt(
01088       PINDEX index  
01089     ) const
01090       { return (const K &)AbstractGetKeyAt(index); }
01091 
01103     D & GetDataAt(
01104       PINDEX index  
01105     ) const
01106       { return (D &)AbstractGetDataAt(index); }
01108 
01109   protected:
01110     PDictionary(int dummy, const PDictionary * c)
01111       : PAbstractDictionary(dummy, c) { }
01112 };
01113 
01114 
01127 #define PDICTIONARY(cls, K, D) typedef PDictionary<K, D> cls
01128 
01129 
01142 #define PDECLARE_DICTIONARY(cls, K, D) \
01143   PDICTIONARY(cls##_PTemplate, K, D); \
01144   PDECLARE_CLASS(cls, cls##_PTemplate) \
01145   protected: \
01146     cls(int dummy, const cls * c) \
01147       : cls##_PTemplate(dummy, c) { } \
01148   public: \
01149     cls() \
01150       : cls##_PTemplate() { } \
01151     virtual PObject * Clone() const \
01152       { return PNEW cls(0, this); } \
01153 
01154 
01162 template <class K> class POrdinalDictionary : public PAbstractDictionary
01163 {
01164   PCLASSINFO(POrdinalDictionary, PAbstractDictionary);
01165 
01166   public:
01175     POrdinalDictionary()
01176       : PAbstractDictionary() { }
01178 
01185     virtual PObject * Clone() const
01186       { return PNEW POrdinalDictionary(0, this); }
01188 
01201     PINDEX operator[](
01202       const K & key   // Key to look for in the dictionary.
01203     ) const
01204       { return (POrdinalKey &)GetRefAt(key); }
01205 
01214     BOOL Contains(
01215       const K & key   
01216     ) const { return AbstractContains(key); }
01217 
01218     virtual POrdinalKey * GetAt(
01219       const K & key   
01220     ) const { return (POrdinalKey *)AbstractGetAt(key); }
01221     /* Get the object at the specified key position. If the key was not in the
01222        collection then NULL is returned.
01223 
01224        @return
01225        pointer to object at the specified key.
01226      */
01227 
01236     virtual BOOL SetDataAt(
01237       PINDEX index,   
01238       PINDEX ordinal  
01239       ) { return PAbstractDictionary::SetDataAt(index, PNEW POrdinalKey(ordinal)); }
01240 
01252     virtual BOOL SetAt(
01253       const K & key,  
01254       PINDEX ordinal  
01255     ) { return AbstractSetAt(key, PNEW POrdinalKey(ordinal)); }
01256 
01265     virtual PINDEX RemoveAt(
01266       const K & key   
01267     ) { PINDEX ord = *GetAt(key); AbstractSetAt(key, NULL); return ord; }
01268 
01280     const K & GetKeyAt(
01281       PINDEX index  
01282     ) const
01283       { return (const K &)AbstractGetKeyAt(index); }
01284 
01296     PINDEX GetDataAt(
01297       PINDEX index  
01298     ) const
01299       { return (POrdinalKey &)AbstractGetDataAt(index); }
01301 
01302   protected:
01303     POrdinalDictionary(int dummy, const POrdinalDictionary * c)
01304       : PAbstractDictionary(dummy, c) { }
01305 };
01306 
01307 
01320 #define PORDINAL_DICTIONARY(cls, K) typedef POrdinalDictionary<K> cls
01321 
01322 
01337 #define PDECLARE_ORDINAL_DICTIONARY(cls, K) \
01338   PORDINAL_DICTIONARY(cls##_PTemplate, K); \
01339   PDECLARE_CLASS(cls, POrdinalDictionary<K>) \
01340   protected: \
01341     cls(int dummy, const cls * c) \
01342       : cls##_PTemplate(dummy, c) { } \
01343   public: \
01344     cls() \
01345       : cls##_PTemplate() { } \
01346     virtual PObject * Clone() const \
01347       { return PNEW cls(0, this); } \
01348 
01349 
01350 #else // PHAS_TEMPLATES
01351 
01352 
01353 #define PDICTIONARY(cls, K, D) \
01354   class cls : public PAbstractDictionary { \
01355   PCLASSINFO(cls, PAbstractDictionary); \
01356   protected: \
01357     inline cls(int dummy, const cls * c) \
01358       : PAbstractDictionary(dummy, c) { } \
01359   public: \
01360     cls() \
01361       : PAbstractDictionary() { } \
01362     virtual PObject * Clone() const \
01363       { return PNEW cls(0, this); } \
01364     D & operator[](const K & key) const \
01365       { return (D &)GetRefAt(key); } \
01366     virtual BOOL Contains(const K & key) const \
01367       { return AbstractContains(key); } \
01368     virtual D * RemoveAt(const K & key) \
01369       { D * obj = GetAt(key); AbstractSetAt(key, NULL); return obj; } \
01370     virtual BOOL SetAt(const K & key, D * obj) \
01371       { return AbstractSetAt(key, obj); } \
01372     virtual D * GetAt(const K & key) const \
01373       { return (D *)AbstractGetAt(key); } \
01374     const K & GetKeyAt(PINDEX index) const \
01375       { return (const K &)AbstractGetKeyAt(index); } \
01376     D & GetDataAt(PINDEX index) const \
01377       { return (D &)AbstractGetDataAt(index); } \
01378   }
01379 
01380 #define PDECLARE_DICTIONARY(cls, K, D) \
01381   PDICTIONARY(cls##_PTemplate, K, D); \
01382   PDECLARE_CLASS(cls, cls##_PTemplate) \
01383   protected: \
01384     cls(int dummy, const cls * c) \
01385       : cls##_PTemplate(dummy, c) { } \
01386   public: \
01387     cls() \
01388       : cls##_PTemplate() { } \
01389     virtual PObject * Clone() const \
01390       { return PNEW cls(0, this); } \
01391 
01392 
01393 #define PORDINAL_DICTIONARY(cls, K) \
01394   class cls : public PAbstractDictionary { \
01395   PCLASSINFO(cls, PAbstractDictionary); \
01396   protected: \
01397     inline cls(int dummy, const cls * c) \
01398       : PAbstractDictionary(dummy, c) { } \
01399   public: \
01400     inline cls() \
01401       : PAbstractDictionary() { } \
01402     virtual PObject * Clone() const \
01403       { return PNEW cls(0, this); } \
01404     inline PINDEX operator[](const K & key) const \
01405       { return (POrdinalKey &)GetRefAt(key); } \
01406     virtual BOOL Contains(const K & key) const \
01407       { return AbstractContains(key); } \
01408     virtual POrdinalKey * GetAt(const K & key) const \
01409       { return (POrdinalKey *)AbstractGetAt(key); } \
01410     virtual BOOL SetDataAt(PINDEX index, PINDEX ordinal) \
01411       { return PAbstractDictionary::SetDataAt(index, PNEW POrdinalKey(ordinal)); } \
01412     virtual BOOL SetAt(const K & key, PINDEX ordinal) \
01413       { return AbstractSetAt(key, PNEW POrdinalKey(ordinal)); } \
01414     virtual PINDEX RemoveAt(const K & key) \
01415       { PINDEX ord = *GetAt(key); AbstractSetAt(key, NULL); return ord; } \
01416     inline const K & GetKeyAt(PINDEX index) const \
01417       { return (const K &)AbstractGetKeyAt(index); } \
01418     inline PINDEX GetDataAt(PINDEX index) const \
01419       { return (POrdinalKey &)AbstractGetDataAt(index); } \
01420   }
01421 
01422 #define PDECLARE_ORDINAL_DICTIONARY(cls, K) \
01423   PORDINAL_DICTIONARY(cls##_PTemplate, K); \
01424   PDECLARE_CLASS(cls, cls##_PTemplate) \
01425   protected: \
01426     cls(int dummy, const cls * c) \
01427       : cls##_PTemplate(dummy, c) { } \
01428   public: \
01429     cls() \
01430       : cls##_PTemplate() { } \
01431     virtual PObject * Clone() const \
01432       { return PNEW cls(0, this); } \
01433 
01434 
01435 #endif // PHAS_TEMPLATES
01436 
01437 // End Of File ///////////////////////////////////////////////////////////////

Generated on Wed Sep 28 10:27:33 2005 for PWLib by  doxygen 1.4.4