Rudiments
/home/dmuse/src/rudiments/include/rudiments/private/dictionaryinlines.h
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         dict.clear();
00036 }
00037 
00038 DICTIONARY_TEMPLATE
00039 RUDIMENTS_TEMPLATE_INLINE
00040 void DICTIONARY_CLASS::setData(keytype key, datatype data) {
00041         dictionarylistnodetype  *node=findNode(key);
00042         if (node) {
00043                 node->getData()->setData(data);
00044         } else {
00045                 dictionarynodetype      *dictnode=new dictionarynodetype();
00046                 dictnode->setKey(key);
00047                 dictnode->setData(data);
00048                 dict.append(dictnode);
00049         }
00050 }
00051 
00052 DICTIONARY_TEMPLATE
00053 RUDIMENTS_TEMPLATE_INLINE
00054 bool DICTIONARY_CLASS::getData(keytype key, datatype *data) {
00055         dictionarylistnodetype  *node=findNode(key);
00056         if (node) {
00057                 *data=node->getData()->getData();
00058                 return true;
00059         }
00060         return false;
00061 }
00062 
00063 DICTIONARY_TEMPLATE
00064 RUDIMENTS_TEMPLATE_INLINE
00065 bool DICTIONARY_CLASS::removeData(keytype key) {
00066         dictionarylistnodetype  *node=findNode(key);
00067         if (node) {
00068                 return dict.removeNode(node);
00069         }
00070         return false;
00071 }
00072 
00073 DICTIONARY_TEMPLATE
00074 RUDIMENTS_TEMPLATE_INLINE
00075 dictionarylistnodetype *DICTIONARY_CLASS::findNode(keytype key) {
00076         for (dictionarylistnodetype *node=
00077                         (dictionarylistnodetype *)dict.getFirstNode();
00078                         node; node=(dictionarylistnodetype *)node->getNext()) {
00079                 if (!node->getData()->compare(key)) {
00080                         return node;
00081                 }
00082         }
00083         return NULL;
00084 }
00085 
00086 DICTIONARY_TEMPLATE
00087 RUDIMENTS_TEMPLATE_INLINE
00088 dictionarylisttype *DICTIONARY_CLASS::getList() {
00089         return &dict;
00090 }
00091 
00092 DICTIONARY_TEMPLATE
00093 RUDIMENTS_TEMPLATE_INLINE
00094 void DICTIONARY_CLASS::clear() {
00095         for (dictionarylistnodetype *node=
00096                         (dictionarylistnodetype *)dict.getFirstNode();
00097                         node; node=(dictionarylistnodetype *)node->getNext()) {
00098                 delete node->getData();
00099         }
00100         dict.clear();
00101 }
00102 
00103 DICTIONARY_TEMPLATE
00104 RUDIMENTS_TEMPLATE_INLINE
00105 void DICTIONARY_CLASS::print() {
00106         for (dictionarylistnodetype *node=
00107                         (dictionarylistnodetype *)dict.getFirstNode();
00108                         node; node=(dictionarylistnodetype *)node->getNext()) {
00109                 node->getData()->print();
00110                 printf("\n");
00111         }
00112 }
00113 
00114 
00115 
00116 template <class datatype>
00117 RUDIMENTS_TEMPLATE_INLINE
00118 stringdictionarynode<datatype>::~stringdictionarynode() {}
00119 
00120 template <class datatype>
00121 RUDIMENTS_TEMPLATE_INLINE
00122 stringdictionarylistnode<datatype>::~stringdictionarylistnode() {}
00123 
00124 template <class datatype>
00125 RUDIMENTS_TEMPLATE_INLINE
00126 stringdictionarylist<datatype>::~stringdictionarylist() {}
00127 
00128 template <class datatype>
00129 RUDIMENTS_TEMPLATE_INLINE
00130 stringdictionary<datatype>::~stringdictionary() {}
00131 
00132 
00133 
00134 template <class datatype>
00135 RUDIMENTS_TEMPLATE_INLINE
00136 conststringdictionarynode<datatype>::~conststringdictionarynode() {}
00137 
00138 template <class datatype>
00139 RUDIMENTS_TEMPLATE_INLINE
00140 conststringdictionarylistnode<datatype>::~conststringdictionarylistnode() {}
00141 
00142 template <class datatype>
00143 RUDIMENTS_TEMPLATE_INLINE
00144 conststringdictionarylist<datatype>::~conststringdictionarylist() {}
00145 
00146 template <class datatype>
00147 RUDIMENTS_TEMPLATE_INLINE
00148 conststringdictionary<datatype>::~conststringdictionary() {}
00149 
00150 
00151 
00152 template <class datatype>
00153 RUDIMENTS_TEMPLATE_INLINE
00154 numericdictionarynode<datatype>::~numericdictionarynode() {}
00155 
00156 template <class datatype>
00157 RUDIMENTS_TEMPLATE_INLINE
00158 numericdictionarylistnode<datatype>::~numericdictionarylistnode() {}
00159 
00160 template <class datatype>
00161 RUDIMENTS_TEMPLATE_INLINE
00162 numericdictionarylist<datatype>::~numericdictionarylist() {}
00163 
00164 template <class datatype>
00165 RUDIMENTS_TEMPLATE_INLINE
00166 numericdictionary<datatype>::~numericdictionary() {}
00167 
00168 #ifdef RUDIMENTS_NAMESPACE
00169 }
00170 #endif
00171 
00172 #endif