aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/flext/source/flmap.h
diff options
context:
space:
mode:
authorThomas Grill <xovo@users.sourceforge.net>2005-03-15 04:56:36 +0000
committerThomas Grill <xovo@users.sourceforge.net>2005-03-15 04:56:36 +0000
commit31a2d9dcc2b3a519033918e180f81c4e7b9f8e7e (patch)
tree7eae5d3f1e302843147fdc6bc13c99e101906d32 /externals/grill/flext/source/flmap.h
parent3e0446e7fda10c3d85a628b8c1effaa5bf7f5529 (diff)
new data type flext::AtomListStatic using pre-allocated space if possible
fixes for OSX replaced memory-intensive STL maps by custom-made vector/map-container fix for gcc strangeness no more static assignment of symbols (problems with Metrowerks) small fix for gcc fixed bugs in SIMD code for non-power-of-2 lengths fixes for attribute editor (to deal with large dialogs) svn path=/trunk/; revision=2628
Diffstat (limited to 'externals/grill/flext/source/flmap.h')
-rw-r--r--externals/grill/flext/source/flmap.h154
1 files changed, 152 insertions, 2 deletions
diff --git a/externals/grill/flext/source/flmap.h b/externals/grill/flext/source/flmap.h
index 980c2c99..8ad3a864 100644
--- a/externals/grill/flext/source/flmap.h
+++ b/externals/grill/flext/source/flmap.h
@@ -15,12 +15,14 @@ WARRANTIES, see the file, "license.txt," in this distribution.
#ifndef __FLMAP_H
#define __FLMAP_H
-#include <map>
-
/*! \defgroup FLEXT_SUPPORT Flext support classes
@{
*/
+#if 0
+
+#include <map>
+
//! Key/Value type for AnyMap... must have size of pointer!
typedef size_t AnyMapType;
@@ -74,6 +76,154 @@ public:
inline void erase(K k) { AnyMap::erase(*(AnyMapType *)&k); }
};
+#endif
+
+class TableAnyMap
+{
+protected:
+ virtual TableAnyMap *New(TableAnyMap *parent) = 0;
+ virtual void Free(void *ptr) = 0;
+
+ struct Data {
+ void operator()(size_t k,void *v) { key = k,value = v; }
+ void operator =(void *v) { value = v; }
+
+ size_t key;
+ void *value;
+ };
+
+ TableAnyMap(TableAnyMap *p,int mx,Data *dt,bool o)
+ : owned(o),max(mx),data(dt)
+ , n(0),parent(p),left(NULL),right(NULL)
+ {}
+
+ virtual ~TableAnyMap() { clear(); }
+
+ int size() const;
+
+ inline void insert(size_t k,void *t)
+ {
+ FLEXT_ASSERT(t);
+ if(n) _set(k,t);
+ else data[n++](k,t);
+ }
+
+ inline void *find(size_t k) { return n?_find(k):NULL; }
+
+ void clear();
+
+ inline void _toleft(size_t k,void *t)
+ {
+ if(left)
+ left->_set(k,t);
+ else {
+ left = New(this);
+ left->data[0](k,t);
+ left->n = 1;
+ }
+ }
+
+ inline void _toright(size_t k,void *t)
+ {
+ if(right)
+ right->_set(k,t);
+ else {
+ right = New(this);
+ right->data[0](k,t);
+ right->n = 1;
+ }
+ }
+
+ inline void _toleft(Data &v) { _toleft(v.key,v.value); }
+ inline void _toright(Data &v) { _toright(v.key,v.value); }
+
+ void _set(size_t k,void *t);
+ void *_find(size_t k);
+
+ Data *const data;
+ const int max;
+ const bool owned;
+ int n;
+ TableAnyMap *parent,*left,*right;
+
+
+ class iterator
+ {
+ public:
+ inline iterator(): map(NULL) {}
+ inline iterator(TableAnyMap &m): map(&m),ix(0) { leftmost(); }
+ inline iterator(iterator &it): map(it.map),ix(it.ix) {}
+
+ iterator &operator =(const iterator &it) { map = it.map,ix = it.ix; return *this; }
+
+ operator bool() const { return map && /*ix >= 0 &&*/ ix < map->n; }
+
+ // no checking here!
+ void *data() const { return map->data[ix].value; }
+ size_t key() const { return map->data[ix].key; }
+
+ iterator &operator ++() { forward(); return *this; }
+
+ protected:
+ void leftmost()
+ {
+ // search smallest branch (go left as far as possible)
+ TableAnyMap *nmap;
+ while((nmap = map->left) != NULL) map = nmap;
+ }
+
+ void forward();
+
+ TableAnyMap *map;
+ int ix;
+ };
+};
+
+
+template <typename K,typename T,int N = 8,bool O = false>
+class TableMap
+ : TableAnyMap
+{
+public:
+ TableMap(): TableAnyMap(NULL,N,slots,O) {}
+ virtual ~TableMap() { clear(); }
+
+ inline void clear() { TableAnyMap::clear(); }
+
+ inline int size() const { return TableAnyMap::size(); }
+
+ inline void insert(K k,T *t) { TableAnyMap::insert(*(size_t *)&k,t); }
+
+ inline T *find(K k) { return (T *)TableAnyMap::find(*(size_t *)&k); }
+
+ class iterator
+ : TableAnyMap::iterator
+ {
+ public:
+ inline iterator() {}
+ inline iterator(TableMap &m): TableAnyMap::iterator(m) {}
+ inline iterator(iterator &it): TableAnyMap::iterator(it) {}
+
+ inline iterator &operator =(const iterator &it) { TableAnyMap::operator =(it); return *this; }
+
+ inline operator bool() const {return TableAnyMap::iterator::operator bool(); }
+ inline T *data() const { return (T *)TableAnyMap::iterator::data(); }
+ inline K key() const { return (K)TableAnyMap::iterator::key(); }
+
+ inline iterator &operator ++() { TableAnyMap::iterator::operator ++(); return *this; }
+
+ };
+
+protected:
+ inline TableMap(TableAnyMap *p): TableAnyMap(p,N,slots,O) {}
+
+ virtual TableAnyMap *New(TableAnyMap *parent) { return new TableMap(parent); }
+ virtual void Free(void *ptr) { delete (T *)ptr; }
+
+ Data slots[N];
+};
+
+
//! @} // FLEXT_SUPPORT
#endif