summaryrefslogtreecommitdiffstats
path: root/kicker/applets/launcher/easyvector.h
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit4aed2c8219774f5d797760606b8489a92ddc5163 (patch)
tree3f8c130f7d269626bf6a9447407ef6c35954426a /kicker/applets/launcher/easyvector.h
downloadtdebase-4aed2c8219774f5d797760606b8489a92ddc5163.tar.gz
tdebase-4aed2c8219774f5d797760606b8489a92ddc5163.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kicker/applets/launcher/easyvector.h')
-rw-r--r--kicker/applets/launcher/easyvector.h147
1 files changed, 147 insertions, 0 deletions
diff --git a/kicker/applets/launcher/easyvector.h b/kicker/applets/launcher/easyvector.h
new file mode 100644
index 000000000..cad9a2c86
--- /dev/null
+++ b/kicker/applets/launcher/easyvector.h
@@ -0,0 +1,147 @@
+/* Copyright 2004, Daniel Woods Bullok <dan.devel@bullok.com>
+ distributed under the terms of the
+ GNU GENERAL PUBLIC LICENSE Version 2 -
+ See the file kdebase/COPYING for details
+*/
+
+#ifndef __easyvector_h__
+#define __easyvector_h__
+#include <vector>
+#include <algorithm>
+#include <assert.h>
+
+template < class VALUE >
+class __Valtype {
+public:
+ typedef const VALUE& CVALUE;
+};
+
+
+template < class VALUE >
+class __Valtype< VALUE* > {
+public:
+ typedef const VALUE* CVALUE;
+};
+
+
+template <class VALUE, bool CHECKINDEX=true>
+class EasyVector: public std::vector< VALUE > {
+public:
+ typedef int Index;
+ typedef std::vector< Index > Indices;
+ typedef typename __Valtype< VALUE >::CVALUE CVALUE;
+
+ static const Index NotFound=-2;
+ static const Index Append=-1;
+
+ template < class PTYPE, class PROP_FUNC >
+ Index findProperty(const PTYPE &property,
+ PROP_FUNC prop_func) const;
+ Index findValue(CVALUE value) const;
+
+ Index lastIndex() const {return this->size()-1;}
+
+ void eraseAt(Index index);
+
+ VALUE takeFrom(Index index);
+
+ void insertAt(Index index,const VALUE &value);
+ void insertAt(Index index,const EasyVector &values);
+
+ bool isValidIndex(Index index) const;
+ bool isValidInsertIndex(Index index) const;
+ virtual ~EasyVector(){};
+
+
+protected:
+ void _checkInsertIndex(Index index) const;
+ void _checkIndex(Index index) const;
+ Index _convertInsertIndex(Index index) const;
+};
+
+
+template < class VALUE, bool CHECKINDEX >
+template < class PTYPE, class PROP_FUNC >
+typename EasyVector< VALUE, CHECKINDEX >::Index
+ EasyVector< VALUE, CHECKINDEX >::findProperty(const PTYPE &property,
+ PROP_FUNC prop_func) const
+{ typename EasyVector< VALUE, CHECKINDEX >::const_iterator i;
+ for (i=this->begin();i!=this->end();++i) {
+ if (prop_func(*i)==property)
+ return i-this->begin();
+ }
+ return NotFound;
+}
+
+
+template < class VALUE, bool CHECKINDEX >
+typename EasyVector< VALUE, CHECKINDEX >::Index
+ EasyVector< VALUE, CHECKINDEX >::findValue(CVALUE value) const
+{ typename EasyVector< VALUE, CHECKINDEX >::const_iterator i;
+ i=std::find(this->begin(),this->end(),value);
+ if (i==this->end()) return NotFound;
+ return i-this->begin();
+}
+
+
+template < class VALUE, bool CHECKINDEX >
+void EasyVector< VALUE, CHECKINDEX >::eraseAt(Index index)
+{ _checkIndex(index);
+ erase(this->begin()+index);
+}
+
+
+template < class VALUE, bool CHECKINDEX >
+VALUE EasyVector< VALUE, CHECKINDEX >::takeFrom(Index index)
+{ _checkIndex(index);
+ VALUE result=(*this)[index];
+ eraseAt(index);
+ return result;
+}
+
+
+template < class VALUE, bool CHECKINDEX >
+void EasyVector< VALUE, CHECKINDEX >::insertAt(EasyVector< VALUE, CHECKINDEX >::Index index,const VALUE &value)
+{ index=_convertInsertIndex(index);
+ _checkInsertIndex(index);
+ if (index==int(this->size())) {
+ this->push_back(value);
+ return;
+ }
+ insert(this->begin()+index,value);
+}
+
+
+template < class VALUE, bool CHECKINDEX >
+void EasyVector< VALUE, CHECKINDEX >::insertAt(EasyVector< VALUE, CHECKINDEX >::Index index,const EasyVector< VALUE, CHECKINDEX > &v)
+{ index=_convertInsertIndex(index);
+ _checkInsertIndex(index);
+ insert(this->begin()+index,v.begin(),v.end());
+}
+
+
+template < class VALUE, bool CHECKINDEX >
+bool EasyVector< VALUE, CHECKINDEX >::isValidIndex(EasyVector< VALUE, CHECKINDEX >::Index index) const
+{ return(0<=index && index<int(this->size()));}
+
+template < class VALUE, bool CHECKINDEX >
+bool EasyVector< VALUE, CHECKINDEX >::isValidInsertIndex(EasyVector< VALUE, CHECKINDEX >::Index index) const
+{ return(index==Append)||(0<=index && index<=int(this->size()));}
+
+template < class VALUE, bool CHECKINDEX >
+inline typename EasyVector< VALUE, CHECKINDEX >::Index EasyVector< VALUE, CHECKINDEX >::_convertInsertIndex(Index index) const
+{ if (index==Append) return this->size();
+ return index;
+}
+
+template < class VALUE, bool CHECKINDEX >
+void EasyVector< VALUE, CHECKINDEX >::_checkInsertIndex(Index index) const
+{ if (CHECKINDEX) assert (isValidInsertIndex(index));}
+
+template < class VALUE, bool CHECKINDEX >
+void EasyVector< VALUE, CHECKINDEX >::_checkIndex(Index index) const
+{ if (CHECKINDEX) assert (isValidIndex(index));}
+
+
+#endif
+