| 2189 | } |
| 2190 | |
| 2191 | void CppExportsIncludeGenerator::writeBegin() { |
| 2192 | |
| 2193 | ostr() << "namespace " << packageCpp() << " {" |
| 2194 | << std::endl << std::endl; |
| 2195 | |
| 2196 | // Import Rcpp into this namespace. This allows declarations to |
| 2197 | // be written without fully qualifying all Rcpp types. The only |
| 2198 | // negative side-effect is that when this package's namespace |
| 2199 | // is imported it will also pull in Rcpp. However since this is |
| 2200 | // opt-in and represents a general desire to do namespace aliasing |
| 2201 | // this seems okay |
| 2202 | ostr() << " using namespace Rcpp;" << std::endl << std::endl; |
| 2203 | |
| 2204 | // Write our export validation helper function. Putting it in |
| 2205 | // an anonymous namespace will hide it from callers and give |
| 2206 | // it per-translation unit linkage |
| 2207 | ostr() << " namespace {" << std::endl; |
| 2208 | ostr() << " void validateSignature(const char* sig) {" |
| 2209 | << std::endl; |
| 2210 | ostr() << " Rcpp::Function require = " |
| 2211 | << "Rcpp::Environment::base_env()[\"require\"];" |
| 2212 | << std::endl; |
| 2213 | ostr() << " require(\"" << package() << "\", " |
| 2214 | << "Rcpp::Named(\"quietly\") = true);" |
| 2215 | << std::endl; |
| 2216 | |
| 2217 | std::string validate = "validate"; |
| 2218 | std::string fnType = "Ptr_" + validate; |
| 2219 | ostr() << " typedef int(*" << fnType << ")(const char*);" |
| 2220 | << std::endl; |
| 2221 | |
| 2222 | std::string ptrName = "p_" + validate; |
| 2223 | ostr() << " static " << fnType << " " << ptrName << " = " |
| 2224 | << "(" << fnType << ")" << std::endl |
| 2225 | << " " |
| 2226 | << getCCallable(exportValidationFunctionRegisteredName()) |
| 2227 | << ";" << std::endl; |
| 2228 | ostr() << " if (!" << ptrName << "(sig)) {" << std::endl; |
| 2229 | ostr() << " throw Rcpp::function_not_exported(" |
| 2230 | << std::endl |
| 2231 | << " " |
| 2232 | << "\"C++ function with signature '\" + std::string(sig) + \"' not found in " << package() |
| 2233 | << "\");" << std::endl; |
| 2234 | ostr() << " }" << std::endl; |
| 2235 | ostr() << " }" << std::endl; |
| 2236 | |
| 2237 | ostr() << " }" << std::endl << std::endl; |
| 2238 | } |
| 2239 | |
| 2240 | void CppExportsIncludeGenerator::doWriteFunctions( |
| 2241 | const SourceFileAttributes& attributes, |
no test coverage detected