An Example Wrapper

A <#7152#>wrapper<#7152#> routine is one which translates its input into a new format, calls a routine which requires this format, and then translates the return value back into the format of the calling environment. In <#7211#>LINK<#7211#>, wrappers extract C++ data from STk structures, call a <#7212#>LINK~<#7212#> method, and store the return value in a new Scheme object. As stated above, Erick Gallesio's document <#7153#>Extending the STk Interpreter<#7153#> will be a helpful guide to extending the <#7213#>LINK~<#7213#>system, though there are dozens small wrapper programs in <#7214#>LINK~<#7214#>which can serve as examples. In particular, the file <#7154#>graph_Graph_Methods.cpp<#7154#> in 14 contains wrappers for the many methods of the <#7215#>Graph<#7215#>class, while the files in 15 contain individual wrapper programs for the library algorithms. Let us consider the example wrapper in Figure~#fig:even-odd#7155>. This is the wrapper associated with the example program 16. The input is an STk ``cons'' element, which is simple a structure pointer. STk provides many helpful macros for extracting useful information from this structure (see stk.h). However, <#7216#>LINK~<#7216#>provides several shortcut functions to abstract some of the detail away.