1 /* 2 This is dictionary.h 3 4 Coxeter version 3.0 Copyright (C) 2002 Fokko du Cloux 5 See file main.cpp for full copyright notice 6 */ 7 8 #ifndef DICTIONARY_H /* guard against multiple inclusions */ 9 #define DICTIONARY_H 10 11 #include "globals.h" 12 #include "memory.h" 13 #include "io.h" 14 15 namespace dictionary { 16 using namespace coxeter; 17 using namespace memory; 18 using namespace io; 19 20 /******** type declarations *************************************************/ 21 22 template <class T> class Dictionary; 23 template <class T> struct DictCell; 24 25 /******** function declarations *********************************************/ 26 27 template <class T> 28 void printExtensions(FILE* file, DictCell<T>* cell, String& name, 29 bool& first, const char* sep = ","); 30 31 /* class definitions */ 32 33 template <class T> 34 struct DictCell { 35 T *ptr; 36 DictCell *left; 37 DictCell *right; 38 char letter; 39 bool fullname; 40 bool uniquePrefix; 41 /* constructors and destructors */ newDictCell42 void* operator new(size_t size) {return arena().alloc(size);} deleteDictCell43 void operator delete(void* ptr) 44 {return arena().free(ptr,sizeof(DictCell));} DictCellDictCell45 DictCell() {/* not implemented */}; 46 DictCell(char c, T* v, bool f, bool u, DictCell *l = 0, DictCell *r = 0) ptrDictCell47 :ptr(v), left(l), right(r), letter(c), fullname(f), uniquePrefix(u) {}; 48 ~DictCell(); 49 /* accessors */ valueDictCell50 T* value() const {return ptr;} 51 }; 52 53 template <class T> 54 class Dictionary { 55 protected: 56 DictCell<T>* d_root; 57 public: 58 /* creators and destructors */ 59 Dictionary(); 60 virtual ~Dictionary(); 61 /* modifiers */ 62 void insert(const String& str, T* const value); 63 void remove(const String& str); 64 /* accessors */ 65 T* find(const String& str) const; 66 DictCell<T>* findCell(const String& str) const; root()67 DictCell<T>* root() {return d_root;} 68 }; 69 70 } 71 72 #include "dictionary.hpp" 73 74 #endif 75