convert a C++ ::create style argument value to an R argument value (returns empty string if no conversion is possible)
| 2640 | // convert a C++ ::create style argument value to an R argument |
| 2641 | // value (returns empty string if no conversion is possible) |
| 2642 | std::string cppCreateArgToRArg(const std::string& cppArg) { |
| 2643 | |
| 2644 | std::string create = "::create"; |
| 2645 | size_t createLoc = cppArg.find(create); |
| 2646 | if (createLoc == std::string::npos || |
| 2647 | ((createLoc + create.length()) >= cppArg.size())) { |
| 2648 | return std::string(); |
| 2649 | } |
| 2650 | |
| 2651 | std::string type = cppArg.substr(0, createLoc); |
| 2652 | std::string rcppScope = "Rcpp::"; |
| 2653 | size_t rcppLoc = type.find(rcppScope); |
| 2654 | if (rcppLoc == 0 && type.size() > rcppScope.length()) |
| 2655 | type = type.substr(rcppScope.length()); |
| 2656 | |
| 2657 | std::string args = cppArg.substr(createLoc + create.length()); |
| 2658 | if (type == "CharacterVector") |
| 2659 | return "as.character( c" + args + ")"; |
| 2660 | if (type == "IntegerVector") |
| 2661 | return "as.integer( c" + args + ")"; |
| 2662 | if (type == "NumericVector") |
| 2663 | return "as.numeric( c" + args + ")"; |
| 2664 | if (type == "LogicalVector") |
| 2665 | return "as.logical( c" + args + ")"; |
| 2666 | |
| 2667 | return std::string(); |
| 2668 | } |
| 2669 | |
| 2670 | // convert a C++ Matrix to an R argument (returns empty string |
| 2671 | // if no conversion possible) |
no test coverage detected