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 __objectAddress="$1" __method="$2" __outputVar="$3"
33 ([[ -z "${__objectAddress}" ]] || [[ -z "${__method}" ]] || [[ -z "${__outputVar}" ]]) && >&2 echo "Bash++: Error: Invalid vTable lookup" && exit 1
35 if ! eval "declare -p \"${__objectAddress}\"" &>/dev/null; then
38 [[ -z "${!__objectAddress}" ]] && break
39 __objectAddress="${!__objectAddress}"
41 local __vTable="${__objectAddress}____vPointer"
42 if ! eval "declare -p \"${__vTable}\"" &>/dev/null; then
43 >&2 echo "Bash++: Error: vTable not found for object '${__objectAddress}'"
46 local __result="${!__vTable}[\"${__method}\"]"
47 [[ -z "${!__result}" ]] && >&2 echo "Bash++: Error: Method '${__method}' not found in vTable for object '${__objectAddress}'" && exit 1
48 eval "${__outputVar}=\$__result"
53 local __objectAddress="$1" __type="$2" __outputVar="$3"
54 ([[ -z "${__objectAddress}" ]] || [[ -z "${__type}" ]] || [[ -z "${__outputVar}" ]]) && >&2 echo "Bash++: Error: Invalid dynamic_cast" && exit 1
55 eval "${__outputVar}=0"
56 while [[ ! -z "${!__objectAddress}" ]] 2>/dev/null; do
57 __objectAddress="${!__objectAddress}"
59 local __vTable="${__objectAddress}____vPointer"
60 while [[ ! -z "${!__vTable}" ]] 2>/dev/null; do
61 [[ "${!__vTable}" == "bpp__${__type}____vTable" ]] && eval "${__outputVar}=\"${__objectAddress}\"" && return 0
62 __vTable="${!__vTable}[\"__parent__\"]"
69 local __objectAddress="$1"
70 if [[ "${__objectAddress}" == "" ]]; then
72 __objectAddress="bpp__%CLASS%__$RANDOM$RANDOM$RANDOM$RANDOM"
73 local __unusedVar="${__objectAddress}____vPointer"
74 [[ -z "${!__unusedVar+x}" ]] && break
77 eval "${__objectAddress}____vPointer=bpp__%CLASS%____vTable"
79 echo "${__objectAddress}"
84 local __objectAddress="$1"
85 local __vPointer="${__objectAddress}____vPointer"
86 if [[ "${__objectAddress}" == "0" ]] || [[ -z "${!__vPointer}" ]]; then
87 >&2 echo "Bash++: Error: %CLASS%: Attempted to delete null object"
91 unset ${__objectAddress}____vPointer
96 local __copyFromAddress="$1" __copyToAddress="$2"
97 local __copyFromVPointer="${__copyFromAddress}____vPointer" __copyToVPointer="${__copyToAddress}____vPointer"
98 if [[ "${__copyFromAddress}" == "0" ]] || [[ -z "${!__copyFromVPointer}" ]]; then
99 >&2 echo "Bash++: Error: %CLASS%: Attempted to copy from null object"
102 if [[ "${__copyToAddress}" == "0" ]] || [[ -z "${!__copyToVPointer}" ]]; then
103 >&2 echo "Bash++: Error: %CLASS%: Attempted to copy to null object"
107 eval "${__copyToVPointer}=${!__copyFromVPointer}"
112 local __objectAddress="$1"
115 local __vPointer="${__objectAddress}____vPointer"
116 if [[ "${__objectAddress}" == "0" ]] || [[ -z "${!__vPointer}" ]]; then
117 >&2 echo "Bash++: Error: Attempted to call @%CLASS%.%SIGNATURE% on null object"
125 local __objectAddress="$1"
126 local __vPointer="${__objectAddress}____vPointer"
127 if [[ "${__objectAddress}" == "0" ]] || [[ -z "${!__vPointer}" ]]; then
128 >&2 echo "Bash++: Error: %CLASS%: Attempted to construct null object"
136 local __objectAddress="$1"
137 local __vPointer="${__objectAddress}____vPointer"
138 if [[ "${__objectAddress}" == "0" ]] || [[ -z "${!__vPointer}" ]]; then
139 >&2 echo "Bash++: Error: %CLASS%: Attempted to destruct null object"
const char * bpp_vtable_lookup
Definition: templates.h:31
const char * template_delete_function
Definition: templates.h:83
const char * template_destructor
Definition: templates.h:135
const char * template_constructor
Definition: templates.h:124
const char * bpp_dynamic_cast
Definition: templates.h:52
const char * template_new_function
Definition: templates.h:68
const char * bpp_supershell_function
Definition: templates.h:9
const char * template_copy_function
Definition: templates.h:95
const char * template_method
Definition: templates.h:111