-------------------------------------------------------------------------------------- Description: Re-compiles muParser with a new expression. Arguments: parser - A parser expression - Expression to compile --------------------------------------------------------------------------------------
| 186 | // expression - Expression to compile |
| 187 | // -------------------------------------------------------------------------------------- |
| 188 | void Tr2ScalarExprKey::SetExpression( CcpParser::Program& parser, std::string& expression ) |
| 189 | { |
| 190 | if( expression.empty() ) |
| 191 | { |
| 192 | parser = {}; |
| 193 | return; |
| 194 | } |
| 195 | CcpParser::Variable s_variables[] = { |
| 196 | { "value", 0, offsetof( VariableBuffer, m_value ) }, |
| 197 | { "time", 0, offsetof( VariableBuffer, m_time ) }, |
| 198 | { "input1", 0, offsetof( VariableBuffer, m_inputVar1 ) }, |
| 199 | { "input2", 0, offsetof( VariableBuffer, m_inputVar2 ) }, |
| 200 | { "input3", 0, offsetof( VariableBuffer, m_inputVar3 ) }, |
| 201 | { "input4", 0, offsetof( VariableBuffer, m_inputVar4 ) }, |
| 202 | { "randomConstant", 0, offsetof( VariableBuffer, m_randomConstant ) }, |
| 203 | { "leftTangent", 0, offsetof( VariableBuffer, m_leftTangent ) }, |
| 204 | { "rightTangent", 0, offsetof( VariableBuffer, m_rightTangent ) }, |
| 205 | { "prevKeyTime", 0, offsetof( VariableBuffer, m_prevKeyTime ) }, |
| 206 | { "prevKeyValue", 0, offsetof( VariableBuffer, m_prevKeyValue ) }, |
| 207 | }; |
| 208 | |
| 209 | CcpParser::FunctionView functionView[] = { s_functions }; |
| 210 | CcpParser::ConstantView constantView[] = { s_constants }; |
| 211 | CcpParser::VariableView variableView[] = { s_variables }; |
| 212 | |
| 213 | CcpParser::Externals externals; |
| 214 | externals.functions = functionView; |
| 215 | externals.variables = variableView; |
| 216 | externals.constants = constantView; |
| 217 | auto result = CcpParser::Parse( expression.c_str(), externals, parser ); |
| 218 | if( !result ) |
| 219 | { |
| 220 | CCP_LOGERR( "Tr2ScalarExprKey expression: %s", ToString( result, expression.c_str() ).c_str() ); |
| 221 | return; |
| 222 | } |
| 223 | size_t arenaSize = 0; |
| 224 | arenaSize = std::max( arenaSize, m_timeParser.GetTempArenaSize() ); |
| 225 | arenaSize = std::max( arenaSize, m_valueParser.GetTempArenaSize() ); |
| 226 | arenaSize = std::max( arenaSize, m_leftTangentParser.GetTempArenaSize() ); |
| 227 | arenaSize = std::max( arenaSize, m_rightTangentParser.GetTempArenaSize() ); |
| 228 | if( m_tempArena.size() < arenaSize ) |
| 229 | { |
| 230 | m_tempArena.resize( arenaSize ); |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | // -------------------------------------------------------------------------------------- |
| 235 | // Description: |