Skip to content

Commit cb61454

Browse files
committed
no way tp specify default arguments for methods, use method overloading
1 parent 6121e07 commit cb61454

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/rampl.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,16 @@ bool RAMPL::isRunning() const {
310310
return _impl.isRunning();
311311
}
312312

313+
/*.. method:: AMPL.solve(problem, solver)
314+
315+
Solve the current model.
316+
317+
:raises Error: If the underlying interpreter is not running.
318+
*/
319+
void RAMPL::solve() {
320+
_impl.solve("", "");
321+
}
322+
313323
/*.. method:: AMPL.solve(problem, solver)
314324
315325
Solve the current model.
@@ -318,11 +328,8 @@ bool RAMPL::isRunning() const {
318328
:param string solver: The solver that will be used to solve the problem.
319329
:raises Error: If the underlying interpreter is not running.
320330
*/
321-
void RAMPL::solve(Rcpp::Nullable<std::string> problem, Rcpp::Nullable<std::string> solver) {
322-
std::string cpp_problem = problem.isNotNull() ? Rcpp::as<std::string>(problem) : "";
323-
std::string cpp_solver = solver.isNotNull() ? Rcpp::as<std::string>(solver) : "";
324-
325-
_impl.solve(cpp_problem, cpp_solver);
331+
void RAMPL::solve(std::string problem, std::string solver) {
332+
_impl.solve(problem, solver);
326333
}
327334

328335

@@ -658,7 +665,8 @@ RCPP_MODULE(rampl){
658665
.method("reset", &RAMPL::reset)
659666
.method("close", &RAMPL::close)
660667
.method("isRunning", &RAMPL::isRunning)
661-
.method("solve", &RAMPL::solve, List::create( _["problem"], _["solver"] = "" ))
668+
.method("solve", ( void (RAMPL::*)() )(&RAMPL::solve))
669+
.method("solve", ( void (RAMPL::*)(std:string, std:string) )(&RAMPL::solve))
662670

663671
.method("getData", &RAMPL::getData)
664672
.method("getValue", &RAMPL::getValue)

src/rampl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ class RAMPL {
104104
void reset();
105105
void close();
106106
bool isRunning() const;
107-
void solve(Rcpp::Nullable<std::string> problem = Rcpp::Nullable<std::string>(), Rcpp::Nullable<std::string> solver = Rcpp::Nullable<std::string>());
108-
107+
void solve();
108+
void solve(std::string problem, std::string solver);
109109
Rcpp::DataFrame getData(Rcpp::List statements) const;
110110
SEXP getValue(std::string scalarExpression) const;
111111
Rcpp::String getOutput(std::string amplstatements);

0 commit comments

Comments
 (0)