convert a C++ numeric argument to an R argument value (returns empty string if no conversion is possible)
| 2608 | // convert a C++ numeric argument to an R argument value |
| 2609 | // (returns empty string if no conversion is possible) |
| 2610 | std::string cppNumericArgToRArg(const std::string& type, |
| 2611 | const std::string& cppArg) { |
| 2612 | // check for a number |
| 2613 | double num; |
| 2614 | std::stringstream argStream(cppArg); |
| 2615 | if ((argStream >> num)) { |
| 2616 | |
| 2617 | // L suffix means return the value literally |
| 2618 | if (!argStream.eof()) { |
| 2619 | std::string suffix; |
| 2620 | argStream >> suffix; |
| 2621 | if (argStream.eof() && suffix == "L") |
| 2622 | return cppArg; |
| 2623 | } |
| 2624 | |
| 2625 | // no decimal and the type isn't explicitly double or |
| 2626 | // float means integer |
| 2627 | if (cppArg.find('.') == std::string::npos && |
| 2628 | type != "double" && type != "float") |
| 2629 | return cppArg + "L"; |
| 2630 | |
| 2631 | // otherwise return arg literally |
| 2632 | else |
| 2633 | return cppArg; |
| 2634 | } |
| 2635 | else { |
| 2636 | return std::string(); |
| 2637 | } |
| 2638 | } |
| 2639 | |
| 2640 | // convert a C++ ::create style argument value to an R argument |
| 2641 | // value (returns empty string if no conversion is possible) |