Skip to content

Commit eb8671c

Browse files
committed
Added a GeneratorContext class to manage un/tracked variables.
1 parent 56dd562 commit eb8671c

25 files changed

+327
-1
lines changed

src/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ set(SOURCE_FILES
4949
${CMAKE_CURRENT_SOURCE_DIR}/entity.cpp
5050
${CMAKE_CURRENT_SOURCE_DIR}/enums.cpp
5151
${CMAKE_CURRENT_SOURCE_DIR}/generator.cpp
52+
${CMAKE_CURRENT_SOURCE_DIR}/generatorcontext.cpp
5253
${CMAKE_CURRENT_SOURCE_DIR}/generatorprofile.cpp
5354
${CMAKE_CURRENT_SOURCE_DIR}/generatorprofiletools.cpp
5455
${CMAKE_CURRENT_SOURCE_DIR}/importedentity.cpp
@@ -90,6 +91,7 @@ set(GIT_API_HEADER_FILES
9091
${CMAKE_CURRENT_SOURCE_DIR}/api/libcellml/entity.h
9192
${CMAKE_CURRENT_SOURCE_DIR}/api/libcellml/enums.h
9293
${CMAKE_CURRENT_SOURCE_DIR}/api/libcellml/generator.h
94+
${CMAKE_CURRENT_SOURCE_DIR}/api/libcellml/generatorcontext.h
9395
${CMAKE_CURRENT_SOURCE_DIR}/api/libcellml/generatorprofile.h
9496
${CMAKE_CURRENT_SOURCE_DIR}/api/libcellml/importedentity.h
9597
${CMAKE_CURRENT_SOURCE_DIR}/api/libcellml/importer.h
@@ -134,6 +136,7 @@ set(GIT_HEADER_FILES
134136
${CMAKE_CURRENT_SOURCE_DIR}/debug.h
135137
${CMAKE_CURRENT_SOURCE_DIR}/entity_p.h
136138
${CMAKE_CURRENT_SOURCE_DIR}/generator_p.h
139+
${CMAKE_CURRENT_SOURCE_DIR}/generatorcontext_p.h
137140
${CMAKE_CURRENT_SOURCE_DIR}/generatorprofile_p.h
138141
${CMAKE_CURRENT_SOURCE_DIR}/generatorprofilesha1values.h
139142
${CMAKE_CURRENT_SOURCE_DIR}/generatorprofiletools.h

src/api/libcellml/generator.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ limitations under the License.
1616

1717
#pragma once
1818

19+
#include "libcellml/generatorcontext.h"
1920
#include "libcellml/logger.h"
2021

2122
namespace libcellml {
@@ -46,6 +47,24 @@ class LIBCELLML_EXPORT Generator: public Logger
4647
*/
4748
static GeneratorPtr create() noexcept;
4849

50+
/**
51+
* @brief Get the @ref GeneratorContext.
52+
*
53+
* Get the @ref GeneratorContext used by this @ref Generator.
54+
*
55+
* @return The @ref GeneratorContext used.
56+
*/
57+
GeneratorContextPtr context();
58+
59+
/**
60+
* @brief Set the @ref GeneratorContext.
61+
*
62+
* Set the @ref GeneratorContext to be used by this @ref Generator.
63+
*
64+
* @param context The @ref GeneratorContext to set.
65+
*/
66+
void setContext(const GeneratorContextPtr &context);
67+
4968
/**
5069
* @brief Get the @ref GeneratorProfile.
5170
*
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
Copyright libCellML Contributors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
#pragma once
18+
19+
#include "libcellml/logger.h"
20+
21+
namespace libcellml {
22+
23+
/**
24+
* @brief The GeneratorContext class.
25+
*
26+
* The GeneratorContext class is for representing a CellML GeneratorContext.
27+
*/
28+
class LIBCELLML_EXPORT GeneratorContext: public Logger
29+
{
30+
public:
31+
~GeneratorContext(); /**< Destructor, @private. */
32+
GeneratorContext(const GeneratorContext &rhs) = delete; /**< Copy constructor, @private. */
33+
GeneratorContext(GeneratorContext &&rhs) noexcept = delete; /**< Move constructor, @private. */
34+
GeneratorContext &operator=(GeneratorContext rhs) = delete; /**< Assignment operator, @private. */
35+
36+
/**
37+
* @brief Create a @ref GeneratorContext object.
38+
*
39+
* Factory method to create a @ref GeneratorContext. Create a GeneratorContext with::
40+
*
41+
* @code
42+
* auto GeneratorContext = libcellml::GeneratorContext::create();
43+
* @endcode
44+
*
45+
* @return A smart pointer to a @ref GeneratorContext object.
46+
*/
47+
static GeneratorContextPtr create() noexcept;
48+
49+
private:
50+
GeneratorContext(); /**< Constructor, @private. */
51+
52+
struct GeneratorContextImpl;
53+
54+
GeneratorContextImpl *pFunc(); /**< Getter for private implementation pointer, @private. */
55+
const GeneratorContextImpl *pFunc() const; /**< Const getter for private implementation pointer, @private. */
56+
};
57+
58+
} // namespace libcellml

src/api/libcellml/module/libcellml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ limitations under the License.
3434
#include "libcellml/component.h"
3535
#include "libcellml/enums.h"
3636
#include "libcellml/generator.h"
37+
#include "libcellml/generatorcontext.h"
3738
#include "libcellml/generatorprofile.h"
3839
#include "libcellml/importer.h"
3940
#include "libcellml/importsource.h"

src/api/libcellml/types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ using AnyCellmlElementPtr = std::shared_ptr<AnyCellmlElement>; /**< Type definit
4646

4747
class Generator; /**< Forward declaration of Generator class. */
4848
using GeneratorPtr = std::shared_ptr<Generator>; /**< Type definition for shared generator pointer. */
49+
class GeneratorContext; /**< Forward declaration of GeneratorContext class. */
50+
using GeneratorContextPtr = std::shared_ptr<GeneratorContext>; /**< Type definition for shared generator context pointer. */
4951
class GeneratorProfile; /**< Forward declaration of GeneratorProfile class. */
5052
using GeneratorProfilePtr = std::shared_ptr<GeneratorProfile>; /**< Type definition for shared generator variable pointer. */
5153
class Importer; /**< Forward declaration of Importer class. */

src/bindings/interface/generator.i

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@
66

77
%import "analysermodel.i"
88
%import "createconstructor.i"
9+
%import "generatorcontext.i"
910
%import "generatorprofile.i"
1011
%import "logger.i"
1112

1213
%feature("docstring") libcellml::Generator
1314
"Creates a :class:`Generator` object.";
1415

16+
%feature("docstring") libcellml::Generator::context
17+
"Returns the context used for code generation.";
18+
19+
%feature("docstring") libcellml::Generator::setContext
20+
"Sets the context to use for code generation.";
21+
1522
%feature("docstring") libcellml::Generator::profile
1623
"Returns the profile used for code generation.";
1724

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
%module(package="libcellml") generatorcontext
2+
3+
#define LIBCELLML_EXPORT
4+
5+
%import "createconstructor.i"
6+
%import "logger.i"
7+
8+
%feature("docstring") libcellml::GeneratorContext
9+
"Creates a :class:`GeneratorContext` object.";
10+
11+
%{
12+
#include "libcellml/generatorcontext.h"
13+
%}
14+
15+
%pythoncode %{
16+
# libCellML generated wrapper code starts here.
17+
%}
18+
19+
%create_constructor(GeneratorContext)
20+
21+
%include "libcellml/generatorcontext.h"

src/bindings/interface/types.i

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Provides support for shared pointers declared in types.h.
2525
%shared_ptr(libcellml::ComponentEntity)
2626
%shared_ptr(libcellml::Entity)
2727
%shared_ptr(libcellml::Generator)
28+
%shared_ptr(libcellml::GeneratorContext)
2829
%shared_ptr(libcellml::GeneratorProfile)
2930
%shared_ptr(libcellml::Importer)
3031
%shared_ptr(libcellml::ImportSource)

src/bindings/javascript/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ set(SOURCE_FILES
1212
${CMAKE_CURRENT_SOURCE_DIR}/entity.cpp
1313
${CMAKE_CURRENT_SOURCE_DIR}/enums.cpp
1414
${CMAKE_CURRENT_SOURCE_DIR}/generator.cpp
15+
${CMAKE_CURRENT_SOURCE_DIR}/generatorcontext.cpp
1516
${CMAKE_CURRENT_SOURCE_DIR}/generatorprofile.cpp
1617
${CMAKE_CURRENT_SOURCE_DIR}/importedentity.cpp
1718
${CMAKE_CURRENT_SOURCE_DIR}/importer.cpp

src/bindings/javascript/generator.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ limitations under the License.
1818

1919
#include "libcellml/analyserequationast.h"
2020
#include "libcellml/generator.h"
21+
#include "libcellml/generatorcontext.h"
2122
#include "libcellml/generatorprofile.h"
2223

2324
using namespace emscripten;
@@ -26,6 +27,8 @@ EMSCRIPTEN_BINDINGS(libcellml_generator)
2627
{
2728
class_<libcellml::Generator, base<libcellml::Logger>>("Generator")
2829
.smart_ptr_constructor("Generator", &libcellml::Generator::create)
30+
.function("context", &libcellml::Generator::context)
31+
.function("setContext", &libcellml::Generator::setContext)
2932
.function("profile", &libcellml::Generator::profile)
3033
.function("setProfile", &libcellml::Generator::setProfile)
3134
.function("isTrackedVariable", &libcellml::Generator::isTrackedVariable)

0 commit comments

Comments
 (0)