aboutsummaryrefslogtreecommitdiff
path: root/0.8.0/misc/make_sr.bash
diff options
context:
space:
mode:
Diffstat (limited to '0.8.0/misc/make_sr.bash')
-rwxr-xr-x0.8.0/misc/make_sr.bash559
1 files changed, 559 insertions, 0 deletions
diff --git a/0.8.0/misc/make_sr.bash b/0.8.0/misc/make_sr.bash
new file mode 100755
index 0000000..be98244
--- /dev/null
+++ b/0.8.0/misc/make_sr.bash
@@ -0,0 +1,559 @@
+#!/bin/bash
+# vim: set sw=4 sts=4 et tw=0 :
+
+echo -n "/* vim"
+echo ": set ro : */"
+echo
+echo "/* ******************************************************** */"
+echo "/* THIS IS A GENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY */"
+echo "/* ******************************************************** */"
+echo
+
+what_to_make=${1}
+shift
+
+for src in ${@} ; do
+ if ! source ${src} ; then
+ echo "source ${src} failed" 1>&2
+ exit 7
+ fi
+done
+
+make_const_ref()
+{
+ local x=${@}
+ if [[ "${x%\*}" != "${x}" ]] ; then
+ echo "${@}" const
+ elif [[ "${1#const}" != "${1}" ]] ; then
+ echo "${@}" const "&"
+ else
+ echo const "${@}" "&"
+ fi
+}
+
+set | grep '^make_class_.*() $' | sort -r | \
+while read a ; do
+ a=${a##make_class_}
+ a=${a%% *}
+
+ want_named_args=
+ want_visible=
+ want_keys=( )
+ want_key_types=( )
+ want_comparison_operators=
+ want_comparison_fields=( )
+
+ extra_constructors()
+ {
+ :
+ }
+
+ extra_methods()
+ {
+ :
+ }
+
+ allow_named_args()
+ {
+ want_named_args=yes
+ }
+
+ visible()
+ {
+ want_visible=yes
+ }
+
+ doxygen_comment()
+ {
+ :
+ }
+
+ key()
+ {
+ want_keys=( "${want_keys[@]}" "$1" )
+ want_key_types=( "${want_key_types[@]}" "$2" )
+ }
+
+ comparison_operators()
+ {
+ want_comparison_operators=$1
+ shift
+ want_comparison_fields=( $@ )
+ }
+
+ make_class_${a}
+
+ if [[ "${want_comparison_fields[0]}" == "all" ]] ; then
+ want_comparison_fields=( ${want_keys[@]} )
+ fi
+
+ doxygen_comment()
+ {
+ cat
+ }
+
+ allow_named_args()
+ {
+ :
+ }
+
+ key()
+ {
+ :
+ }
+
+ comparison_operators()
+ {
+ :
+ }
+
+
+ make_class_${a}
+
+ doxygen_comment()
+ {
+ :
+ }
+
+
+ extra_constructors()
+ {
+ echo
+ cat
+ }
+
+ extra_methods()
+ {
+ echo
+ cat
+ }
+
+ if [[ "${what_to_make}" == "--header" ]] ; then
+ if [[ -z ${want_visible} ]] ; then
+ echo "class ${a}"
+ else
+ echo "class PALUDIS_VISIBLE ${a}"
+ fi
+ echo "{"
+ echo " public:"
+ echo
+ echo " ///\\name Data members"
+ echo " ///\\{"
+ echo
+
+ for (( k = 0 ; k < ${#want_keys[@]} ; k++ )) ; do
+ echo " ${want_key_types[${k}]} ${want_keys[${k}]};"
+ done
+
+ echo
+ echo " ///\\}"
+ echo
+
+ if [[ -n "${want_comparison_operators}" ]] ; then
+
+ echo " ///\\name Comparison operators"
+ echo " ///\\{"
+ echo
+
+ if [[ "${want_comparison_operators}" == "all" ]] ; then
+ want_comparison_operators=( "==" "!=" "<" ">" "<=" ">=" )
+ echo " int compare (const ${a} & other) const;"
+ elif [[ "${want_comparison_operators}" == "equality" ]] ; then
+ want_comparison_operators=( "==" "!=" )
+ 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;"
+ done
+
+ echo
+ echo " ///\\}"
+ echo
+ fi
+
+ echo " ///\\name Basic operations"
+ echo " ///\\{"
+ echo
+
+ echo " ${a}("
+ for (( k = 0 ; k < ${#want_keys[@]} ; k++ )) ; do
+ echo -n " $(make_const_ref "${want_key_types[${k}]}") value_for_${want_keys[${k}]}"
+ if [[ $(( ${k} + 1 )) -lt ${#want_keys[@]} ]] ; then
+ echo ","
+ else
+ echo
+ fi
+ done
+ echo " );"
+ echo
+ echo " ${a}(const ${a} & other);"
+ echo
+ echo " const ${a} & operator= (const ${a} & other);"
+ echo
+ echo " ~${a}();"
+
+ make_class_${a}
+
+ echo
+ echo " ///\\}"
+ echo
+
+ if [[ -n "${want_named_args}" ]] ; then
+
+ echo " ///\\name Named argument constructor"
+ echo " ///\\{"
+ echo
+
+ for (( k = 0 ; k < ${#want_keys[@]} ; k++ )) ; do
+ n=${want_keys[${k}]}
+ t=${want_key_types[${k}]}
+ echo " /**"
+ echo " * Holds the named parameter construction value for ${a}.${n}"
+ echo " */"
+ echo " class Param_${n}"
+ echo " {"
+ echo " private:"
+ echo " Param_${n}();"
+ echo
+ echo " public:"
+ echo " /// The value"
+ echo " $(make_const_ref "${t}" ) ${n};"
+ echo
+ echo " ///\\name Basic operations"
+ echo " ///\\{"
+ echo
+ echo " Param_${n}(const Empty &, $(make_const_ref "${t}" ) value_for_${n}) :"
+ echo " ${n}(value_for_${n})"
+ echo " {"
+ echo " }"
+ echo
+ echo " /// Constructor"
+ echo " Param_${n}(const Empty &, const Param_${n} & other) :"
+ echo " ${n}(other.${n})"
+ echo " {"
+ echo " }"
+ echo
+ echo " ///\\}"
+ echo " };"
+ echo
+ echo " /**"
+ echo " * Provides the ${n} method for ${a} named parameters."
+ echo " */"
+ echo " template <typename Before_, typename After_>"
+ echo " class ParamNeeded_${n}"
+ echo " {"
+ echo " private:"
+ echo " const Before_ & _before;"
+ echo
+ echo " public:"
+ echo " ///\\name Basic operations"
+ echo " ///\\{"
+ echo
+ echo " After_"
+ echo " ${n}($(make_const_ref "${t}" ) value_for_${n})"
+ echo " {"
+ echo " return After_("
+ for (( j = 0 ; j < ${#want_keys[@]} ; j++ )) ; do
+ if [[ ${j} == ${k} ]] ; then
+ echo -n " Param_${n}(_before, value_for_${n})"
+ else
+ echo -n " _before"
+ fi
+ if [[ $(( ${j} + 1 )) -lt ${#want_keys[@]} ]] ; then
+ echo ","
+ else
+ echo
+ fi
+ done
+ echo " );"
+ echo " }"
+ echo
+ echo " ParamNeeded_${n}(const Before_ & before, const Empty &) :"
+ echo " _before(before)"
+ echo " {"
+ echo " }"
+ echo
+ echo " ///\\}"
+ echo " };"
+ echo
+ done
+
+ echo " /**"
+ echo " * Handle named parameters for ${a}."
+ echo " */"
+ echo " template <"
+ for (( k = 0 ; k < ${#want_keys[@]} ; k++ )) ; do
+ echo -n " bool has_${want_keys[${k}]}_"
+ if [[ $(( ${k} + 1 )) -lt ${#want_keys[@]} ]] ; then
+ echo ","
+ else
+ echo
+ fi
+ done
+ echo " >"
+ echo " class Params :"
+ for (( k = 0 ; k < ${#want_keys[@]} ; k++ )) ; do
+ echo " public Select<has_${want_keys[${k}]}_,"
+ echo " Param_${want_keys[${k}]},"
+ echo " ParamNeeded_${want_keys[${k}]}<"
+ echo -n " Params<"
+ for (( j = 0 ; j < ${#want_keys[@]} ; j++ )) ; do
+ if [[ ${j} == ${k} ]] ; then
+ echo -n "false"
+ else
+ echo -n "has_${want_keys[${j}]}_"
+ fi
+ if [[ $(( ${j} + 1 )) -lt ${#want_keys[@]} ]] ; then
+ echo -n ", "
+ else
+ echo ">,"
+ fi
+ done
+ echo -n " Params<"
+ for (( j = 0 ; j < ${#want_keys[@]} ; j++ )) ; do
+ if [[ ${j} == ${k} ]] ; then
+ echo -n "true"
+ else
+ echo -n "has_${want_keys[${j}]}_"
+ fi
+ if [[ $(( ${j} + 1 )) -lt ${#want_keys[@]} ]] ; then
+ echo -n ", "
+ else
+ echo "> >"
+ fi
+ done
+ echo " >::Type,"
+ done
+ echo " public Empty"
+ echo " {"
+ echo " private:"
+ echo " Params();"
+ echo
+ echo " public:"
+ echo " ///\\name Basic operations"
+ echo " ///\\{"
+ echo
+ echo " Params("
+ for (( k = 0 ; k < ${#want_keys[@]} ; k++ )) ; do
+ n=${want_keys[${k}]}
+ echo -n " "
+ echo -n "const typename Select<has_${n}_, Param_${n}, Empty>::Type & value_for_${n}"
+ if [[ $(( ${k} + 1 )) -lt ${#want_keys[@]} ]] ; then
+ echo ","
+ else
+ echo
+ fi
+ done
+ echo " ) :"
+ for (( k = 0 ; k < ${#want_keys[@]} ; k++ )) ; do
+ echo " Select<has_${want_keys[${k}]}_,"
+ echo " Param_${want_keys[${k}]},"
+ echo " ParamNeeded_${want_keys[${k}]}<"
+ echo -n " Params<"
+ for (( j = 0 ; j < ${#want_keys[@]} ; j++ )) ; do
+ if [[ ${j} == ${k} ]] ; then
+ echo -n "false"
+ else
+ echo -n "has_${want_keys[${j}]}_"
+ fi
+ if [[ $(( ${j} + 1 )) -lt ${#want_keys[@]} ]] ; then
+ echo -n ", "
+ else
+ echo ">,"
+ fi
+ done
+ echo -n " Params<"
+ for (( j = 0 ; j < ${#want_keys[@]} ; j++ )) ; do
+ if [[ ${j} == ${k} ]] ; then
+ echo -n "true"
+ else
+ echo -n "has_${want_keys[${j}]}_"
+ fi
+ if [[ $(( ${j} + 1 )) -lt ${#want_keys[@]} ]] ; then
+ echo -n ", "
+ else
+ echo "> >"
+ fi
+ done
+ echo " >::Type(*this, value_for_${want_keys[${k}]}),"
+ done
+
+ echo " Empty()"
+ echo " {"
+ echo " }"
+ echo
+ echo " operator ${a} () const"
+ echo " {"
+ echo " return ${a}("
+ for (( k = 0 ; k < ${#want_keys[@]} ; k++ )) ; do
+ echo -n " this->${want_keys[${k}]}"
+ if [[ $(( ${k} + 1 )) -lt ${#want_keys[@]} ]] ; then
+ echo ", "
+ else
+ echo
+ fi
+ done
+
+ echo " );"
+ echo " }"
+ echo
+ echo " ///\\}"
+ echo
+ echo " };"
+ echo
+
+ echo " /// Create, via named parameters"
+ echo -n " static Params<"
+ for (( k = 0 ; k < ${#want_keys[@]} ; k++ )) ; do
+ echo -n "false"
+ if [[ $(( ${k} + 1 )) -lt ${#want_keys[@]} ]] ; then
+ echo -n ", "
+ fi
+ done
+ echo "> create();"
+ echo
+ fi
+
+ echo "};"
+
+ elif [[ "${what_to_make}" == "--source" ]] ; then
+
+ echo "${a}::${a}("
+ for (( k = 0 ; k < ${#want_keys[@]} ; k++ )) ; do
+ echo -n " $(make_const_ref "${want_key_types[${k}]}") value_for_${want_keys[${k}]}"
+ if [[ $(( ${k} + 1 )) -lt ${#want_keys[@]} ]] ; then
+ echo ","
+ else
+ echo ") :"
+ fi
+ done
+ for (( k = 0 ; k < ${#want_keys[@]} ; k++ )) ; do
+ echo -n " ${want_keys[${k}]}(value_for_${want_keys[${k}]})"
+ if [[ $(( ${k} + 1 )) -lt ${#want_keys[@]} ]] ; then
+ echo ","
+ else
+ echo
+ fi
+ done
+ echo "{"
+ echo "}"
+ echo
+
+ echo "${a}::${a}(const ${a} & other) :"
+ for (( k = 0 ; k < ${#want_keys[@]} ; k++ )) ; do
+ echo -n " ${want_keys[${k}]}(other.${want_keys[${k}]})"
+ if [[ $(( ${k} + 1 )) -lt ${#want_keys[@]} ]] ; then
+ echo ","
+ else
+ echo
+ fi
+ done
+ echo "{"
+ echo "}"
+ echo
+
+ echo "const ${a} &"
+ echo "${a}::operator= (const ${a} & other)"
+ echo "{"
+ for (( k = 0 ; k < ${#want_keys[@]} ; k++ )) ; do
+ echo " ${want_keys[${k}]} = other.${want_keys[${k}]};"
+ done
+ echo " return *this;"
+ echo "}"
+
+ echo "${a}::~${a}()"
+ echo "{"
+ echo "}"
+ echo
+
+ 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 "{"
+ 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
+ done
+ echo " return 0;"
+ 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 "{"
+ for (( k = 0 ; k < ${#want_comparison_fields[@]} ; k++ )) ; do
+ echo " if (${want_comparison_fields[${k}]} != other.${want_comparison_fields[${k}]})"
+ echo " return false;"
+ done
+ echo " return true;"
+ echo "}"
+ echo
+ echo "bool"
+ echo "${a}::operator!= (const ${a} & other) const"
+ echo "{"
+ echo " return ! operator== (other);"
+ echo "}"
+ echo
+ else
+ echo "bad first parameter for comparison_operators" 1>&2
+ exit 1
+ fi
+ fi
+
+ if [[ -n "${want_named_args}" ]] ; then
+
+ echo -n "${a}::Params<"
+ for (( k = 0 ; k < ${#want_keys[@]} ; k++ )) ; do
+ echo -n "false"
+ if [[ $(( ${k} + 1 )) -lt ${#want_keys[@]} ]] ; then
+ echo -n ", "
+ fi
+ done
+ echo ">"
+ echo "${a}::create()"
+ echo "{"
+ echo " return Params<"
+ for (( k = 0 ; k < ${#want_keys[@]} ; k++ )) ; do
+ echo -n "false"
+ if [[ $(( ${k} + 1 )) -lt ${#want_keys[@]} ]] ; then
+ echo -n ", "
+ fi
+ done
+ echo -n ">("
+ for (( k = 0 ; k < ${#want_keys[@]} ; k++ )) ; do
+ echo -n "Empty()"
+ if [[ $(( ${k} + 1 )) -lt ${#want_keys[@]} ]] ; then
+ echo -n ", "
+ fi
+ done
+ echo ");"
+ echo "}"
+ fi
+
+ else
+ echo "bad argument (expected --header or --source)" 1>&2
+ exit 1
+ fi
+done
+