| Cantera 3.0.0

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
6#include "cantera/base/ExtensionManager.h"
7#include "cantera/base/global.h"
8
9 namespace 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
16 void ExtensionManager::wrapReactionData(const string& rateName,
17 ReactionDataDelegator& data)
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
28 void ExtensionManager::registerReactionDataLinker(const string& rateName,
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
47 void ExtensionManager::registerSolutionLinker(const string& rateName,
48 function<shared_ptr<ExternalHandle>(shared_ptr<Solution>)> link)
49{
50 s_Solution_linkers[rateName] = link;
51}
52
53 string 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}
ExtensionManager.h
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition ctexceptions.h:66
Cantera::ExtensionManager::registerSolutionLinker
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 ...
Definition ExtensionManager.cpp:47
Cantera::ExtensionManager::wrapReactionData
static void wrapReactionData(const string &rateName, ReactionDataDelegator &data)
Create an object in an external language that wraps the specified ReactionData object.
Definition ExtensionManager.cpp:16
Cantera::ExtensionManager::s_userTypeToWrapperType
static map< string, string > s_userTypeToWrapperType
Mapping from user-defined rate types to Solution wrapper types.
Definition ExtensionManager.h:117
Cantera::ExtensionManager::getSolutionWrapperType
static string getSolutionWrapperType(const string &userType)
Get the Solution wrapper type corresponding to the specified user-defined reaction rate type.
Definition ExtensionManager.cpp:53
Cantera::ExtensionManager::registerReactionDataLinker
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...
Definition ExtensionManager.cpp:28
Cantera::ExtensionManager::s_Solution_linkers
static map< string, function< shared_ptr< ExternalHandle >(shared_ptr< Solution >)> > s_Solution_linkers
Functions for wrapping and linking Solution objects.
Definition ExtensionManager.h:114
Cantera::ExtensionManager::wrapSolution
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.
Definition ExtensionManager.cpp:35
Cantera::ExtensionManager::s_ReactionData_linkers
static map< string, function< void(ReactionDataDelegator &)> > s_ReactionData_linkers
Functions for wrapping and linking ReactionData objects.
Definition ExtensionManager.h:110
Cantera::ReactionDataDelegator
Delegate methods of the ReactionData class to external functions.
Definition ReactionRateDelegator.h:20
global.h
This file contains definitions for utility functions and text for modules, inputfiles and logging,...
Cantera
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564