diff options
author | Tuowen Zhao <ztuowen@gmail.com> | 2016-09-19 21:14:58 +0000 |
---|---|---|
committer | Tuowen Zhao <ztuowen@gmail.com> | 2016-09-19 21:14:58 +0000 |
commit | 210f77d2c32f14d2e99577fd3c9842bb19d47e50 (patch) | |
tree | 5edb327c919b8309e301c3440fb6668a0075c8ef /omegalib/omega/include/basic/Map.h | |
parent | a66ce5cd670c4d3c0dc449720f5bc45dd4c281b8 (diff) | |
download | chill-210f77d2c32f14d2e99577fd3c9842bb19d47e50.tar.gz chill-210f77d2c32f14d2e99577fd3c9842bb19d47e50.tar.bz2 chill-210f77d2c32f14d2e99577fd3c9842bb19d47e50.zip |
Moved most modules into lib
Diffstat (limited to 'omegalib/omega/include/basic/Map.h')
-rw-r--r-- | omegalib/omega/include/basic/Map.h | 127 |
1 files changed, 0 insertions, 127 deletions
diff --git a/omegalib/omega/include/basic/Map.h b/omegalib/omega/include/basic/Map.h deleted file mode 100644 index 25a116d..0000000 --- a/omegalib/omega/include/basic/Map.h +++ /dev/null @@ -1,127 +0,0 @@ -#if ! defined _Map_h -#define _Map_h 1 - -#include <basic/Link.h> -#include <stdio.h> // for NULL - -namespace omega { - -#define foreach_map(k,K,v,V,M,A) {for (omega::MapElementIterator<K,V> __M_##k = (M).iterator();__M_##k;__M_##k++) {K & k = *__M_##k; V & v = __M_##k.value(); A;}} - -template <class K, class V> class MapElement { -public: - K k; - V v; - MapElement<K,V> *tail; - MapElement(const MapElement<K,V>&); - MapElement() {} - MapElement & operator=(const MapElement<K,V>&); - ~MapElement() { delete tail; } -}; - -template<class K, class V> class MapElementIterator { -public: - MapElementIterator(MapElement<K,V>* j) { i = j;} - virtual const K & operator*() const { return i->k; } - virtual K & operator*() { return i->k;} - virtual const V & value() const { return i->v; } - virtual V & value() { return i->v; } - virtual void operator++(int) { i = i->tail; } - virtual void operator++() { i = i->tail; } - virtual bool live() const { return i != NULL; } - operator bool() const { return live(); } -protected: -MapElement<K,V> *i; -}; - -template <class K, class V> class Map { -public: -#if ! defined linux - Map(const V &default_value); -#else - // work around for '386 g++ on Linux - Map(V default_value); -#endif - ~Map(); - MapElementIterator<K,V> iterator() - {return MapElementIterator<K,V>(contents);} - int empty() const {return contents == NULL;} - V operator()(K) const; - V& operator[](K); -private: - MapElement<K,V> * contents; - V _default_value; -}; - -} // namespace - -#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 |