From 2fce43d484e4148ae858f410d51dcd9951d34374 Mon Sep 17 00:00:00 2001 From: Tuowen Zhao Date: Sun, 18 Sep 2016 15:45:13 +0000 Subject: remove include & rename --- omegalib/omega/include/basic/Map.h | 68 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 omegalib/omega/include/basic/Map.h (limited to 'omegalib/omega/include/basic/Map.h') diff --git a/omegalib/omega/include/basic/Map.h b/omegalib/omega/include/basic/Map.h new file mode 100644 index 0000000..f94a10c --- /dev/null +++ b/omegalib/omega/include/basic/Map.h @@ -0,0 +1,68 @@ +#if ! defined _Map_h +#define _Map_h 1 + +#include +#include // for NULL + +namespace omega { + +#define foreach_map(k,K,v,V,M,A) {for (omega::MapElementIterator __M_##k = (M).iterator();__M_##k;__M_##k++) {K & k = *__M_##k; V & v = __M_##k.value(); A;}} + +template class MapElement { +public: + K k; + V v; + MapElement *tail; + MapElement(const MapElement&); + MapElement() {} + MapElement & operator=(const MapElement&); + ~MapElement() { delete tail; } +}; + +template class MapElementIterator { +public: + MapElementIterator(MapElement* 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 *i; +}; + +template 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 iterator() + {return MapElementIterator(contents);} + int empty() const {return contents == NULL;} + V operator()(K) const; + V& operator[](K); +private: + MapElement * contents; + V _default_value; +}; + +} // namespace + +#if ! defined DONT_INCLUDE_TEMPLATE_CODE +#include +#endif + +#define instantiate_Map(T1,T2) template class Map; \ + template class MapElement; \ + template class MapElementIterator; +#define instantiate_MapElement(T1,T2) instantiate_Map(T1,T2) +#define instantiate_MapElementIterator(T1,T2) instantiate_Map(T1,T2) + +#endif -- cgit v1.2.3-70-g09d2