Cantera  3.1.0a1
Loading...
Searching...
No Matches
ExtensionManager.cpp
Go to the documentation of this file.
1//! @file ExtensionManager.cpp
2
3// This file is part of Cantera. See License.txt in the top-level directory or
4// at https://cantera.org/license.txt for license and copyright information.
5
8
9namespace Cantera
10{
11
12map<string, function<void(ReactionDataDelegator&)>> ExtensionManager::s_ReactionData_linkers = {};
13map<string, function<shared_ptr<ExternalHandle>(shared_ptr<Solution>)>> ExtensionManager::s_Solution_linkers = {};
14map<string, string> ExtensionManager::s_userTypeToWrapperType = {};
15
16void ExtensionManager::wrapReactionData(const string& rateName,
18{
19 if (s_ReactionData_linkers.count(rateName) != 0) {
20 s_ReactionData_linkers.at(rateName)(data);
21 } else {
22 throw CanteraError("ExtensionManager::wrapReactionData",
23 "No ReactionData delegator for type {} registered",
24 rateName);
25 }
26}
27
29 const string& wrapperName, function<void(ReactionDataDelegator& delegator)> link)
30{
31 s_ReactionData_linkers[rateName] = link;
32 s_userTypeToWrapperType[rateName] = wrapperName;
33}
34
35shared_ptr<ExternalHandle> ExtensionManager::wrapSolution(
36 const string& rateName, shared_ptr<Solution> soln)
37{
38 if (s_Solution_linkers.count(rateName) != 0) {
39 return s_Solution_linkers.at(rateName)(soln);
40 } else {
41 throw CanteraError("ExtensionManager::wrapSolution",
42 "No Solution linker for type {} registered",
43 rateName);
44 }
45}
46
47void ExtensionManager::registerSolutionLinker(const string& rateName,
48 function<shared_ptr<ExternalHandle>(shared_ptr<Solution>)> link)
49{
50 s_Solution_linkers[rateName] = link;
51}
52
53string ExtensionManager::getSolutionWrapperType(const string& userType)
54{
55 if (s_userTypeToWrapperType.count(userType)) {
56 return s_userTypeToWrapperType[userType];
57 } else {
58 throw CanteraError("ExtensionManager::getSolutionWrapperType",
59 "No Solution linker for type {} registered", userType);
60 }
61}
62
63}
Base class for exceptions thrown by Cantera classes.
static void registerSolutionLinker(const string &wrapperName, function< shared_ptr< ExternalHandle >(shared_ptr< Solution >)> link)
Register a function that can be used to create wrappers for Solution objects in an external language ...
static void wrapReactionData(const string &rateName, ReactionDataDelegator &data)
Create an object in an external language that wraps the specified ReactionData object.
static map< string, string > s_userTypeToWrapperType
Mapping from user-defined rate types to Solution wrapper types.
static string getSolutionWrapperType(const string &userType)
Get the Solution wrapper type corresponding to the specified user-defined reaction rate type.
static void registerReactionDataLinker(const string &rateName, const string &wrapperName, function< void(ReactionDataDelegator &)> link)
Register a function that can be used to create wrappers for ReactionData objects in an external langu...
static map< string, function< shared_ptr< ExternalHandle >(shared_ptr< Solution >)> > s_Solution_linkers
Functions for wrapping and linking Solution objects.
static shared_ptr< ExternalHandle > wrapSolution(const string &wrapperType, shared_ptr< Solution > soln)
Create an object in an external language that wraps the specified Solution object.
static map< string, function< void(ReactionDataDelegator &)> > s_ReactionData_linkers
Functions for wrapping and linking ReactionData objects.
Delegate methods of the ReactionData class to external functions.
This file contains definitions for utility functions and text for modules, inputfiles and logging,...
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564