// Execute mathematica constructs and fetch the response shell << matd; shell >> determinant;
// determinant can be converted to C++ machine sized types std::cout << determinant << std::endl; // Prints -2
The Mathematica functions declared with MATHEMATICA_DECLARE outside any function (may be inside a header) e.g. MATHEMATICA_DECLARE(Table), MATHEMATICA_DECLARE(Det)
A symbols created using mathematica::symbol e.g. mathematica::symbol i("i"), mathematica::symbol j("j")
mathematica::m creates a mathematica construct
mathematica::value holds the value returnd from mathematica
mathematica::value object can be converted to an equivalent STL container like std::vector using mathematica::cast
1 2
std::vector<int> list; list = cast<std::vector<int>>(result_list);
Executing intermediate returned output
An mathematica::value object can be using to build a mathematica::m construct. Here res_mata and res_matb are values returned by mathematica that we are passing inside Det.
1 2 3 4 5 6 7 8 9 10 11 12 13
value res_mata; value res_matb; value res_matc; value res_det;
point(): location(std::make_pair(0, 0)), name(""), elevation (0.0f){} point (std::pair<int, int> loc, conststd::string& name_, double elevation_): location(loc), name(name_), elevation(elevation_){} }; value result; point pti(std::make_pair(1, 1), "Hallo", 100.0f); shell << Evaluate(pti); shell >> result; point pto = cast<point>(result);
The object pti of type struct point is the above example will be serialized as Association[Rule["location", List[1, 1]], Rule["name", "Hallo"], Rule["elevation", 100]]. The associations need to be declared as following.