diff --git a/R/zzz.R b/R/zzz.R new file mode 100644 index 0000000..3d98e36 --- /dev/null +++ b/R/zzz.R @@ -0,0 +1,15 @@ + +Rcpp::loadModule(module = "growth", what = TRUE) + + + +setMethod("[<-", signature(x = "Rcpp_VariableVector", i = "numeric"), + function(x, i) { + (x$at(i)) + return(x) + }) + +setMethod("[", signature(x = "Rcpp_VariableVector", i = "numeric"), + function(x, i) { + return(x$at(i)) + }) diff --git a/inst/include/interface/rcpp/rcpp_interface.hpp b/inst/include/interface/rcpp/rcpp_interface.hpp index ef5bb73..8dd4f67 100644 --- a/inst/include/interface/rcpp/rcpp_interface.hpp +++ b/inst/include/interface/rcpp/rcpp_interface.hpp @@ -20,6 +20,7 @@ bool CreateModel(){ * Exposes the Variable and vonBertalanffyInterface classes to R. */ RCPP_EXPOSED_CLASS(Variable) +RCPP_EXPOSED_CLASS(VariableVector) RCPP_EXPOSED_CLASS(vonBertalanffyInterface) RCPP_EXPOSED_CLASS(ObsDataInterface) @@ -70,6 +71,10 @@ RCPP_MODULE(growth) { .constructor() .field("value", &Variable::value) .field("estimable",&Variable::estimable); + Rcpp::class_("VariableVector") + .constructor() + .constructor() + .method("at", &VariableVector::at); Rcpp::class_("Population") .constructor() .field("ages", &PopulationInterface::ages) @@ -110,4 +115,4 @@ RCPP_MODULE(growth) { Rcpp::function("CreateModel", CreateModel); }; -#endif \ No newline at end of file +#endif diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_interface_base.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_interface_base.hpp index 40491cd..18916ce 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_interface_base.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_interface_base.hpp @@ -28,6 +28,42 @@ class Variable { }; + + +class VariableVector{ + static uint32_t id_g; + Rcpp::List vec_m; +public: + uint32_t id; + + VariableVector(){ + this->id = VariableVector::id_g++; + Variable v; + this->vec_m.push_back(Rcpp::wrap(v)); + } + + VariableVector(size_t size ){ + this->id = VariableVector::id_g++; + for(size_t i =0; i < size; i++){ + Variable v; + this->vec_m.push_back(Rcpp::wrap(v)); + } + } + + inline Variable operator[](size_t pos) { return this->vec_m[pos]; } + + SEXP at(size_t pos){ + if(pos == 0 || pos > this->vec_m.size()){ + Rcpp::Rcout <<"Index out of range.\n"; + return NULL; + } + return this->vec_m[pos-1]; + } + + +}; +uint32_t VariableVector::id_g = 0; + /** *@brief Base class for all interface objects */ @@ -157,4 +193,4 @@ RcppInterfaceBase::interface_objects; std::vector Variable::parameters; std::vector Variable::estimated_parameters; -#endif \ No newline at end of file +#endif