mirror of
https://github.com/Cantera/cantera.git
synced 2025-02-25 18:55:29 -06:00
[sourcegen] Differentiate CFunc.uses cases
This commit is contained in:
parent
eb8d6595b8
commit
fb95f34262
@ -9,11 +9,17 @@ base: Kinetics
|
||||
parents: [] # List of parent classes
|
||||
derived: [InterfaceKinetics] # List of specializations
|
||||
recipes:
|
||||
- name: nReactions
|
||||
- name: kineticsType # previously getType
|
||||
- name: nTotalSpecies # previously: nSpecies
|
||||
- name: nReactions
|
||||
- name: reaction # new
|
||||
uses: nReactions
|
||||
what: constructor # registers object in CLib storage
|
||||
- name: nPhases
|
||||
- name: phase
|
||||
uses: nPhases
|
||||
what: constructor # registers object in CLib storage
|
||||
- name: phaseIndex
|
||||
- name: nTotalSpecies # previously: nSpecies
|
||||
- name: reactantStoichCoeff
|
||||
- name: productStoichCoeff
|
||||
- name: getFwdRatesOfProgress
|
||||
@ -32,10 +38,6 @@ recipes:
|
||||
implements: Kinetics::kineticsSpeciesIndex(const string&)
|
||||
- name: advanceCoverages
|
||||
implements: InterfaceKinetics::advanceCoverages(double)
|
||||
- name: reaction # new
|
||||
what: constructor # registers object in CLib storage
|
||||
- name: phase
|
||||
what: constructor
|
||||
- name: getDeltaEnthalpy # previously: part of getDelta
|
||||
- name: getDeltaGibbs # previously: part of getDelta
|
||||
- name: getDeltaEntropy # previously: part of getDelta
|
||||
|
@ -38,7 +38,7 @@ recipes:
|
||||
- name: nAdjacent
|
||||
- name: adjacent
|
||||
implements: Solution::adjacent(size_t)
|
||||
uses: [thermo, kinetics, transport]
|
||||
uses: [nAdjacent, thermo, kinetics, transport]
|
||||
what: constructor # registers object in CLib storage
|
||||
- name: adjacentName
|
||||
- name: source
|
||||
|
@ -277,8 +277,15 @@ class CLibSourceGenerator(SourceGenerator):
|
||||
cxx_ix += 1
|
||||
|
||||
# Obtain class and getter for managed objects
|
||||
uses = [(shared_object(uu.ret_type), uu.name) for uu in c_func.uses]
|
||||
bases |= {uu[0] for uu in uses if uu[0]}
|
||||
shared = []
|
||||
checks = []
|
||||
for uu in c_func.uses:
|
||||
obj = shared_object(uu.ret_type)
|
||||
if obj:
|
||||
shared.append((obj, uu.name))
|
||||
bases |= {obj}
|
||||
else:
|
||||
checks.append(uu.name)
|
||||
|
||||
# Ensure that all error codes are set correctly
|
||||
error = [-1, "ERR"]
|
||||
@ -299,8 +306,8 @@ class CLibSourceGenerator(SourceGenerator):
|
||||
buffer = ["", "", "0"]
|
||||
|
||||
ret = {
|
||||
"handle": handle, "lines": lines, "buffer": buffer, "uses": uses,
|
||||
"base": base, "error": error,
|
||||
"base": base, "handle": handle, "lines": lines, "buffer": buffer,
|
||||
"shared": shared, "checks": checks, "error": error,
|
||||
"cxx_base": cxx_func.base, "cxx_name": cxx_func.name, "cxx_args": args,
|
||||
"cxx_implements": cxx_func.short_declaration(),
|
||||
"c_func": c_func.name, "c_args": [arg.name for arg in c_func.arglist],
|
||||
|
@ -139,7 +139,14 @@ clib-constructor: |-
|
||||
{% for line in lines %}
|
||||
{{ line }}
|
||||
{% endfor %}
|
||||
{% if uses %}
|
||||
{% if handle and checks %}
|
||||
if ({{ c_args[1] }} < 0 || {{ c_args[1] }} >= {{ base }}Cabinet::at({{ handle }})->{{ checks[0] }}()) {
|
||||
throw IndexError("{{ c_func }}", "", {{ c_args[1] }}, {{ base }}Cabinet::at({{ handle }})->{{ checks[0] }}() - 1);
|
||||
}
|
||||
{% else %}
|
||||
// no size checking specified
|
||||
{% endif %}
|
||||
{% if shared %}
|
||||
{% if handle %}
|
||||
auto obj = {{ base }}Cabinet::at({{ handle }})->{{ cxx_name }}({{ ', '.join(cxx_args) }});
|
||||
{% else %}
|
||||
@ -147,7 +154,7 @@ clib-constructor: |-
|
||||
{% endif %}
|
||||
int id = {{ base }}Cabinet::add(obj);
|
||||
// add all associated objects
|
||||
{% for typ, getter in uses %}
|
||||
{% for typ, getter in shared %}
|
||||
if (obj->{{ getter }}()) {
|
||||
{{ typ }}Cabinet::add(obj->{{ getter }}(), id);
|
||||
}
|
||||
@ -167,10 +174,10 @@ clib-constructor: |-
|
||||
clib-destructor: |-
|
||||
// destructor
|
||||
try {
|
||||
{% if uses %}
|
||||
{% if shared %}
|
||||
auto obj = {{ base }}Cabinet::at({{ handle }});
|
||||
// remove all associated objects in reversed order
|
||||
{% for typ, getter in uses[-1::-1] %}
|
||||
{% for typ, getter in shared[-1::-1] %}
|
||||
if (obj->{{ getter }}()) {
|
||||
int index = {{ typ }}Cabinet::index(*(obj->{{ getter }}()), {{ handle }});
|
||||
if (index >= 0) {
|
||||
@ -228,11 +235,9 @@ clib-array-getter: |-
|
||||
{% else %}
|
||||
auto obj = {{ base }}Cabinet::as<{{ cxx_base }}>({{ handle }});
|
||||
{% endif %}
|
||||
{% if uses %}
|
||||
if ({{ c_args[1] }} < obj->{{ uses[0][1] }}()) {
|
||||
throw CanteraError("{{ c_func }}",
|
||||
"Invalid output array size; expected minimum size {} but received {}.",
|
||||
obj->{{ uses[0][1] }}(), {{ c_args[1] }});
|
||||
{% if checks %}
|
||||
if ({{ c_args[1] }} < obj->{{ checks[0] }}()) {
|
||||
throw ArraySizeError("{{ c_func }}", {{ c_args[1] }}, obj->{{ checks[0] }}());
|
||||
}
|
||||
{% else %}
|
||||
// no size checking specified
|
||||
@ -259,11 +264,9 @@ clib-array-setter: |-
|
||||
{% else %}
|
||||
auto obj = {{ base }}Cabinet::as<{{ cxx_base }}>({{ handle }});
|
||||
{% endif %}
|
||||
{% if uses %}
|
||||
if ({{ c_args[1] }} != obj->{{ uses[0][1] }}()) {
|
||||
throw CanteraError("{{ c_func }}",
|
||||
"Invalid input array size; expected size {} but received {}.",
|
||||
obj->{{ uses[0][1] }}(), {{ c_args[1] }});
|
||||
{% if checks %}
|
||||
if ({{ c_args[1] }} != obj->{{ checks[0] }}()) {
|
||||
throw ArraySizeError("{{ c_func }}", {{ c_args[1] }}, obj->{{ checks[0] }}());
|
||||
}
|
||||
{% else %}
|
||||
// no size checking specified
|
||||
|
Loading…
Reference in New Issue
Block a user