aboutsummaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-05-18 20:10:31 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-05-18 20:10:31 +0000
commit71c030417c39bbc42f4677eb025aa0b122289b6b (patch)
tree46932d7770f3a5dfbad1f022675e63165fa79226 /misc
parentcef92c0ae2d47d9e34b08e2c7981f71e0d5bdf18 (diff)
downloadpaludis-71c030417c39bbc42f4677eb025aa0b122289b6b.tar.gz
paludis-71c030417c39bbc42f4677eb025aa0b122289b6b.tar.xz
Change how we specify operators
Diffstat (limited to 'misc')
-rwxr-xr-xmisc/make_sr.bash85
1 files changed, 49 insertions, 36 deletions
diff --git a/misc/make_sr.bash b/misc/make_sr.bash
index 9614095..a8853bc 100755
--- a/misc/make_sr.bash
+++ b/misc/make_sr.bash
@@ -170,8 +170,25 @@ while read a ; do
echo -n "class PALUDIS_VISIBLE ${a}"
fi
- if [[ 0 != "${#want_inherit[@]}" ]] ; then
+ if [[ 0 != "${#want_inherit[@]}" ]] || [[ -n "${want_comparison_operators}" ]] ; then
echo " :"
+ if [[ -n "${want_comparison_operators}" ]] ; then
+ if [[ "${want_comparison_operators}" == "all" ]] ; then
+ echo -n " public paludis::relational_operators::HasRelationalOperators"
+ elif [[ "${want_comparison_operators}" == "equality" ]] ; then
+ echo -n " public paludis::equality_operators::HasEqualityOperators"
+ else
+ echo "bad first parameter for comparison_operators" 1>&2
+ exit 1
+ fi
+
+ if [[ 0 == ${#want_inherit[@]} ]] ; then
+ echo
+ else
+ echo ","
+ fi
+ fi
+
for (( k = 0 ; k < ${#want_inherit[@]} ; k++ )) ; do
echo -n " ${want_inherit[${k}]}"
if [[ ${k} == $(( ${#want_inherit[@]} - 1 )) ]] ; then
@@ -235,20 +252,15 @@ while read a ; do
echo
if [[ "${want_comparison_operators}" == "all" ]] ; then
- want_comparison_operators=( "==" "!=" "<" ">" "<=" ">=" )
- echo " int compare (const ${a} & other) const;"
+ echo " bool operator== (const ${a} & other) const;"
+ echo " bool operator< (const ${a} & other) const;"
elif [[ "${want_comparison_operators}" == "equality" ]] ; then
- want_comparison_operators=( "==" "!=" )
+ echo " bool operator== (const ${a} & other) const;"
else
echo "bad first parameter for comparison_operators" 1>&2
exit 1
fi
- for (( k = 0 ; k < ${#want_comparison_operators[@]} ; k++ )) ; do
- echo " bool operator${want_comparison_operators[${k}]} (const ${a} & other) const"
- echo " PALUDIS_ATTRIBUTE((warn_unused_result));"
- done
-
echo
echo " ///\\}"
echo
@@ -522,47 +534,48 @@ while read a ; do
if [[ -n "${want_comparison_operators}" ]] ; then
if [[ "${want_comparison_operators}" == "all" ]] ; then
- want_comparison_operators=( "==" "!=" "<" ">" "<=" ">=" )
- echo "int"
- echo "${a}::compare(const ${a} & other) const"
+ echo "bool"
+ echo "${a}::operator== (const ${a} & other) const"
echo "{"
for (( k = 0 ; k < ${#want_comparison_fields[@]} ; k++ )) ; do
- w=${want_comparison_fields[${k}]}
- echo " switch (paludis::compare(${w}, ${w//[^\*]}other.${w#\*}))"
- echo " {"
- echo " case -1:"
- echo " return -1;"
- echo " case 1:"
- echo " return 1;"
- echo " }"
- echo
+ w="${want_comparison_fields[${k}]}"
+ s=${w//[^*]}
+ w=${w#\*}
+ echo " if (${want_comparison_fields[${k}]} != ${s}other.${w})"
+ echo " return false;"
done
- echo " return 0;"
+ echo " return true;"
echo "}"
echo
- for (( k = 0 ; k < ${#want_comparison_operators[@]} ; k++ )) ; do
- echo "bool"
- echo "${a}::operator${want_comparison_operators[${k}]} (const ${a} & other) const"
- echo "{"
- echo " return compare(other) ${want_comparison_operators[${k}]} 0;"
- echo "}"
- echo
- done
- elif [[ "${want_comparison_operators}" == "equality" ]] ; then
echo "bool"
- echo "${a}::operator== (const ${a} & other) const"
+ echo "${a}::operator< (const ${a} & other) const"
echo "{"
+ echo " using namespace std::rel_ops;"
+ echo
for (( k = 0 ; k < ${#want_comparison_fields[@]} ; k++ )) ; do
- echo " if (${want_comparison_fields[${k}]} != other.${want_comparison_fields[${k}]})"
+ w="${want_comparison_fields[${k}]}"
+ s=${w//[^*]}
+ w=${w#\*}
+ echo " if (${want_comparison_fields[${k}]} < ${s}other.${w})"
+ echo " return true;"
+ echo " if (${want_comparison_fields[${k}]} > ${s}other.${w})"
echo " return false;"
done
- echo " return true;"
+ echo " return false;"
echo "}"
echo
+ elif [[ "${want_comparison_operators}" == "equality" ]] ; then
echo "bool"
- echo "${a}::operator!= (const ${a} & other) const"
+ echo "${a}::operator== (const ${a} & other) const"
echo "{"
- echo " return ! operator== (other);"
+ for (( k = 0 ; k < ${#want_comparison_fields[@]} ; k++ )) ; do
+ w="${want_comparison_fields[${k}]}"
+ s=${w//[^*]}
+ w=${w#\*}
+ echo " if (${want_comparison_fields[${k}]} != ${s}other.${w})"
+ echo " return false;"
+ done
+ echo " return true;"
echo "}"
echo
else