diff options
Diffstat (limited to 'omegalib/omega/include/basic/Map.h')
-rw-r--r-- | omegalib/omega/include/basic/Map.h | 67 |
1 files changed, 63 insertions, 4 deletions
diff --git a/omegalib/omega/include/basic/Map.h b/omegalib/omega/include/basic/Map.h index f94a10c..25a116d 100644 --- a/omegalib/omega/include/basic/Map.h +++ b/omegalib/omega/include/basic/Map.h @@ -55,14 +55,73 @@ private: } // namespace -#if ! defined DONT_INCLUDE_TEMPLATE_CODE -#include <basic/Map.c> -#endif - #define instantiate_Map(T1,T2) template class Map<T1,T2>; \ template class MapElement<T1,T2>; \ template class MapElementIterator<T1,T2>; #define instantiate_MapElement(T1,T2) instantiate_Map(T1,T2) #define instantiate_MapElementIterator(T1,T2) instantiate_Map(T1,T2) +namespace omega { + +template<class K, class V> MapElement<K,V>:: MapElement(const MapElement<K,V>& M) { + if (M.tail) tail = new MapElement<K,V>(*M.tail); + else tail = 0; + k = M.k; + v = M.v; + } + +template<class K, class V> MapElement<K,V> & + MapElement<K,V>:: operator=(const MapElement<K,V>& M) { + if (this != &M) { + if (tail) delete tail; + if (M.tail) tail = new MapElement<K,V>(*M.tail); + else tail = 0; + k = M.k; + v = M.v; + } + return *this; + } + + + + +#if ! defined linux +template <class K, class V> Map <K,V>::Map(const V &default_value) +#else +template <class K, class V> Map <K,V>::Map(V default_value) +#endif + : _default_value(default_value) + { + contents = 0; + } + +template <class K, class V> Map <K,V>::~Map() + { + delete contents; + } + +template <class K, class V> V Map<K,V>::operator()(K k) const { + MapElement <K,V> * P = contents; + while (P) { + if (P->k == k) return P->v; + P = P->tail; + }; + return _default_value; + } + +template <class K, class V> V & Map<K,V>::operator[](K k) { + MapElement <K,V> * P = contents; + while (P) { + if (P->k == k) return P->v; + P = P->tail; + }; + P = new MapElement <K,V>; + P->k = k; + P->v = _default_value; + P->tail = contents; + contents = P; + return P->v; + } + +} // namespace #endif |