Skip to content

Commit

Permalink
whisker 4 beginning of create_fims_rcpp_interface
Browse files Browse the repository at this point in the history
Started translating code from create_fims_rcpp_interface to a whisker
template. Added example of how
to run this in the roxygen
of create_fims_rcpp_interface

Still need to fix to match what the current
files look like rather than what the old cat() template
says we should have.
Also maybe do not need all of the fed to the function.

Co-authored-by: Chris Legault <chris.legault@noaa.gov>
  • Loading branch information
kellijohnson-NOAA and cmlegault committed Aug 23, 2023
1 parent bf9932a commit 3025158
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
21 changes: 21 additions & 0 deletions R/create_rcpp_interface_object.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@
#' evaluate_parameter = "x",
#' evaluate_parameter_type = "double"
#' )
#' whisker.render(
#' # xfun::read_utf8("inst/templates/test.hpp"),
#' xfun::read_utf8("inst/templates/test_template.hpp"),
#' data = list(
#' interface_name = "mybestname",
#' base_class = "thisclassisthebomb",
#' evaluate_parameter = TRUE,
#' evaluate_parameter_type = "works",
#' model = "test",
#' parameters = unname(whisker::rowSplit(data.frame(
#' value = c("mean", "sd"),
#' comment = c("comment 1", "comment 2")
#' ))),
#' types = unname(whisker::rowSplit(data.frame(
#' values = c("mean", "sd"),
#' mtypes = c("comment 1", "comment 2")
#' )))
#' )
#' ) |>
#' strsplit(split = "\n")
create_fims_rcpp_interface <- function(interface_name = character(),
model = character(),
base_class = character(),
Expand Down Expand Up @@ -67,6 +87,7 @@ create_fims_rcpp_interface <- function(interface_name = character(),

cat(" virtual uint32_t get_id() { return this->id; }\n\n\n")

# find option for whisker if evaluate parameter is null
if (!is.null(evaluate_parameter)) {
cat(paste0(" virtual double evaluate(", evaluate_parameter_type, " ", evaluate_parameter, ") {\n"))
cat(paste0(" fims::", model, "<double> object;\n"))
Expand Down
35 changes: 35 additions & 0 deletions inst/templates/test_template.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class {{{ interface_name }}} : public {{{ base_class }}} {
public:

/**< static id of the {{{ interface_name }}} object */

{{{#parameters}}}
Parameter {{{value}}} /**{{{comment}}}*/
{{{/parameters}}}

{{{ interface_name }}}() : {{{ base_class }}}() {}

virtual ~{{{interface_name}}}() {}

virtual uint32_t get_id() { return this->id; }

virtual double evaluate( {{{evaluate_parameter_type}}} {{{#evaluate_parameter}}})
fims::{{{model}}} <double> object;
{{{#parameters}}}
object.{{{value}}}; = this->{{{value}}}.value;
{{{/parameters}}}
return object.evaluate( {{{evaluate_parameter_type}}} );

virtual bool add_to_fims_tmb()
{{{#types}}}
std::shared_ptr<fims::Information< {{{values}}}
fims::Information< {{{values}}} >::GetInstance();

std::shared_ptr<fims::{{{model}}}< {{{values}}} > > {{{mtypes}}}
std::make_shared<fims:: {{{model}}} < {{{values}}} > >();


{{{mtypes}}} ->id = this->id;
{{{/types}}}
{{{/evaluate_parameter}}}
}

0 comments on commit 3025158

Please sign in to comment.