From bf3fe8bd13f18571b7d460e073a136a9e6651b01 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Mon, 29 Sep 2014 15:10:38 +0100 Subject: [PATCH] Compiled function: access to source code --- lib/CompiledFunction.cpp | 6 ++++++ lib/CompiledFunction.hpp | 4 +++- lib/CompiledModel.cpp | 8 +++++++- lib/CompiledModel.hpp | 4 +++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/CompiledFunction.cpp b/lib/CompiledFunction.cpp index b3c8f68..5c6ba58 100644 --- a/lib/CompiledFunction.cpp +++ b/lib/CompiledFunction.cpp @@ -40,8 +40,14 @@ CompiledDoubleFunction::CompiledDoubleFunction(const unsigned nArg, } // access ////////////////////////////////////////////////////////////////////// +string CompiledDoubleFunction::getCode(void) +{ + return code_; +} + void CompiledDoubleFunction::setCode(const string &code) { + code_ = code; interpreter_.reset(new MathInterpreter(code)); context_.reset(new RunContext); varAddress_.reset(new std::vector); diff --git a/lib/CompiledFunction.hpp b/lib/CompiledFunction.hpp index 4bbdb2f..b827571 100644 --- a/lib/CompiledFunction.hpp +++ b/lib/CompiledFunction.hpp @@ -38,7 +38,8 @@ public: // destructor virtual ~CompiledDoubleFunction(void) = default; // access - void setCode(const std::string &code); + std::string getCode(void); + void setCode(const std::string &code); // function call using DoubleFunction::operator(); virtual double operator()(const double *arg) const; @@ -49,6 +50,7 @@ private: // compile void compile(void) const; private: + std::string code_; std::shared_ptr interpreter_; std::shared_ptr context_; std::shared_ptr> varAddress_; diff --git a/lib/CompiledModel.cpp b/lib/CompiledModel.cpp index 0a4ba2c..eb4237b 100644 --- a/lib/CompiledModel.cpp +++ b/lib/CompiledModel.cpp @@ -42,9 +42,15 @@ CompiledDoubleModel::CompiledDoubleModel(const unsigned nArg, } // access ////////////////////////////////////////////////////////////////////// +string CompiledDoubleModel::getCode(void) +{ + return code_; +} + void CompiledDoubleModel::setCode(const std::string &code) { - interpreter_.reset(new MathInterpreter(code)); + code_ = code; + interpreter_.reset(new MathInterpreter(code_)); context_.reset(new RunContext); varAddress_.reset(new std::vector); parAddress_.reset(new std::vector); diff --git a/lib/CompiledModel.hpp b/lib/CompiledModel.hpp index cc479d9..600006e 100644 --- a/lib/CompiledModel.hpp +++ b/lib/CompiledModel.hpp @@ -39,7 +39,8 @@ public: // destructor virtual ~CompiledDoubleModel(void) = default; // access - void setCode(const std::string &code); + std::string getCode(void); + void setCode(const std::string &code); // function call using DoubleModel::operator(); virtual double operator()(const double *arg, const double *par) const; @@ -50,6 +51,7 @@ private: // compile void compile(void) const; private: + std::string code_; std::shared_ptr interpreter_; std::shared_ptr context_; std::shared_ptr> varAddress_, parAddress_;