aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2008-01-22 01:25:28 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2008-01-22 01:25:28 +0000
commit8ed98c406675c8ff01381633c4e41ade4c96360e (patch)
tree29c617d3002c68fc6cf9850e08470c2a47e27de2
parent8c3decbad616902b8ffbf7d3a8cda8cbf8cbf8f8 (diff)
downloadpaludis-8ed98c406675c8ff01381633c4e41ade4c96360e.tar.gz
paludis-8ed98c406675c8ff01381633c4e41ade4c96360e.tar.xz
Sort keywords by name first, then by stable/testing/etc.
-rw-r--r--paludis/name-fwd.hh3
-rw-r--r--paludis/name.cc20
-rw-r--r--paludis/name.hh6
-rw-r--r--paludis/util/validated-fwd.hh9
-rw-r--r--paludis/util/validated.hh39
-rw-r--r--python/iterable.hh4
-rw-r--r--python/validated.hh26
7 files changed, 72 insertions, 35 deletions
diff --git a/paludis/name-fwd.hh b/paludis/name-fwd.hh
index 448067d..b94ca10 100644
--- a/paludis/name-fwd.hh
+++ b/paludis/name-fwd.hh
@@ -165,13 +165,14 @@ namespace paludis
class KeywordNameValidator;
class KeywordNameError;
+ class KeywordNameComparator;
/**
* A KeywordName holds a std::string that is a valid name for a KEYWORD.
*
* \ingroup g_names
*/
- typedef Validated<std::string, KeywordNameValidator> KeywordName;
+ typedef Validated<std::string, KeywordNameValidator, true, KeywordNameComparator> KeywordName;
/**
* Holds a collection of KeywordName instances.
diff --git a/paludis/name.cc b/paludis/name.cc
index 7ae69b3..453102d 100644
--- a/paludis/name.cc
+++ b/paludis/name.cc
@@ -320,6 +320,26 @@ KeywordNameValidator::validate(const std::string & s)
throw KeywordNameError(s);
}
+bool
+KeywordNameComparator::operator() (const std::string & a, const std::string & b) const
+{
+ char a_prefix('~' == a[0] || '-' == a[0] ? a[0] : '\0');
+ char b_prefix('~' == b[0] || '-' == b[0] ? b[0] : '\0');
+ const std::string & a_keyword(a_prefix ? a.substr(1) : a);
+ const std::string & b_keyword(b_prefix ? b.substr(1) : b);
+
+ if (a_keyword == b_keyword)
+ {
+ if ('\0' == a_prefix && '\0' != b_prefix)
+ return true;
+ if ('~' == a_prefix && '-' == b_prefix)
+ return true;
+ return false;
+ }
+ else
+ return a_keyword < b_keyword;
+}
+
namespace
{
CategoryNamePart
diff --git a/paludis/name.hh b/paludis/name.hh
index f2682bc..e76fa3e 100644
--- a/paludis/name.hh
+++ b/paludis/name.hh
@@ -298,6 +298,12 @@ namespace paludis
KeywordNameError(const std::string & name) throw ();
};
+ class PALUDIS_VISIBLE KeywordNameComparator
+ {
+ public:
+ bool operator() (const std::string &, const std::string &) const;
+ };
+
/**
* A SetNameValidator handles validation rules for the value of a
* SetName.
diff --git a/paludis/util/validated-fwd.hh b/paludis/util/validated-fwd.hh
index 8431bdd..bd71a53 100644
--- a/paludis/util/validated-fwd.hh
+++ b/paludis/util/validated-fwd.hh
@@ -30,12 +30,15 @@
namespace paludis
{
- template <typename, typename, bool = true>
+ template <typename T_>
+ struct DefaultValidatedComparator;
+
+ template <typename D_, typename, bool = true, typename = DefaultValidatedComparator<D_> >
class Validated;
- template <typename D_, typename V_, bool c_>
+ template <typename D_, typename V_, bool c_, typename C_>
std::ostream &
- operator<< (std::ostream & s, const Validated<D_, V_, c_> & v);
+ operator<< (std::ostream & s, const Validated<D_, V_, c_, C_> & v);
}
#endif
diff --git a/paludis/util/validated.hh b/paludis/util/validated.hh
index 39a492d..a691314 100644
--- a/paludis/util/validated.hh
+++ b/paludis/util/validated.hh
@@ -21,6 +21,7 @@
#define PALUDIS_GUARD_PALUDIS_VALIDATED_HH 1
#include <iosfwd>
+#include <functional>
#include <paludis/util/validated-fwd.hh>
#include <paludis/util/operators.hh>
#include <paludis/util/sr.hh>
@@ -38,13 +39,19 @@
namespace paludis
{
+ template <typename T_>
+ struct PALUDIS_VISIBLE DefaultValidatedComparator :
+ std::less<T_>
+ {
+ };
+
/**
* A Validated wraps a particular class instance, ensuring that it always
* meets certain validation criteria.
*
* \ingroup g_data_structures
*/
- template <typename ValidatedDataType_, typename Validator_, bool full_comparison_>
+ template <typename ValidatedDataType_, typename Validator_, bool full_comparison_, typename Comparator_>
class Validated :
public Select<full_comparison_,
relational_operators::HasRelationalOperators,
@@ -60,7 +67,7 @@ namespace paludis
/**
* Copy constructor (no validation needed).
*/
- Validated(const Validated<ValidatedDataType_, Validator_, full_comparison_> & other);
+ Validated(const Validated<ValidatedDataType_, Validator_, full_comparison_, Comparator_> & other);
/**
* Constructor (validation needed).
@@ -89,35 +96,35 @@ namespace paludis
}
};
- template <typename ValidatedDataType_, typename Validator_, bool full_comparison_>
- Validated<ValidatedDataType_, Validator_, full_comparison_>::Validated(
- const Validated<ValidatedDataType_, Validator_, full_comparison_> & other) :
+ template <typename ValidatedDataType_, typename Validator_, bool full_comparison_, typename Comparator_>
+ Validated<ValidatedDataType_, Validator_, full_comparison_, Comparator_>::Validated(
+ const Validated<ValidatedDataType_, Validator_, full_comparison_, Comparator_> & other) :
_value(other._value)
{
}
- template <typename ValidatedDataType_, typename Validator_, bool full_comparison_>
- Validated<ValidatedDataType_, Validator_, full_comparison_>::Validated(
+ template <typename ValidatedDataType_, typename Validator_, bool full_comparison_, typename Comparator_>
+ Validated<ValidatedDataType_, Validator_, full_comparison_, Comparator_>::Validated(
const ValidatedDataType_ & value) :
_value(value)
{
Validator_::validate(_value);
}
- template <typename ValidatedDataType_, typename Validator_, bool full_comparison_>
+ template <typename ValidatedDataType_, typename Validator_, bool full_comparison_, typename Comparator_>
bool operator== (
- const Validated<ValidatedDataType_, Validator_, full_comparison_> & a,
- const Validated<ValidatedDataType_, Validator_, full_comparison_> & b)
+ const Validated<ValidatedDataType_, Validator_, full_comparison_, Comparator_> & a,
+ const Validated<ValidatedDataType_, Validator_, full_comparison_, Comparator_> & b)
{
return a.data() == b.data();
}
- template <typename ValidatedDataType_, typename Validator_>
+ template <typename ValidatedDataType_, typename Validator_, typename Comparator_>
bool operator< (
- const Validated<ValidatedDataType_, Validator_, true> & a,
- const Validated<ValidatedDataType_, Validator_, true> & b)
+ const Validated<ValidatedDataType_, Validator_, true, Comparator_> & a,
+ const Validated<ValidatedDataType_, Validator_, true, Comparator_> & b)
{
- return a.data() < b.data();
+ return Comparator_()(a.data(), b.data());
}
/**
@@ -125,9 +132,9 @@ namespace paludis
*
* \ingroup g_data_structures
*/
- template <typename D_, typename V_, bool c_>
+ template <typename D_, typename V_, bool c_, typename C_>
std::ostream &
- operator<< (std::ostream & s, const Validated<D_, V_, c_> & v)
+ operator<< (std::ostream & s, const Validated<D_, V_, c_, C_> & v)
{
s << v.data();
return s;
diff --git a/python/iterable.hh b/python/iterable.hh
index ced4fe3..6a2dc53 100644
--- a/python/iterable.hh
+++ b/python/iterable.hh
@@ -38,8 +38,8 @@ namespace paludis
static const bool value = tr1::is_convertible<From_, To_>::value;
};
- template <typename From_, typename ValidatedDataType_, typename Validator_, bool full_comparison_>
- struct IsConvertible<From_, Validated<ValidatedDataType_, Validator_, full_comparison_> >
+ template <typename From_, typename ValidatedDataType_, typename Validator_, bool full_comparison_, typename Comparator_>
+ struct IsConvertible<From_, Validated<ValidatedDataType_, Validator_, full_comparison_, Comparator_> >
{
static const bool value = tr1::is_convertible<From_, ValidatedDataType_>::value;
};
diff --git a/python/validated.hh b/python/validated.hh
index 452a6b4..f4a02ba 100644
--- a/python/validated.hh
+++ b/python/validated.hh
@@ -32,45 +32,45 @@ namespace paludis
template <typename V_>
class class_validated;
- template <typename ValidatedDataType_, typename Validator_>
- class class_validated<Validated<ValidatedDataType_, Validator_, true> > :
- public boost::python::class_<Validated<ValidatedDataType_, Validator_, true> >
+ template <typename ValidatedDataType_, typename Validator_, typename Comparator_>
+ class class_validated<Validated<ValidatedDataType_, Validator_, true, Comparator_> > :
+ public boost::python::class_<Validated<ValidatedDataType_, Validator_, true, Comparator_> >
{
public:
class_validated(const std::string & name,
const std::string & class_doc, const std::string & init_arg="string") :
- boost::python::class_<Validated<ValidatedDataType_, Validator_, true> >(
+ boost::python::class_<Validated<ValidatedDataType_, Validator_, true, Comparator_> >(
name.c_str(), class_doc.c_str(),
boost::python::init<const ValidatedDataType_ &>(("__init__("+init_arg+")").c_str())
)
{
this->def(boost::python::self_ns::str(boost::python::self));
this->def("__cmp__",
- &paludis::python::py_cmp<Validated<ValidatedDataType_, Validator_, true> >);
+ &paludis::python::py_cmp<Validated<ValidatedDataType_, Validator_, true, Comparator_> >);
boost::python::implicitly_convertible<ValidatedDataType_,
- Validated<ValidatedDataType_, Validator_, true> >();
+ Validated<ValidatedDataType_, Validator_, true, Comparator_> >();
}
};
- template <typename ValidatedDataType_, typename Validator_>
- class class_validated<Validated<ValidatedDataType_, Validator_, false> > :
- public boost::python::class_<Validated<ValidatedDataType_, Validator_, false> >
+ template <typename ValidatedDataType_, typename Validator_, typename Comparator_>
+ class class_validated<Validated<ValidatedDataType_, Validator_, false, Comparator_> > :
+ public boost::python::class_<Validated<ValidatedDataType_, Validator_, false, Comparator_> >
{
public:
class_validated(const std::string & name,
const std::string & class_doc, const std::string & init_arg="string") :
- boost::python::class_<Validated<ValidatedDataType_, Validator_, false> >(
+ boost::python::class_<Validated<ValidatedDataType_, Validator_, false, Comparator_> >(
name.c_str(), class_doc.c_str(),
boost::python::init<const ValidatedDataType_ &>(("__init__("+init_arg+")").c_str())
)
{
this->def(boost::python::self_ns::str(boost::python::self));
this->def("__eq__",
- &paludis::python::py_eq<Validated<ValidatedDataType_, Validator_, false> >);
+ &paludis::python::py_eq<Validated<ValidatedDataType_, Validator_, false, Comparator_> >);
this->def("__ne__",
- &paludis::python::py_ne<Validated<ValidatedDataType_, Validator_, false> >);
+ &paludis::python::py_ne<Validated<ValidatedDataType_, Validator_, false, Comparator_> >);
boost::python::implicitly_convertible<ValidatedDataType_,
- Validated<ValidatedDataType_, Validator_, false> >();
+ Validated<ValidatedDataType_, Validator_, false, Comparator_> >();
}
};