aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-24 06:37:49 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-24 06:37:49 +0000
commit9ed3a2a493ff4cb21e63d085bad908d994fbef3d (patch)
treedd3dc9676e2b9ce83e6f093cd8f258ff3ba2368d
parent440320262bbf63701a9fbe9b5dab51a91fd0078d (diff)
downloadpaludis-9ed3a2a493ff4cb21e63d085bad908d994fbef3d.tar.gz
paludis-9ed3a2a493ff4cb21e63d085bad908d994fbef3d.tar.xz
Don't use < followed by > or < twice for types that have a .compare function.
-rw-r--r--paludis/compare.cc4
-rw-r--r--paludis/compare.hh66
-rw-r--r--paludis/files.m41
-rw-r--r--paludis/smart_record.hh.m421
4 files changed, 86 insertions, 6 deletions
diff --git a/paludis/compare.cc b/paludis/compare.cc
new file mode 100644
index 0000000..53b2d12
--- /dev/null
+++ b/paludis/compare.cc
@@ -0,0 +1,4 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+#include "compare.hh"
+
diff --git a/paludis/compare.hh b/paludis/compare.hh
new file mode 100644
index 0000000..57ad38d
--- /dev/null
+++ b/paludis/compare.hh
@@ -0,0 +1,66 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+#ifndef PALUDIS_GUARD_PALUDIS_COMPARE_HH
+#define PALUDIS_GUARD_PALUDIS_COMPARE_HH 1
+
+#include <paludis/attributes.hh>
+#include <paludis/validated.hh>
+#include <string>
+
+namespace paludis
+{
+ inline int compare(int t1, int t2) PALUDIS_ATTRIBUTE((always_inline));
+
+ inline int compare(int t1, int t2)
+ {
+ if (t1 < t2)
+ return -1;
+ else if (t2 > t1)
+ return 1;
+ else
+ return 0;
+ }
+
+ template <typename T_>
+ inline int compare(
+ const std::basic_string<T_> & t1,
+ const std::basic_string<T_> & t2)
+ PALUDIS_ATTRIBUTE((always_inline));
+
+ template <typename T_>
+ inline int compare(
+ const std::basic_string<T_> & t1,
+ const std::basic_string<T_> & t2)
+ {
+ register int r(t1.compare(t2));
+ if (r < 0)
+ return -1;
+ else if (r > 0)
+ return 1;
+ else
+ return 0;
+ }
+
+ template <typename T_, typename U_>
+ inline int compare(
+ const Validated<T_, U_> & t1,
+ const Validated<T_, U_> & t2)
+ {
+ return compare(t1.data(), t2.data());
+ }
+
+ template <typename T_>
+ int compare(
+ const T_ & t1,
+ const T_ & t2)
+ {
+ if (t1 < t2)
+ return -1;
+ else if (t1 > t2)
+ return 1;
+ else
+ return 0;
+ }
+}
+
+#endif
diff --git a/paludis/files.m4 b/paludis/files.m4
index f9a11bb..8f706bb 100644
--- a/paludis/files.m4
+++ b/paludis/files.m4
@@ -14,6 +14,7 @@ add(`any_dep_atom', `hh', `cc')
add(`attributes', `hh', `cc')
add(`block_dep_atom', `hh', `cc')
add(`category_name_part', `hh', `cc', `test')
+add(`compare', `hh', `cc')
add(`comparison_policy', `hh', `cc', `test')
add(`composite_dep_atom', `hh', `cc')
add(`composite_pattern', `hh', `cc')
diff --git a/paludis/smart_record.hh.m4 b/paludis/smart_record.hh.m4
index 2c2df41..4ebb1c6 100644
--- a/paludis/smart_record.hh.m4
+++ b/paludis/smart_record.hh.m4
@@ -29,6 +29,8 @@ define(`_forloop', `$4`'ifelse($1, `$3', , `define(`$1', incr($1))_forloop(`$1',
#define PALUDIS_GUARD_PALUDIS_SMART_RECORD_HH 1
#include <paludis/comparison_policy.hh>
+#include <paludis/compare.hh>
+#include <paludis/exception.hh>
namespace paludis
{
@@ -518,12 +520,19 @@ forloop(`idx', `1', max_record_size, `
const RecordBase<Tag_, `'idx`'> * const b)
{
forloop(`idy', `0', decr(`'idx`'), `
- if (RecordKeyGetter<Tag_, `'idx`', `'idy`'>::do_get(*a) <
- RecordKeyGetter<Tag_, `'idx`', `'idy`'>::do_get(*b))
- return -1;
- if (RecordKeyGetter<Tag_, `'idx`', `'idy`'>::do_get(*a) >
- RecordKeyGetter<Tag_, `'idx`', `'idy`'>::do_get(*b))
- return 1;
+ switch (compare(
+ RecordKeyGetter<Tag_, `'idx`', `'idy`'>::do_get(*a),
+ RecordKeyGetter<Tag_, `'idx`', `'idy`'>::do_get(*b)))
+ {
+ case -1:
+ return -1;
+ case 1:
+ return 1;
+ case 0:
+ break;
+ default:
+ throw InternalError(PALUDIS_HERE, "Bad value from compare");
+ }
')
return 0;
}