-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
330 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
Copyright libCellML Contributors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "libcellml/exportdefinitions.h" | ||
#include "libcellml/types.h" | ||
|
||
namespace libcellml { | ||
|
||
/** | ||
* @brief The Interpreter class. | ||
* | ||
* The Interpreter class is for representing a CellML Interpreter. | ||
*/ | ||
class LIBCELLML_EXPORT Interpreter | ||
{ | ||
public: | ||
~Interpreter(); /**< Destructor, @private. */ | ||
Interpreter(const Interpreter &rhs) = delete; /**< Copy constructor, @private. */ | ||
Interpreter(Interpreter &&rhs) noexcept = delete; /**< Move constructor, @private. */ | ||
Interpreter &operator=(Interpreter rhs) = delete; /**< Assignment operator, @private. */ | ||
|
||
/** | ||
* @brief Create an @ref Interpreter object. | ||
* | ||
* Factory method to create an @ref Interpreter. Create an interpreter with:: | ||
* | ||
* @code | ||
* auto interpreter = libcellml::Interpreter::create(); | ||
* @endcode | ||
* | ||
* @return A smart pointer to an @ref Interpreter object. | ||
*/ | ||
static InterpreterPtr create() noexcept; | ||
|
||
/** | ||
* @brief Get the @ref AnalyserModel. | ||
* | ||
* Get the @ref AnalyserModel used by this @ref Interpreter. | ||
* | ||
* @return The @ref AnalyserModel used. | ||
*/ | ||
AnalyserModelPtr model(); | ||
|
||
/** | ||
* @brief Set the @ref AnalyserModel. | ||
* | ||
* Set the @ref AnalyserModel to be used by this @ref Interpreter. | ||
* | ||
* @param model The @ref AnalyserModel to set. | ||
*/ | ||
void setModel(const AnalyserModelPtr &model); | ||
|
||
private: | ||
Interpreter(); /**< Constructor, @private. */ | ||
|
||
struct InterpreterImpl; | ||
InterpreterImpl *mPimpl; /**< Private member to implementation pointer, @private. */ | ||
}; | ||
|
||
} // namespace libcellml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
%module(package="libcellml") interpreter | ||
|
||
#define LIBCELLML_EXPORT | ||
|
||
%include <std_string.i> | ||
|
||
%import "analysermodel.i" | ||
%import "createconstructor.i" | ||
|
||
%feature("docstring") libcellml::Interpreter | ||
"Creates a :class:`Interpreter` object."; | ||
|
||
%feature("docstring") libcellml::Interpreter::model | ||
"Returns the model to interpret."; | ||
|
||
%feature("docstring") libcellml::Interpreter::setModel | ||
"Sets the model to interpret."; | ||
|
||
%{ | ||
#include "libcellml/interpreter.h" | ||
%} | ||
|
||
%pythoncode %{ | ||
# libCellML generated wrapper code starts here. | ||
%} | ||
|
||
%create_constructor(Interpreter) | ||
|
||
%include "libcellml/interpreter.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
Copyright libCellML Contributors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#include <emscripten/bind.h> | ||
|
||
#include "libcellml/interpreter.h" | ||
|
||
using namespace emscripten; | ||
|
||
EMSCRIPTEN_BINDINGS(libcellml_interpreter) | ||
{ | ||
class_<libcellml::Interpreter>("Interpreter") | ||
.smart_ptr_constructor("Interpreter", &libcellml::Interpreter::create) | ||
.function("model", &libcellml::Interpreter::model) | ||
.function("setModel", &libcellml::Interpreter::setModel) | ||
; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
Copyright libCellML Contributors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#include "libcellml/interpreter.h" | ||
|
||
#include "interpreter_p.h" | ||
|
||
namespace libcellml { | ||
|
||
Interpreter::Interpreter() | ||
: mPimpl(new InterpreterImpl()) | ||
{ | ||
} | ||
|
||
Interpreter::~Interpreter() | ||
{ | ||
delete mPimpl; | ||
} | ||
|
||
InterpreterPtr Interpreter::create() noexcept | ||
{ | ||
return std::shared_ptr<Interpreter> {new Interpreter {}}; | ||
} | ||
|
||
AnalyserModelPtr Interpreter::model() | ||
{ | ||
return mPimpl->mModel; | ||
} | ||
|
||
void Interpreter::setModel(const AnalyserModelPtr &model) | ||
{ | ||
mPimpl->mModel = model; | ||
} | ||
|
||
} // namespace libcellml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
Copyright libCellML Contributors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "libcellml/interpreter.h" | ||
|
||
namespace libcellml { | ||
|
||
std::string generateDoubleCode(const std::string &value); | ||
|
||
/** | ||
* @brief The Interpreter::InterpreterImpl struct. | ||
* | ||
* The private implementation for the Interpreter class. | ||
*/ | ||
struct Interpreter::InterpreterImpl | ||
{ | ||
AnalyserModelPtr mModel; | ||
}; | ||
|
||
} // namespace libcellml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
Copyright libCellML Contributors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
const loadLibCellML = require('libcellml.js/libcellml.common') | ||
const { basicModel } = require('./resources') | ||
|
||
let libcellml = null | ||
|
||
describe("Interpreter tests", () => { | ||
beforeAll(async () => { | ||
libcellml = await loadLibCellML() | ||
}) | ||
test('Checking Interpreter model manipulation.', () => { | ||
const i = new libcellml.Interpreter() | ||
const p = new libcellml.Parser(true) | ||
|
||
m = p.parseModel(basicModel) | ||
a = new libcellml.Analyser() | ||
|
||
a.analyseModel(m) | ||
|
||
expect(i.model()).toBe(null) | ||
|
||
i.setModel(a.model()) | ||
|
||
expect(i.model()).toBeDefined() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# | ||
# Tests the Interpreter class bindings | ||
# | ||
import unittest | ||
|
||
|
||
class InterpreterTestCase(unittest.TestCase): | ||
|
||
def test_create_destroy(self): | ||
from libcellml import Interpreter | ||
|
||
x = Interpreter() | ||
del x | ||
|
||
def test_algebraic_eqn_computed_var_on_rhs(self): | ||
from libcellml import Analyser | ||
from libcellml import AnalyserModel | ||
from libcellml import Interpreter | ||
from libcellml import Parser | ||
from test_resources import file_contents | ||
|
||
p = Parser() | ||
m = p.parseModel(file_contents('generator/algebraic_eqn_computed_var_on_rhs/model.cellml')) | ||
|
||
a = Analyser() | ||
a.analyseModel(m) | ||
|
||
am = a.model() | ||
|
||
self.assertEqual(AnalyserModel.Type.ALGEBRAIC, am.type()) | ||
|
||
i = Interpreter() | ||
|
||
self.assertIsNone(i.model()) | ||
|
||
i.setModel(am) | ||
|
||
self.assertIsNotNone(i.model()) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Oops, something went wrong.