[Rcpp-commits] r3912 - in pkg/Rcpp: . src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Nov 7 18:25:06 CET 2012
Author: jjallaire
Date: 2012-11-07 18:25:05 +0100 (Wed, 07 Nov 2012)
New Revision: 3912
Modified:
pkg/Rcpp/ChangeLog
pkg/Rcpp/src/Attributes.cpp
Log:
import Rcpp namespace into package shim namespace
Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog 2012-11-07 16:12:29 UTC (rev 3911)
+++ pkg/Rcpp/ChangeLog 2012-11-07 17:25:05 UTC (rev 3912)
@@ -2,7 +2,8 @@
* src/Attributes.cpp: validate exported C++ functions before calling;
use static rather than inline for stubs to avoid call-site bloat;
- improved error message when package hpp already exists
+ improved error message when package hpp already exists; import Rcpp
+ namespace into package shim namespace
* src/AttributesParser.h: add signature and isHidden methods
* src/AttributesParser.cpp: add signature and isHidden methods
* src/exceptions.cpp: add function_not_exported exception
Modified: pkg/Rcpp/src/Attributes.cpp
===================================================================
--- pkg/Rcpp/src/Attributes.cpp 2012-11-07 16:12:29 UTC (rev 3911)
+++ pkg/Rcpp/src/Attributes.cpp 2012-11-07 17:25:05 UTC (rev 3912)
@@ -383,6 +383,9 @@
ostr << "#include <set>" << std::endl;
ostr << std::endl;
+ // always bring in Rcpp
+ ostr << "using namespace Rcpp;" << std::endl << std::endl;
+
// prototypes
if (!prototypes_.empty()) {
for (std::size_t i=0;i<prototypes_.size(); i++)
@@ -434,13 +437,21 @@
}
virtual void writeBegin() {
- ostr() << "namespace " << package() << " {" << std::endl;
+ ostr() << "namespace " << package() << " {"
+ << std::endl << std::endl;
+ // Import Rcpp into this namespace. This allows declarations to
+ // be written without fully qualifying all Rcpp types. The only
+ // negative side-effect is that when this package's namespace
+ // is imported it will also pull in Rcpp. However since this is
+ // opt-in and represents a general desire to do namespace aliasing
+ // this seems okay
+ ostr() << " using namespace Rcpp;" << std::endl << std::endl;
+
// Write our export validation helper function. Putting it in
// an anonymous namespace will hide it from callers and give
// it per-translation unit linkage
ostr() << " namespace {" << std::endl;
-
ostr() << " void " << exportValidationFunction()
<< "(const std::string& sig) {" << std::endl;
std::string ptrName = "p_" + exportValidationFunction();
@@ -504,7 +515,7 @@
}
ostr() << ");" << std::endl;
- ostr() << " }" << std::endl;
+ ostr() << " }" << std::endl << std::endl;
}
}
}
More information about the Rcpp-commits
mailing list