[gnome-commander] Added tuple.h, a small utility for 'triple' class



commit 7dbb6add6a8d1d19379c69c96091b156a289f0f3
Author: Piotr Eljasiak <epiotr src gnome org>
Date:   Thu Jul 1 20:03:28 2010 +0200

    Added tuple.h, a small utility for 'triple' class

 src/Makefile.am |    1 +
 src/tuple.h     |   81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index d3c5276..ee87e81 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -90,6 +90,7 @@ gnome_commander_SOURCES = \
 	main.cc \
 	owner.h owner.cc \
 	plugin_manager.h plugin_manager.cc \
+	tuple.h \
 	utils.h utils.cc \
 	widget-factory.h
 
diff --git a/src/tuple.h b/src/tuple.h
new file mode 100755
index 0000000..6f081bb
--- /dev/null
+++ b/src/tuple.h
@@ -0,0 +1,81 @@
+/*
+    GNOME Commander - A GNOME based file manager
+    Copyright (C) 2001-2006 Marcus Bjurman
+    Copyright (C) 2007-2010 Piotr Eljasiak
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+#ifndef __TUPLE_H__
+#define __TUPLE_H__
+
+#include <utility>
+
+template <typename T1, typename T2, typename T3>
+struct triple: public std::pair<T1,T2>
+{
+    typedef T3 third_type;
+
+    T3 third;
+
+    triple(): third(T3()) {}
+    triple(const T1 &t1, const T2 &t2, const T3 &t3): std::pair<T1,T2>(t1,t2), third(t3) {}
+    template<typename U1, typename U2, typename U3> triple(const triple<U1,U2,U3> &t): std::pair<U1,U2>(t.first,t.second), third(third) {}
+};
+
+template <typename T1, typename T2, typename T3>
+inline bool operator == (const triple<T1,T2,T3> &x, const triple<T1,T2,T3> &y)
+{
+    return x.first == y.first && x.second == y.second && x.third == y.third;
+}
+
+template <typename T1, typename T2, typename T3>
+inline bool operator < (const triple<T1,T2,T3> &x, const triple<T1,T2,T3> &y)
+{
+    return x.first < y.first ||
+            !(y.first < x.first) && (x.second < y.second || !(y.second < x.second) && x.third < y.third);
+}
+
+template <typename T1, typename T2, typename T3>
+inline bool operator != (const triple<T1,T2,T3> &x, const triple<T1,T2,T3> &y)
+{
+    return !(x == y);
+}
+
+template <typename T1, typename T2, typename T3>
+inline bool operator > (const triple<T1,T2,T3> &x, const triple<T1,T2,T3> &y)
+{
+    return y < x;
+}
+
+template <typename T1, typename T2, typename T3>
+inline bool operator <=(const triple<T1,T2,T3> &x, const triple<T1,T2,T3> &y)
+{
+    return !(y < x);
+}
+
+template <typename T1, typename T2, typename T3>
+inline bool operator >= (const triple<T1,T2,T3> &x, const triple<T1,T2,T3> &y)
+{
+    return !(x < y);
+}
+
+template <typename T1, typename T2, typename T3>
+inline triple<T1,T2,T3> make_triple(const T1 &t1, const T2 &t2, const T3 &t3)
+{
+    return triple<T1,T2,T3>(t1,t2,t3);
+}
+
+#endif // __TUPLE_H__



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]