summaryrefslogtreecommitdiff
path: root/tools/listiter.h
diff options
context:
space:
mode:
Diffstat (limited to 'tools/listiter.h')
-rw-r--r--tools/listiter.h83
1 files changed, 83 insertions, 0 deletions
diff --git a/tools/listiter.h b/tools/listiter.h
new file mode 100644
index 00000000..9c88940e
--- /dev/null
+++ b/tools/listiter.h
@@ -0,0 +1,83 @@
+/*
+ * listiter.h:
+ *
+ * See the main source file 'xineliboutput.c' for copyright information and
+ * how to reach the author.
+ *
+ * $Id: listiter.h,v 1.1 2006-06-03 10:04:27 phintuka Exp $
+ *
+ */
+
+
+#ifndef _LISTITER_H_
+#define _LISTITER_H_
+
+//------------------------------ list ----------------------------------------
+
+template <class LIST,class ITEM, class RESULT>
+void ForEach(LIST& List, RESULT (ITEM::*f)())
+{
+ for(ITEM *it = List.First(); it; it = List.Next(it))
+ (*it.*f)();
+}
+
+template <class LIST,class ITEM, class ARG1, class RESULT>
+void ForEach(LIST& List, RESULT (ITEM::*f)(ARG1), ARG1 arg1)
+{
+ for(ITEM *it = List.First(); it; it = List.Next(it))
+ (*it.*f)(arg1);
+}
+
+template <class LIST,class ITEM, class ARG1, class ARG2>
+void ForEach(LIST& List, void (ITEM::*f)(ARG1,ARG2), ARG1 arg1, ARG2 arg2)
+{
+ for(ITEM *it = List.First(); it; it = List.Next(it))
+ (*it.*f)(arg1,arg2);
+}
+
+template <class LIST,class ITEM, class ARG1, class RESULT>
+RESULT ForEach(LIST& List, RESULT (ITEM::*f)(ARG1), ARG1 arg1,
+ RESULT (*combiner)(RESULT,RESULT), RESULT def)
+{
+ RESULT result = def;
+ for(ITEM *it = List.First(); it; it = List.Next(it))
+ result = (*combiner)((*it.*f)(arg1),result);
+ return result;
+}
+
+template <class LIST,class ITEM, class ARG1, class ARG2, class RESULT>
+RESULT ForEach(LIST& List, RESULT (ITEM::*f)(ARG1,ARG2),
+ ARG1 arg1, ARG2 arg2,
+ RESULT (*combiner)(RESULT,RESULT), RESULT def)
+{
+ RESULT result = def;
+ for(ITEM *it = List.First(); it; it = List.Next(it))
+ result = (*combiner)((*it.*f)(arg1,arg2),result);
+ return result;
+}
+
+template <class LIST,class ITEM, class ARG1, class ARG2, class ARG3,
+ class RESULT>
+RESULT ForEach(LIST& List, RESULT (ITEM::*f)(ARG1,ARG2,ARG3),
+ ARG1 arg1, ARG2 arg2, ARG3 arg3,
+ RESULT (*combiner)(RESULT,RESULT), RESULT def)
+{
+ RESULT result = def;
+ for(ITEM *it = List.First(); it; it = List.Next(it))
+ result = (*combiner)((*it.*f)(arg1,arg2,arg3),result);
+ return result;
+}
+
+template<class T>
+T mmin(T a, T b) {return a<b ? a : b;}
+
+template<class T>
+T mmax(T a, T b) {return a>b ? a : b;}
+
+template<class T>
+T mand(T a, T b) {return a&&b;}
+
+template<class T>
+T mor(T a, T b) {return a||b;}
+
+#endif