From d4b2f09f1c42d49e53c1b039cedc5b09ec8e87cd Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Fri, 23 Apr 2004 22:14:24 +0000 Subject: "" svn path=/trunk/; revision=1634 --- externals/grill/flext/source/flmap.h | 70 ++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 externals/grill/flext/source/flmap.h (limited to 'externals/grill/flext/source/flmap.h') diff --git a/externals/grill/flext/source/flmap.h b/externals/grill/flext/source/flmap.h new file mode 100644 index 00000000..b32b2652 --- /dev/null +++ b/externals/grill/flext/source/flmap.h @@ -0,0 +1,70 @@ +/* + +flext - C++ layer for Max/MSP and pd (pure data) externals + +Copyright (c) 2001-2004 Thomas Grill (xovo@gmx.net) +For information on usage and redistribution, and for a DISCLAIMER OF ALL +WARRANTIES, see the file, "license.txt," in this distribution. + +*/ + +/*! \file flmap.h + \brief special map class for all 32-bit key/value-pairs +*/ + +#ifndef __FLMAP_H +#define __FLMAP_H + +#include + +/*! \defgroup FLEXT_SUPPORT Flext support classes + @{ +*/ + +//! Base class for maps +class AnyMap: + public std::map +{ + typedef std::map Parent; +public: + AnyMap(); + ~AnyMap(); + iterator find(unsigned int k); + unsigned int &operator [](unsigned int k); + + typedef std::pair pair; +}; + +//! Specialized map class for any 32-bit key/value types +template +class DataMap: + public AnyMap +{ +public: + class iterator: + public AnyMap::iterator + { + public: + iterator() {} + iterator(AnyMap::iterator it): AnyMap::iterator(it) {} + + inline K &key() const { return *(K *)&((*this)->first); } + inline T &data() const { return *(T *)&((*this)->second); } + }; + + class pair: + public AnyMap::pair + { + public: + inline K &key() const { return *(K *)&first; } + inline T &data() const { return *(T *)&second; } + }; + + inline iterator find(K k) { return AnyMap::find(*(unsigned int *)&k); } + inline T &operator [](K k) { return *(T *)&(AnyMap::operator [](*(unsigned int *)&k)); } + inline void erase(K k) { AnyMap::erase(*(unsigned int *)&k); } +}; + +//! @} // FLEXT_SUPPORT + +#endif -- cgit v1.2.1