6 #ifndef SRC_BPP_INCLUDE_TEMPLATES_H_
7 #define SRC_BPP_INCLUDE_TEMPLATES_H_
10 local bpp____supershellDirectory="/dev/shm/"
11 if [[ ! -d "${bpp____supershellDirectory}" ]]; then
12 bpp____supershellDirectory="${TMPDIR:-/tmp/}"
14 local bpp____supershelltempfile="$(mktemp "${bpp____supershellDirectory}/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")"
15 eval "exec {bpp____supershellFD__$BASHPID}<>\"$bpp____supershelltempfile\""
16 rm "$bpp____supershelltempfile"
18 function bpp____supershell() {
19 local __outputVar="$1" __command="$2" __supershellFD="bpp____supershellFD__$BASHPID" __temporaryStorage=""
20 if [[ -z "${!__supershellFD}" ]]; then
23 __temporaryStorage=$(< "/dev/fd/${!__supershellFD}")
25 $__command 1>"/dev/fd/${!__supershellFD}" 2>/dev/null
26 eval "$__outputVar=\$(< "/dev/fd/${!__supershellFD}")"
27 echo "${__temporaryStorage}">"/dev/fd/${!__supershellFD}"
32 local __this="$1" __method="$2" __outputVar="$3"
33 ([[ -z "${__this}" ]] || [[ -z "${__method}" ]] || [[ -z "${__outputVar}" ]]) && >&2 echo "Bash++: Error: Invalid vTable lookup" && exit 1
35 if ! eval "declare -p \"${__this}\"" &>/dev/null; then
38 [[ -z "${!__this}" ]] && break
41 local __vTable="${__this}____vPointer"
42 if ! eval "declare -p \"${__vTable}\"" &>/dev/null; then
45 local __result="${!__vTable}[\"${__method}\"]"
46 [[ -z "${!__result}" ]] && >&2 echo "Bash++: Error: Method '${__method}' not found in vTable for object '${__this}'" && return 1
47 eval "${__outputVar}=\$__result"
52 local __type="$1" __outputVar="$2" __this="$3"
53 ([[ -z "${__type}" ]] || [[ -z "${__outputVar}" ]]) && >&2 echo "Bash++: Error: Invalid dynamic_cast" && exit 1
54 eval "${__outputVar}=0"
56 if ! eval "declare -p \"${__this}\"" &>/dev/null; then
59 [[ -z "${!__this}" ]] && break
62 local __vTable="${__this}____vPointer"
63 if ! eval "declare -p \"${__vTable}\"" &>/dev/null; then
66 while [[ ! -z "${!__vTable}" ]] 2>/dev/null; do
67 [[ "${!__vTable}" == "bpp__${__type}____vTable" ]] && eval "${__outputVar}=\"${__this}\"" && return 0
68 __vTable="${!__vTable}[\"__parent__\"]"
76 if [[ "${__this}" == "" ]]; then
78 __this="bpp__%CLASS%__$RANDOM$RANDOM$RANDOM$RANDOM"
79 local __unusedVar="${__this}____vPointer"
80 [[ -z "${!__unusedVar+x}" ]] && break
83 eval "${__this}____vPointer=bpp__%CLASS%____vTable"
90 local __copyFromAddress="$1" __copyToAddress="$2"
92 if ! eval "declare -p \"${__copyFromAddress}\"" &>/dev/null; then
95 [[ -z "${!__copyFromAddress}" ]] && break
96 __copyFromAddress="${!__copyFromAddress}"
99 if ! eval "declare -p \"${__copyToAddress}\"" &>/dev/null; then
102 [[ -z "${!__copyToAddress}" ]] && break
103 __copyToAddress="${!__copyToAddress}"
105 local __copyFromVPointer="${__copyFromAddress}____vPointer" __copyToVPointer="${__copyToAddress}____vPointer"
106 if [[ "${__copyFromAddress}" == "0" ]] || [[ -z "${!__copyFromVPointer}" ]]; then
107 >&2 echo "Bash++: Error: %CLASS%: Attempted to copy from null object"
110 if [[ "${__copyToAddress}" == "0" ]] || [[ -z "${!__copyToVPointer}" ]]; then
111 >&2 echo "Bash++: Error: %CLASS%: Attempted to copy to null object"
114 if [[ "${!__copyFromVPointer}" != "${!__copyToVPointer}" ]]; then
115 >&2 echo "Bash++: Error: %CLASS%: Attempted to copy between different types"
119 eval "${__copyToVPointer}=${!__copyFromVPointer}"
128 if ! eval "declare -p \"${__this}\"" &>/dev/null; then
131 [[ -z "${!__this}" ]] && break
134 local __vPointer="${__this}____vPointer"
135 if [[ "${__this}" == "0" ]] || [[ -z "${!__vPointer}" ]]; then
136 >&2 echo "Bash++: Error: Attempted to call @%CLASS%.%SIGNATURE% on null object"
static const char * bpp_vtable_lookup
Definition: templates.h:31
static const char * bpp_dynamic_cast
Definition: templates.h:51
static const char * template_new_function
Definition: templates.h:74
static const char * bpp_supershell_function
Definition: templates.h:9
static const char * template_copy_function
Definition: templates.h:89
static const char * template_method
Definition: templates.h:123