00001 #ifndef DICTIONARY_HH_ 00002 # define DICTIONARY_HH_ 00003 00004 # include <map> 00005 # include <string> 00006 00007 namespace dictionary 00008 { 00009 template<typename Content> 00010 struct DictionaryNode 00011 { 00012 DictionaryNode(); 00013 00014 Content *_content; 00015 std::map<int, DictionaryNode<Content> *> _sub_nodes; 00016 }; 00017 00018 template<typename Content> 00019 class Dictionary 00020 { 00021 public: 00022 Dictionary(); 00023 ~Dictionary(); 00024 00025 void clear(); 00026 void put_word(const std::string &s, Content *c); 00027 Content *find(const std::string &s); 00028 Content *find_shortest(const std::string &s, std::string *res = NULL); 00029 Content *find_longest(const std::string &s, std::string *res = NULL); 00030 00031 protected: 00032 DictionaryNode<Content> _root; 00033 00034 // Navigation. 00035 int _depth; 00036 DictionaryNode<Content> *_current_node; 00037 int _best_depth; 00038 DictionaryNode<Content> *_best_node; 00039 std::string::const_iterator _current_iterator; 00040 std::string::const_iterator _end_iterator; 00041 00042 // Recursive functions. 00043 void put_word_rec(); 00044 void find_rec(); 00045 void find_shortest_rec(); 00046 void find_longest_rec(); 00047 void clear_rec(DictionaryNode<Content> &node); 00048 }; 00049 } 00050 00051 # include "dictionary.hxx" 00052 00053 #endif