47 assert(m_Parent !=
this);
50 Substitutions(
const std::vector<FunctionTemplate> &functions) : m_Parent(nullptr)
53 for(
const auto &f: functions) {
54 addFuncSubstitution(f.genericName, f.numArguments, f.funcTemplate);
63 const std::string &destPrefix =
"",
const std::string &destSuffix =
"")
65 for(
const auto &v : variables) {
66 addVarSubstitution(v.name + sourceSuffix,
67 destPrefix + v.name + destSuffix);
71 template<
typename T,
typename S>
73 const std::string &destPrefix, S getDestSuffixFn)
75 for(
const auto &v : variables) {
76 addVarSubstitution(v.name + sourceSuffix,
77 destPrefix + v.name + getDestSuffixFn(v.access));
83 const std::string &sourceSuffix =
"")
85 if(variables.size() != values.size()) {
86 throw std::runtime_error(
"Number of variables does not match number of values");
89 auto var = variables.cbegin();
90 auto val = values.cbegin();
91 for (;var != variables.cend() && val != values.cend(); var++, val++) {
92 addVarSubstitution(var->name + sourceSuffix,
97 void addParamValueSubstitution(
const std::vector<std::string> ¶mNames,
const std::vector<double> &values,
98 const std::string &sourceSuffix =
"");
102 const std::string &sourceSuffix =
"",
const std::string &destPrefix =
"",
const std::string &destSuffix =
"")
104 if(paramNames.size() != values.size()) {
105 throw std::runtime_error(
"Number of parameters does not match number of values");
108 for(
size_t i = 0; i < paramNames.size(); i++) {
109 if(isHeterogeneousFn(i)) {
110 addVarSubstitution(paramNames[i] + sourceSuffix,
111 destPrefix + paramNames[i] + destSuffix);
114 addVarSubstitution(paramNames[i] + sourceSuffix,
120 template<
typename T,
typename G>
122 const std::string &sourceSuffix =
"",
const std::string &destPrefix =
"",
const std::string &destSuffix =
"")
124 if(variables.size() != values.size()) {
125 throw std::runtime_error(
"Number of variables does not match number of values");
128 for(
size_t i = 0; i < variables.size(); i++) {
129 if(isHeterogeneousFn(i)) {
130 addVarSubstitution(variables[i].name + sourceSuffix,
131 destPrefix + variables[i].name + destSuffix);
134 addVarSubstitution(variables[i].name + sourceSuffix,
140 void addVarSubstitution(
const std::string &source,
const std::string &destionation,
bool allowOverride =
false);
141 void addFuncSubstitution(
const std::string &source,
unsigned int numArguments,
const std::string &funcTemplate,
bool allowOverride =
false);
142 bool hasVarSubstitution(
const std::string &source)
const;
144 const std::string &getVarSubstitution(
const std::string &source)
const;
146 void apply(std::string &code)
const;
147 void applyCheckUnreplaced(std::string &code,
const std::string &context)
const;
152 const std::string operator[] (
const std::string &source)
const 154 return getVarSubstitution(source);
161 void applyFuncs(std::string &code)
const;
162 void applyVars(std::string &code)
const;
167 std::map<std::string, std::string> m_VarSubstitutions;
168 std::map<std::string, std::pair<unsigned int, std::string>> m_FuncSubstitutions;
Substitutions(const Substitutions *parent=nullptr)
Definition: substitutions.h:45
const unsigned int numArguments
Number of function arguments.
Definition: substitutions.h:39
#define GENN_EXPORT
Definition: gennExport.h:13
void addParamValueSubstitution(const std::vector< std::string > ¶mNames, const std::vector< double > &values, G isHeterogeneousFn, const std::string &sourceSuffix="", const std::string &destPrefix="", const std::string &destSuffix="")
Definition: substitutions.h:101
void writePreciseString(std::ostream &os, T value)
This function writes a floating point value to a stream -setting the precision so no digits are lost...
Definition: gennUtils.h:92
Helper class for generating code - automatically inserts brackets, indents etc.
Definition: backendBase.h:30
Definition: substitutions.h:21
const std::string funcTemplate
The function template (for use with functionSubstitute) used when model uses double precision...
Definition: substitutions.h:42
void addVarValueSubstitution(const std::vector< T > &variables, const std::vector< double > &values, const std::string &sourceSuffix="")
Definition: substitutions.h:82
void addVarNameSubstitution(const std::vector< T > &variables, const std::string &sourceSuffix, const std::string &destPrefix, S getDestSuffixFn)
Definition: substitutions.h:72
Substitutions(const std::vector< FunctionTemplate > &functions)
Definition: substitutions.h:50
void addVarNameSubstitution(const std::vector< T > &variables, const std::string &sourceSuffix="", const std::string &destPrefix="", const std::string &destSuffix="")
Definition: substitutions.h:62
void addVarValueSubstitution(const std::vector< T > &variables, const std::vector< double > &values, G isHeterogeneousFn, const std::string &sourceSuffix="", const std::string &destPrefix="", const std::string &destSuffix="")
Definition: substitutions.h:121
const std::string genericName
Generic name used to refer to function in user code.
Definition: substitutions.h:36
Definition: substitutions.h:27