Skip to content

Commit d82485b

Browse files
committed
Generator: specify tracked/untracked variables.
1 parent 9df5d4e commit d82485b

File tree

4 files changed

+403
-22
lines changed

4 files changed

+403
-22
lines changed

src/api/libcellml/generator.h

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,102 @@ class LIBCELLML_EXPORT Generator
8989
*/
9090
bool untrackVariable(const AnalyserVariablePtr &variable);
9191

92+
/**
93+
* @brief Track all the constants in the given @p model.
94+
*
95+
* Track all the constants in the given @p model. This will add all the constants in the model to the list of
96+
* tracked variables.
97+
*
98+
* @param model The pointer to the @ref AnalyserModel which all the constants are to be tracked.
99+
*
100+
* @return @c true if all the constants in the model were tracked, @c false otherwise.
101+
*/
102+
bool trackAllConstants(const AnalyserModelPtr &model);
103+
104+
/**
105+
* @brief Untrack all the constants in the given @p model.
106+
*
107+
* Untrack all the constants in the given @p model. This will remove all the constants in the model from the list of
108+
* tracked variables.
109+
*
110+
* @param model The pointer to the @ref AnalyserModel which all the constants are to be untracked.
111+
*
112+
* @return @c true if all the constants in the model were untracked, @c false otherwise.
113+
*/
114+
bool untrackAllConstants(const AnalyserModelPtr &model);
115+
116+
/**
117+
* @brief Track all the computed constants in the given @p model.
118+
*
119+
* Track all the computed constants in the given @p model. This will add all the computed constants in the model to
120+
* the list of tracked variables.
121+
*
122+
* @param model The pointer to the @ref AnalyserModel which all the computed constants are to be tracked.
123+
*
124+
* @return @c true if all the computed constants in the model were tracked, @c false otherwise.
125+
*/
126+
bool trackAllComputedConstants(const AnalyserModelPtr &model);
127+
128+
/**
129+
* @brief Untrack all the computed constants in the given @p model.
130+
*
131+
* Untrack all the computed constants in the given @p model. This will remove all the computed constants in the model
132+
* from the list of tracked variables.
133+
*
134+
* @param model The pointer to the @ref AnalyserModel which all the computed constants are to be untracked.
135+
*
136+
* @return @c true if all the computed constants in the model were untracked, @c false otherwise.
137+
*/
138+
bool untrackAllComputedConstants(const AnalyserModelPtr &model);
139+
140+
/**
141+
* @brief Track all the algebraic variables in the given @p model.
142+
*
143+
* Track all the algebraic variables in the given @p model. This will add all the algebraic variables in the model to
144+
* the list of tracked variables.
145+
*
146+
* @param model The pointer to the @ref AnalyserModel which all the algebraic variables are to be tracked.
147+
*
148+
* @return @c true if all the algebraic variables in the model were tracked, @c false otherwise.
149+
*/
150+
bool trackAllAlgebraic(const AnalyserModelPtr &model);
151+
152+
/**
153+
* @brief Untrack all the algebraic variables in the given @p model.
154+
*
155+
* Untrack all the algebraic variables in the given @p model. This will remove all the algebraic variables in the
156+
* model from the list of tracked variables.
157+
*
158+
* @param model The pointer to the @ref AnalyserModel which all the algebraic variables are to be untracked.
159+
*
160+
* @return @c true if all the algebraic variables in the model were untracked, @c false otherwise.
161+
*/
162+
bool untrackAllAlgebraic(const AnalyserModelPtr &model);
163+
164+
/**
165+
* @brief Track all the external variables in the given @p model.
166+
*
167+
* Track all the external variables in the given @p model. This will add all the external variables in the model to
168+
* the list of tracked variables.
169+
*
170+
* @param model The pointer to the @ref AnalyserModel which all the external variables are to be tracked.
171+
*
172+
* @return @c true if all the external variables in the model were tracked, @c false otherwise.
173+
*/
174+
bool trackAllExternals(const AnalyserModelPtr &model);
175+
176+
/**
177+
* @brief Untrack all the external variables in the given @p model.
178+
*
179+
* Untrack all the external variables in the given @p model. This will remove all the external variables in the model
180+
* from the list of tracked variables.
181+
*
182+
* @param model The pointer to the @ref AnalyserModel which all the external variables are to be untracked.
183+
*
184+
* @return @c true if all the external variables in the model were untracked, @c false otherwise.
185+
*/
186+
bool untrackAllExternals(const AnalyserModelPtr &model);
187+
92188
/**
93189
* @brief Track all the variables in the given @p model.
94190
*

src/generator.cpp

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,98 @@ bool Generator::GeneratorImpl::untrackVariable(const AnalyserVariablePtr &variab
7272
return doTrackVariable(variable, false);
7373
}
7474

75+
bool Generator::GeneratorImpl::doTrackAllConstants(const AnalyserModelPtr &model, bool tracked)
76+
{
77+
if (model == nullptr) {
78+
return false;
79+
}
80+
81+
for (const auto &constant : model->constants()) {
82+
doTrackVariable(constant, tracked);
83+
}
84+
85+
return true;
86+
}
87+
88+
bool Generator::GeneratorImpl::trackAllConstants(const AnalyserModelPtr &model)
89+
{
90+
return doTrackAllConstants(model, true);
91+
}
92+
93+
bool Generator::GeneratorImpl::untrackAllConstants(const AnalyserModelPtr &model)
94+
{
95+
return doTrackAllConstants(model, false);
96+
}
97+
98+
bool Generator::GeneratorImpl::doTrackAllComputedConstants(const AnalyserModelPtr &model, bool tracked)
99+
{
100+
if (model == nullptr) {
101+
return false;
102+
}
103+
104+
for (const auto &computedConstant : model->computedConstants()) {
105+
doTrackVariable(computedConstant, tracked);
106+
}
107+
108+
return true;
109+
}
110+
111+
bool Generator::GeneratorImpl::trackAllComputedConstants(const AnalyserModelPtr &model)
112+
{
113+
return doTrackAllComputedConstants(model, true);
114+
}
115+
116+
bool Generator::GeneratorImpl::untrackAllComputedConstants(const AnalyserModelPtr &model)
117+
{
118+
return doTrackAllComputedConstants(model, false);
119+
}
120+
121+
bool Generator::GeneratorImpl::doTrackAllAlgebraic(const AnalyserModelPtr &model, bool tracked)
122+
{
123+
if (model == nullptr) {
124+
return false;
125+
}
126+
127+
for (const auto &algebraic : model->algebraic()) {
128+
doTrackVariable(algebraic, tracked);
129+
}
130+
131+
return true;
132+
}
133+
134+
bool Generator::GeneratorImpl::trackAllAlgebraic(const AnalyserModelPtr &model)
135+
{
136+
return doTrackAllAlgebraic(model, true);
137+
}
138+
139+
bool Generator::GeneratorImpl::untrackAllAlgebraic(const AnalyserModelPtr &model)
140+
{
141+
return doTrackAllAlgebraic(model, false);
142+
}
143+
144+
bool Generator::GeneratorImpl::doTrackAllExternals(const AnalyserModelPtr &model, bool tracked)
145+
{
146+
if (model == nullptr) {
147+
return false;
148+
}
149+
150+
for (const auto &external : model->externals()) {
151+
doTrackVariable(external, tracked);
152+
}
153+
154+
return true;
155+
}
156+
157+
bool Generator::GeneratorImpl::trackAllExternals(const AnalyserModelPtr &model)
158+
{
159+
return doTrackAllExternals(model, true);
160+
}
161+
162+
bool Generator::GeneratorImpl::untrackAllExternals(const AnalyserModelPtr &model)
163+
{
164+
return doTrackAllExternals(model, false);
165+
}
166+
75167
bool Generator::GeneratorImpl::doTrackAllVariables(const AnalyserModelPtr &model, bool tracked)
76168
{
77169
if (model == nullptr) {
@@ -2116,6 +2208,46 @@ bool Generator::untrackVariable(const AnalyserVariablePtr &variable)
21162208
return mPimpl->untrackVariable(variable);
21172209
}
21182210

2211+
bool Generator::trackAllConstants(const AnalyserModelPtr &model)
2212+
{
2213+
return mPimpl->trackAllConstants(model);
2214+
}
2215+
2216+
bool Generator::untrackAllConstants(const AnalyserModelPtr &model)
2217+
{
2218+
return mPimpl->untrackAllConstants(model);
2219+
}
2220+
2221+
bool Generator::trackAllComputedConstants(const AnalyserModelPtr &model)
2222+
{
2223+
return mPimpl->trackAllComputedConstants(model);
2224+
}
2225+
2226+
bool Generator::untrackAllComputedConstants(const AnalyserModelPtr &model)
2227+
{
2228+
return mPimpl->untrackAllComputedConstants(model);
2229+
}
2230+
2231+
bool Generator::trackAllAlgebraic(const AnalyserModelPtr &model)
2232+
{
2233+
return mPimpl->trackAllAlgebraic(model);
2234+
}
2235+
2236+
bool Generator::untrackAllAlgebraic(const AnalyserModelPtr &model)
2237+
{
2238+
return mPimpl->untrackAllAlgebraic(model);
2239+
}
2240+
2241+
bool Generator::trackAllExternals(const AnalyserModelPtr &model)
2242+
{
2243+
return mPimpl->trackAllExternals(model);
2244+
}
2245+
2246+
bool Generator::untrackAllExternals(const AnalyserModelPtr &model)
2247+
{
2248+
return mPimpl->untrackAllExternals(model);
2249+
}
2250+
21192251
bool Generator::trackAllVariables(const AnalyserModelPtr &model)
21202252
{
21212253
return mPimpl->trackAllVariables(model);

src/generator_p.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,26 @@ struct Generator::GeneratorImpl
4646
bool trackVariable(const AnalyserVariablePtr &variable);
4747
bool untrackVariable(const AnalyserVariablePtr &variable);
4848

49+
bool doTrackAllConstants(const AnalyserModelPtr &model, bool tracked);
50+
51+
bool trackAllConstants(const AnalyserModelPtr &model);
52+
bool untrackAllConstants(const AnalyserModelPtr &model);
53+
54+
bool doTrackAllComputedConstants(const AnalyserModelPtr &model, bool tracked);
55+
56+
bool trackAllComputedConstants(const AnalyserModelPtr &model);
57+
bool untrackAllComputedConstants(const AnalyserModelPtr &model);
58+
59+
bool doTrackAllAlgebraic(const AnalyserModelPtr &model, bool tracked);
60+
61+
bool trackAllAlgebraic(const AnalyserModelPtr &model);
62+
bool untrackAllAlgebraic(const AnalyserModelPtr &model);
63+
64+
bool doTrackAllExternals(const AnalyserModelPtr &model, bool tracked);
65+
66+
bool trackAllExternals(const AnalyserModelPtr &model);
67+
bool untrackAllExternals(const AnalyserModelPtr &model);
68+
4969
bool doTrackAllVariables(const AnalyserModelPtr &model, bool tracked);
5070

5171
bool trackAllVariables(const AnalyserModelPtr &model);

0 commit comments

Comments
 (0)