diff --git a/packages/real/yap4r/DESCRIPTION b/packages/real/yap4r/DESCRIPTION new file mode 100644 index 000000000..b9d787454 --- /dev/null +++ b/packages/real/yap4r/DESCRIPTION @@ -0,0 +1,12 @@ +Package: yap4r +Type: Package +Title: What the Package Does in One 'Title Case' Line +Version: 1.0 +Date: 2019-03-25 +Author: Your Name +Maintainer: Your Name +Description: One paragraph description of what the package does as one + or more full sentences. +License: GPL (>= 2) +Imports: Rcpp (>= 1.0.1) +LinkingTo: Rcpp diff --git a/packages/real/yap4r/NAMESPACE b/packages/real/yap4r/NAMESPACE new file mode 100644 index 000000000..a97033a02 --- /dev/null +++ b/packages/real/yap4r/NAMESPACE @@ -0,0 +1,3 @@ +useDynLib(yap4r, .registration=TRUE) +exportPattern("^[[:alpha:]]+") +importFrom(Rcpp, evalCpp) diff --git a/packages/real/yap4r/R/RcppExports.R b/packages/real/yap4r/R/RcppExports.R new file mode 100644 index 000000000..1c03a2ce6 --- /dev/null +++ b/packages/real/yap4r/R/RcppExports.R @@ -0,0 +1,19 @@ +# Generated by using Rcpp::compileAttributes() -> do not edit by hand +# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 + +query <- function(p_name, p_module, sexp) { + .Call(`_yap4r_query`, p_name, p_module, sexp) +} + +next <- function() { + .Call(`_yap4r_next`) +} + +cut <- function() { + .Call(`_yap4r_cut`) +} + +ask <- function(i) { + .Call(`_yap4r_ask`, i) +} + diff --git a/packages/real/yap4r/man/yap4r-package.Rd b/packages/real/yap4r/man/yap4r-package.Rd new file mode 100644 index 000000000..ae1dc9709 --- /dev/null +++ b/packages/real/yap4r/man/yap4r-package.Rd @@ -0,0 +1,34 @@ +\name{yap4r-package} +\alias{yap4r-package} +\alias{yap4r} +\docType{package} +\title{ + A short title line describing what the package does +} +\description{ + A more detailed description of what the package does. A length + of about one to five lines is recommended. +} +\details{ + This section should provide a more detailed overview of how to use the + package, including the most important functions. +} +\author{ +Your Name, email optional. + +Maintainer: Your Name +} +\references{ + This optional section can contain literature or other references for + background information. +} +\keyword{ package } +\seealso{ + Optional links to other man pages +} +\examples{ + \dontrun{ + ## Optional simple examples of the most important functions + ## These can be in \dontrun{} and \donttest{} blocks. + } +} diff --git a/packages/real/yap4r/src/Makevars.in b/packages/real/yap4r/src/Makevars.in new file mode 100644 index 000000000..508f8895a --- /dev/null +++ b/packages/real/yap4r/src/Makevars.in @@ -0,0 +1,2 @@ +PKG_LIBS=-L/home/vsc/.local/lib/Yap/ -lreal +PKG_CPPFLAGS=-I../../../../CXX -I../../../../build -I../../../../include -I../../../../H -I../../../../OPTYap -I../../../../os -I../.. \ No newline at end of file diff --git a/packages/real/yap4r/src/RcppExports.cpp b/packages/real/yap4r/src/RcppExports.cpp new file mode 100644 index 000000000..d44a30492 --- /dev/null +++ b/packages/real/yap4r/src/RcppExports.cpp @@ -0,0 +1,67 @@ +// Generated by using Rcpp::compileAttributes() -> do not edit by hand +// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 + +#include + +using namespace Rcpp; + +// query +bool query(std::string p_name, std::string p_module, SEXP sexp); +RcppExport SEXP _yap4r_query(SEXP p_nameSEXP, SEXP p_moduleSEXP, SEXP sexpSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< std::string >::type p_name(p_nameSEXP); + Rcpp::traits::input_parameter< std::string >::type p_module(p_moduleSEXP); + Rcpp::traits::input_parameter< SEXP >::type sexp(sexpSEXP); + rcpp_result_gen = Rcpp::wrap(query(p_name, p_module, sexp)); + return rcpp_result_gen; +END_RCPP +} +// next +bool next(); +RcppExport SEXP _yap4r_next() { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + rcpp_result_gen = Rcpp::wrap(next()); + return rcpp_result_gen; +END_RCPP +} +// cut +bool cut(); +RcppExport SEXP _yap4r_cut() { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + rcpp_result_gen = Rcpp::wrap(cut()); + return rcpp_result_gen; +END_RCPP +} +// ask +SEXP ask(int i); +RcppExport SEXP _yap4r_ask(SEXP iSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< int >::type i(iSEXP); + rcpp_result_gen = Rcpp::wrap(ask(i)); + return rcpp_result_gen; +END_RCPP +} + +RcppExport SEXP _rcpp_module_boot_mod_yap4r(); + +static const R_CallMethodDef CallEntries[] = { + {"_yap4r_query", (DL_FUNC) &_yap4r_query, 3}, + {"_yap4r_next", (DL_FUNC) &_yap4r_next, 0}, + {"_yap4r_cut", (DL_FUNC) &_yap4r_cut, 0}, + {"_yap4r_ask", (DL_FUNC) &_yap4r_ask, 1}, + {"_rcpp_module_boot_mod_yap4r", (DL_FUNC) &_rcpp_module_boot_mod_yap4r, 0}, + {NULL, NULL, 0} +}; + +RcppExport void R_init_yap4r(DllInfo *dll) { + R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); + R_useDynamicSymbols(dll, FALSE); +} diff --git a/packages/real/yap4r/src/yap4r.cpp b/packages/real/yap4r/src/yap4r.cpp new file mode 100644 index 000000000..16ecd9820 --- /dev/null +++ b/packages/real/yap4r/src/yap4r.cpp @@ -0,0 +1,93 @@ +#include + +#undef Realloc +#undef Malloc +#undef Free +#include + +#include + +#include "real.h" + + +using namespace Rcpp; + +class YAP4R { + + YAPEngine *yap; + YAPQuery *q; + std::vector args; + bool failed; + +public: +//[[Rcpp::export]] + +YAP4R() { + YAPEngineArgs *yargs = new YAPEngineArgs(); + yap = new YAPEngine(yargs); +}; + + +//[[Rcpp::export]] +bool query(std::string p_name,std::string p_module, SEXP sexp) { + + YAPPairTerm tmp; + if (q) { + q->close(); + q = NULL; + } + if (!sexp_to_pl(tmp.handle(), sexp)) + return false; + args = tmp.listToVector(); + YAPTerm ts[1], hd; + YAPTerm qt = YAPApplTerm(p_name,args); + q = new YAPQuery(qt); + return true; +}; + + +//[[Rcpp::export]] + bool next() { + bool rc = true; + if (failed) + return false; + if (q) + rc = next(); + if (!rc) { + failed = true; + } + return rc; + } + +//[[Rcpp::export]] + bool cut() { + bool rc = true; + if (failed) + return false; + if (q) + rc = cut(); + q = NULL; + return rc; + }; + +//[[Rcpp::export]] + SEXP ask(int i) { + if (failed || q==nullptr) + return R_MissingArg; + return term_to_sexp(YAPTerm(Yap_XREGS[i]).handle(), false); + }; + + + +}; + + RCPP_MODULE(mod_yap4r) { + Rcpp::class_( "YAP4R" ) + .constructor("documentation for default constructor") + .method( "query", &YAP4R::query ) +.method( "next", &YAP4R::next ) +.method( "ask", &YAP4R::ask ) +.method( "cut", &YAP4R::cut ) + ; +; +}