FXDict.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                  S t r i n g   D i c t i o n a r y    C l a s s               *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1998,2006 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or                 *
00009 * modify it under the terms of the GNU Lesser General Public                    *
00010 * License as published by the Free Software Foundation; either                  *
00011 * version 2.1 of the License, or (at your option) any later version.            *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             *
00016 * Lesser General Public License for more details.                               *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public              *
00019 * License along with this library; if not, write to the Free Software           *
00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
00021 *********************************************************************************
00022 * $Id: FXDict.h,v 1.26 2006/01/22 17:58:00 fox Exp $                            *
00023 ********************************************************************************/
00024 #ifndef FXDICT_H
00025 #define FXDICT_H
00026 
00027 #ifndef FXOBJECT_H
00028 #include "FXObject.h"
00029 #endif
00030 
00031 namespace FX {
00032 
00033 
00041 class FXAPI FXDict : public FXObject {
00042   FXDECLARE(FXDict)
00043 protected:
00044   struct FXDictEntry {
00045     FXchar *key;              // Key string
00046     void   *data;             // Data
00047     FXint   hash;             // Hash value of key
00048     bool    mark;             // Entry is marked
00049     };
00050 protected:
00051   FXDictEntry *dict;          // Dictionary
00052   FXint        total;         // Dictionary size
00053   FXint        number;        // Number of entries
00054 protected:
00055   static FXint hash(const FXchar* str);
00056 protected:
00057 
00063   virtual void *createData(const void*);
00064 
00070   virtual void deleteData(void*);
00071 public:
00072 
00076   FXDict();
00077 
00079   FXDict(const FXDict& orig);
00080 
00082   FXDict& operator=(const FXDict& orig);
00083 
00087   void size(FXint m);
00088 
00092   FXint size() const { return total; }
00093 
00097   FXint no() const { return number; }
00098 
00104   void* insert(const FXchar* ky,const void* ptr,bool mrk=false);
00105 
00111   void* replace(const FXchar* ky,const void* ptr,bool mrk=false);
00112 
00116   void* remove(const FXchar* ky);
00117 
00121   void* find(const FXchar* ky) const;
00122 
00126   bool empty(FXint pos) const { return dict[pos].hash<0; }
00127 
00131   const FXchar* key(FXuint pos) const { return dict[pos].key; }
00132 
00136   void* data(FXuint pos) const { return dict[pos].data; }
00137 
00141   bool mark(FXuint pos) const { return dict[pos].mark; }
00142 
00146   FXint first() const;
00147 
00151   FXint last() const;
00152 
00153 
00159   FXint next(FXint pos) const;
00160 
00165   FXint prev(FXint pos) const;
00166 
00168   void clear();
00169 
00171   virtual ~FXDict();
00172   };
00173 
00174 }
00175 
00176 #endif

(C) 2002-2009 Niall Douglas. Some parts (C) to assorted authors.
Generated on Fri Nov 20 18:31:20 2009 for TnFOX by doxygen v1.4.7