00001 //File: $Id$ 00002 // Author: John Wu <John.Wu at ACM.org> 00003 // Copyright 2000-2011 the Regents of the University of California 00004 #ifndef IBIS_DICTIONARY_H 00005 #define IBIS_DICTIONARY_H 00006 00007 00008 #include "util.h" 00009 #include "array_t.h" 00010 00014 class FASTBIT_CXX_DLLSPEC ibis::dictionary { 00015 public: 00016 ~dictionary() {clear();} 00017 dictionary(const dictionary& dic); 00019 dictionary() : raw_(1) {raw_[0] = 0;} 00020 00022 uint32_t size() const {return key_.size();} 00023 const char* operator[](uint32_t i) const; 00024 uint32_t operator[](const char* str) const; 00025 const char* find(const char* str) const; 00026 uint32_t insert(const char* str); 00027 uint32_t insertRaw(char* str); 00028 00029 void clear(); 00030 void swap(dictionary&); 00031 int read(const char* name); 00032 int write(const char* name) const; 00033 00034 protected: 00035 00038 array_t<const char*> raw_; 00040 array_t<const char*> key_; 00043 array_t<uint32_t> code_; 00046 array_t<char*> buffer_; 00047 00048 void copy(const dictionary& rhs); 00049 00050 int readRaw(const char*, FILE *); 00051 int readKeys(const char*, FILE *); 00052 00053 private: 00054 dictionary& operator=(const dictionary&); 00055 }; // ibis::dictionary 00056 00058 inline void ibis::dictionary::swap(ibis::dictionary& rhs) { 00059 raw_.swap(rhs.raw_); 00060 key_.swap(rhs.key_); 00061 code_.swap(rhs.code_); 00062 buffer_.swap(rhs.buffer_); 00063 } // ibis::dictionary::swap 00064 00068 inline const char* ibis::dictionary::operator[](uint32_t i) const { 00069 return (i < raw_.size() ? raw_[i] : raw_[0]); 00070 } // int to string 00071 00075 inline const char* ibis::dictionary::find(const char* str) const { 00076 const char* ret = 0; 00077 const uint32_t ind = operator[](str); 00078 if (ind < raw_.size()) 00079 ret = raw_[ind]; 00080 return ret; 00081 } // ibis::dictionary::find 00082 #endif // IBIS_DICTIONARY_H
![]() |