Rudiments
|
00001 // Copyright (c) 2003 David Muse 00002 // See the COPYING file for more information 00003 00004 #ifndef EXCLUDE_RUDIMENTS_TEMPLATE_IMPLEMENTATIONS 00005 00006 #ifdef RUDIMENTS_HAVE_STDLIB_H 00007 #include <stdlib.h> 00008 #endif 00009 #include <stdio.h> 00010 00011 #include <rudiments/private/rudimentsinlines.h> 00012 00013 #ifdef RUDIMENTS_NAMESPACE 00014 namespace rudiments { 00015 #endif 00016 00017 #define DICTIONARY_TEMPLATE \ 00018 template <class keytype, class datatype, \ 00019 class dictionarynodetype, \ 00020 class dictionarylistnodetype, \ 00021 class dictionarylisttype> 00022 00023 #define DICTIONARY_CLASS \ 00024 dictionary<keytype,datatype,dictionarynodetype,\ 00025 dictionarylistnodetype,dictionarylisttype> 00026 00027 DICTIONARY_TEMPLATE 00028 RUDIMENTS_TEMPLATE_INLINE 00029 DICTIONARY_CLASS::dictionary() { 00030 } 00031 00032 DICTIONARY_TEMPLATE 00033 RUDIMENTS_TEMPLATE_INLINE 00034 DICTIONARY_CLASS::~dictionary() { 00035 for (dictionarylistnodetype *node= 00036 (dictionarylistnodetype *)dict.getFirstNode(); 00037 node; node=(dictionarylistnodetype *)node->getNext()) { 00038 delete node->getData(); 00039 } 00040 } 00041 00042 DICTIONARY_TEMPLATE 00043 RUDIMENTS_TEMPLATE_INLINE 00044 void DICTIONARY_CLASS::setData(keytype key, datatype data) { 00045 dictionarylistnodetype *node=findNode(key); 00046 if (node) { 00047 node->getData()->setData(data); 00048 } else { 00049 dictionarynodetype *dictnode=new dictionarynodetype(); 00050 dictnode->setKey(key); 00051 dictnode->setData(data); 00052 dict.append(dictnode); 00053 } 00054 } 00055 00056 DICTIONARY_TEMPLATE 00057 RUDIMENTS_TEMPLATE_INLINE 00058 bool DICTIONARY_CLASS::getData(keytype key, datatype *data) { 00059 dictionarylistnodetype *node=findNode(key); 00060 if (node) { 00061 *data=node->getData()->getData(); 00062 return true; 00063 } 00064 return false; 00065 } 00066 00067 DICTIONARY_TEMPLATE 00068 RUDIMENTS_TEMPLATE_INLINE 00069 bool DICTIONARY_CLASS::removeData(keytype key) { 00070 dictionarylistnodetype *node=findNode(key); 00071 if (node) { 00072 return dict.removeNode(node); 00073 } 00074 return false; 00075 } 00076 00077 DICTIONARY_TEMPLATE 00078 RUDIMENTS_TEMPLATE_INLINE 00079 dictionarylistnodetype *DICTIONARY_CLASS::findNode(keytype key) { 00080 for (dictionarylistnodetype *node= 00081 (dictionarylistnodetype *)dict.getFirstNode(); 00082 node; node=(dictionarylistnodetype *)node->getNext()) { 00083 if (!node->getData()->compare(key)) { 00084 return node; 00085 } 00086 } 00087 return NULL; 00088 } 00089 00090 DICTIONARY_TEMPLATE 00091 RUDIMENTS_TEMPLATE_INLINE 00092 dictionarylisttype *DICTIONARY_CLASS::getList() { 00093 return &dict; 00094 } 00095 00096 DICTIONARY_TEMPLATE 00097 RUDIMENTS_TEMPLATE_INLINE 00098 void DICTIONARY_CLASS::clear() { 00099 dict.clear(); 00100 } 00101 00102 DICTIONARY_TEMPLATE 00103 RUDIMENTS_TEMPLATE_INLINE 00104 void DICTIONARY_CLASS::print() { 00105 for (dictionarylistnodetype *node= 00106 (dictionarylistnodetype *)dict.getFirstNode(); 00107 node; node=(dictionarylistnodetype *)node->getNext()) { 00108 node->getData()->print(); 00109 printf("\n"); 00110 } 00111 } 00112 00113 00114 00115 template <class datatype> 00116 RUDIMENTS_TEMPLATE_INLINE 00117 stringdictionarynode<datatype>::~stringdictionarynode() {} 00118 00119 template <class datatype> 00120 RUDIMENTS_TEMPLATE_INLINE 00121 stringdictionarylistnode<datatype>::~stringdictionarylistnode() {} 00122 00123 template <class datatype> 00124 RUDIMENTS_TEMPLATE_INLINE 00125 stringdictionarylist<datatype>::~stringdictionarylist() {} 00126 00127 template <class datatype> 00128 RUDIMENTS_TEMPLATE_INLINE 00129 stringdictionary<datatype>::~stringdictionary() {} 00130 00131 00132 00133 template <class datatype> 00134 RUDIMENTS_TEMPLATE_INLINE 00135 conststringdictionarynode<datatype>::~conststringdictionarynode() {} 00136 00137 template <class datatype> 00138 RUDIMENTS_TEMPLATE_INLINE 00139 conststringdictionarylistnode<datatype>::~conststringdictionarylistnode() {} 00140 00141 template <class datatype> 00142 RUDIMENTS_TEMPLATE_INLINE 00143 conststringdictionarylist<datatype>::~conststringdictionarylist() {} 00144 00145 template <class datatype> 00146 RUDIMENTS_TEMPLATE_INLINE 00147 conststringdictionary<datatype>::~conststringdictionary() {} 00148 00149 00150 00151 template <class datatype> 00152 RUDIMENTS_TEMPLATE_INLINE 00153 numericdictionarynode<datatype>::~numericdictionarynode() {} 00154 00155 template <class datatype> 00156 RUDIMENTS_TEMPLATE_INLINE 00157 numericdictionarylistnode<datatype>::~numericdictionarylistnode() {} 00158 00159 template <class datatype> 00160 RUDIMENTS_TEMPLATE_INLINE 00161 numericdictionarylist<datatype>::~numericdictionarylist() {} 00162 00163 template <class datatype> 00164 RUDIMENTS_TEMPLATE_INLINE 00165 numericdictionary<datatype>::~numericdictionary() {} 00166 00167 #ifdef RUDIMENTS_NAMESPACE 00168 } 00169 #endif 00170 00171 #endif