Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

/home/jeroen/FOX/fox/fox-1.7.33/include/FXDict.h
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,2012 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or modify          *
00009 * it under the terms of the GNU Lesser General Public License as published by   *
00010 * the Free Software Foundation; either version 3 of the License, or             *
00011 * (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                 *
00016 * GNU Lesser General Public License for more details.                           *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public License      *
00019 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
00020 ********************************************************************************/
00021 #ifndef FXDICT_H
00022 #define FXDICT_H
00023 
00024 #ifndef FXOBJECT_H
00025 #include "FXObject.h"
00026 #endif
00027 
00028 namespace FX {
00029 
00030 
00038 class FXAPI FXDict : public FXObject {
00039   FXDECLARE(FXDict)
00040 protected:
00041   struct Entry {
00042     FXchar *key;                // Key string
00043     void   *data;               // Data
00044     FXint   hash;               // Hash value of key
00045     FXbool  mark;               // Entry is marked
00046     };
00047 protected:
00048   FXArray<Entry> table;         // Hash table
00049   FXint          used;          // Used entries
00050   FXint          free;          // Free entries
00051 protected:
00052   static const Entry init;      // Initialization value
00053 protected:
00054   static FXint hash(const FXchar* str);
00055 private:
00056   FXDict(const FXDict&);
00057   FXDict &operator=(const FXDict&);
00058 protected:
00059 
00065   virtual void *createData(void*);
00066 
00072   virtual void deleteData(void*);
00073 public:
00074 
00078   FXDict();
00079 
00083   FXbool size(FXint m);
00084 
00088   FXint size() const { return table.no(); }
00089 
00093   FXint no() const { return used; }
00094 
00100   void* insert(const FXchar* ky,void* ptr=NULL,FXbool mrk=false);
00101 
00107   void* replace(const FXchar* ky,void* ptr=NULL,FXbool mrk=false);
00108 
00112   void* remove(const FXchar* ky);
00113 
00117   void* find(const FXchar* ky) const;
00118 
00122   FXbool empty(FXint pos) const { return !table[pos].key; }
00123 
00127   const FXchar* key(FXint pos) const { return table[pos].key; }
00128 
00132   void* data(FXint pos) const { return table[pos].data; }
00133 
00137   FXbool mark(FXint pos) const { return table[pos].mark; }
00138 
00142   FXint first() const;
00143 
00147   FXint last() const;
00148 
00149 
00155   FXint next(FXint pos) const;
00156 
00161   FXint prev(FXint pos) const;
00162 
00164   void clear();
00165 
00167   virtual ~FXDict();
00168   };
00169 
00170 }
00171 
00172 #endif

Copyright © 1997-2011 Jeroen van der Zijp