6#ifndef SRC_BPP_INCLUDE_TEMPLATES_H_
7#define SRC_BPP_INCLUDE_TEMPLATES_H_
24 local bpp____supershellDirectory="/dev/shm/"
25 if [[ ! -d "${bpp____supershellDirectory}" ]]; then
26 bpp____supershellDirectory="${TMPDIR:-/tmp/}"
28 local bpp____supershelltempfile="$(mktemp "${bpp____supershellDirectory}/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")"
29 eval "exec {bpp____supershellFD__$BASHPID}<>\"$bpp____supershelltempfile\""
30 rm "$bpp____supershelltempfile"
32function bpp____supershell() {
33 local __outputVar="$1" __command="$2" __supershellFD="bpp____supershellFD__$BASHPID" __temporaryStorage=""
34 if [[ -z "${!__supershellFD}" ]]; then
37 __temporaryStorage=$(< "/dev/fd/${!__supershellFD}")
39 $__command 1>"/dev/fd/${!__supershellFD}" 2>/dev/null
40 eval "$__outputVar=\$(< "/dev/fd/${!__supershellFD}")"
41 echo "${__temporaryStorage}">"/dev/fd/${!__supershellFD}"
46 local __this="$1" __method="$2" __outputVar="$3"
47 ([[ -z "${__this}" ]] || [[ -z "${__method}" ]] || [[ -z "${__outputVar}" ]]) && >&2 echo "Bash++: Error: Invalid vTable lookup" && exit 1
49 if ! eval "declare -p \"${__this}\"" &>/dev/null; then
52 [[ -z "${!__this}" ]] && break
55 local __vTable="${__this}____vPointer"
56 if ! eval "declare -p \"${__vTable}\"" &>/dev/null; then
59 local __result="${!__vTable}[\"${__method}\"]"
60 [[ -z "${!__result}" ]] && >&2 echo "Bash++: Error: Method '${__method}' not found in vTable for object '${__this}'" && return 1
61 eval "${__outputVar}=\$__result"
66 local __type="$1" __outputVar="$2" __this="$3"
67 ([[ -z "${__type}" ]] || [[ -z "${__outputVar}" ]]) && >&2 echo "Bash++: Error: Invalid dynamic_cast" && exit 1
68 eval "${__outputVar}=0"
70 if ! eval "declare -p \"${__this}\"" &>/dev/null; then
73 [[ -z "${!__this}" ]] && break
76 local __vTable="${__this}____vPointer"
77 if ! eval "declare -p \"${__vTable}\"" &>/dev/null; then
80 while [[ ! -z "${!__vTable}" ]] 2>/dev/null; do
81 [[ "${!__vTable}" == "bpp__${__type}____vTable" ]] && eval "${__outputVar}=\"${__this}\"" && return 0
82 __vTable="${!__vTable}[\"__parent__\"]"
89 local __this="$1" __outputVar="$2"
90 [[ -z "${__this}" ]] && >&2 echo "Bash++: Error: Invalid type name request" && exit 1
92 if ! eval "declare -p \"${__this}\"" &>/dev/null; then
95 [[ -z "${!__this}" ]] && break
98 local __vTable="${__this}____vPointer"
99 if ! eval "declare -p \"${__vTable}\"" &>/dev/null; then
102 __vTable="${!__vTable}"
103 local __typeName="${__vTable/bpp__/}"
104 __typeName="${__typeName/____vTable/}"
105 eval "${__outputVar}=\"${__typeName}\""
111 if [[ "${__this}" == "" ]]; then
113 __this="bpp__%CLASS%__$RANDOM$RANDOM$RANDOM$RANDOM"
114 local __unusedVar="${__this}____vPointer"
115 [[ -z "${!__unusedVar+x}" ]] && break
118 eval "${__this}____vPointer=bpp__%CLASS%____vTable"
125 local __copyFromAddress="$1" __copyToAddress="$2"
127 if ! eval "declare -p \"${__copyFromAddress}\"" &>/dev/null; then
130 [[ -z "${!__copyFromAddress}" ]] && break
131 __copyFromAddress="${!__copyFromAddress}"
134 if ! eval "declare -p \"${__copyToAddress}\"" &>/dev/null; then
137 [[ -z "${!__copyToAddress}" ]] && break
138 __copyToAddress="${!__copyToAddress}"
140 local __copyFromVPointer="${__copyFromAddress}____vPointer" __copyToVPointer="${__copyToAddress}____vPointer"
141 if [[ "${__copyFromAddress}" == "0" ]] || [[ -z "${!__copyFromVPointer}" ]]; then
142 >&2 echo "Bash++: Error: %CLASS%: Attempted to copy from null object"
145 if [[ "${__copyToAddress}" == "0" ]] || [[ -z "${!__copyToVPointer}" ]]; then
146 >&2 echo "Bash++: Error: %CLASS%: Attempted to copy to null object"
149 if [[ "${!__copyFromVPointer}" != "${!__copyToVPointer}" ]]; then
150 >&2 echo "Bash++: Error: %CLASS%: Attempted to copy between different types"
154 eval "${__copyToVPointer}=${!__copyFromVPointer}"
163 if ! eval "declare -p \"${__this}\"" &>/dev/null; then
166 [[ -z "${!__this}" ]] && break
169 local __vPointer="${__this}____vPointer"
170 if [[ "${__this}" == "0" ]] || [[ -z "${!__vPointer}" ]]; then
171 >&2 echo "Bash++: Error: Attempted to call @%CLASS%.%SIGNATURE% on null object"
static const char * bpp_vtable_lookup
Definition templates.h:45
static const char * bpp_typeof_function
Definition templates.h:88
static const char * bpp_dynamic_cast
Definition templates.h:65
static const char * template_new_function
Definition templates.h:109
static const char * bpp_supershell_function
Definition templates.h:23
static const char * template_copy_function
Definition templates.h:124
static const char * template_method
Definition templates.h:158