yap4r
This commit is contained in:
2
packages/real/yap4r/src/Makevars.in
Normal file
2
packages/real/yap4r/src/Makevars.in
Normal file
@@ -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../..
|
67
packages/real/yap4r/src/RcppExports.cpp
Normal file
67
packages/real/yap4r/src/RcppExports.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
// Generated by using Rcpp::compileAttributes() -> do not edit by hand
|
||||
// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
|
||||
|
||||
#include <Rcpp.h>
|
||||
|
||||
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);
|
||||
}
|
93
packages/real/yap4r/src/yap4r.cpp
Normal file
93
packages/real/yap4r/src/yap4r.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
#include <Rcpp.h>
|
||||
|
||||
#undef Realloc
|
||||
#undef Malloc
|
||||
#undef Free
|
||||
#include <yapi.hh>
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "real.h"
|
||||
|
||||
|
||||
using namespace Rcpp;
|
||||
|
||||
class YAP4R {
|
||||
|
||||
YAPEngine *yap;
|
||||
YAPQuery *q;
|
||||
std::vector<YAPTerm> 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>( "YAP4R" )
|
||||
.constructor("documentation for default constructor")
|
||||
.method( "query", &YAP4R::query )
|
||||
.method( "next", &YAP4R::next )
|
||||
.method( "ask", &YAP4R::ask )
|
||||
.method( "cut", &YAP4R::cut )
|
||||
;
|
||||
;
|
||||
}
|
Reference in New Issue
Block a user