Skip to content

Commit

Permalink
added VariableVector
Browse files Browse the repository at this point in the history
  • Loading branch information
msupernaw committed Apr 15, 2024
1 parent 6bc0482 commit f90355f
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
15 changes: 15 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -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))
})
7 changes: 6 additions & 1 deletion inst/include/interface/rcpp/rcpp_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -70,6 +71,10 @@ RCPP_MODULE(growth) {
.constructor()
.field("value", &Variable::value)
.field("estimable",&Variable::estimable);
Rcpp::class_<VariableVector>("VariableVector")
.constructor()
.constructor<size_t>()
.method("at", &VariableVector::at);
Rcpp::class_<PopulationInterface>("Population")
.constructor()
.field("ages", &PopulationInterface::ages)
Expand Down Expand Up @@ -110,4 +115,4 @@ RCPP_MODULE(growth) {
Rcpp::function("CreateModel", CreateModel);
};

#endif
#endif
38 changes: 37 additions & 1 deletion inst/include/interface/rcpp/rcpp_objects/rcpp_interface_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -157,4 +193,4 @@ RcppInterfaceBase::interface_objects;
std::vector<Variable*> Variable::parameters;
std::vector<Variable*> Variable::estimated_parameters;

#endif
#endif

0 comments on commit f90355f

Please sign in to comment.