BOOL COMotion::NormalizeKeys(float from_time, float to_time, float speed) { if (to_time<from_time) return FALSE; CEnvelope* E = Envelope(ctPositionX); float new_tm = 0; float t0 = E->keys.front()->time; FloatVec tms; tms.push_back (t0); for (KeyIt it=E->keys.begin()+1; it!=E->keys.end(); it++) { if ((*it)->time>from_time) { if ((*it)->time<to_time+EPS) { float dist = 0; Fvector PT,T,R; _Evaluate (t0, PT, R); for (float tm=t0+1.f/fFPS; tm<=(*it)->time; tm+=EPS_L) { _Evaluate (tm, T, R); dist += PT.distance_to(T); PT.set (T); } new_tm += dist / speed; t0 = (*it)->time; tms.push_back (new_tm); } else { float dt = (*it)->time-t0; t0 = (*it)->time; new_tm +=dt; tms.push_back (new_tm); } } } for (int ch = 0; ch < ctMaxChannel; ch++) { E = Envelope(EChannelType(ch)); FloatIt f_it = tms.begin(); VERIFY(tms.size()==E->keys.size()); for (KeyIt k_it=E->keys.begin(); k_it!=E->keys.end(); k_it++,f_it++) (*k_it)->time = *f_it; } /* CEnvelope* E = Envelope(); for (KeyIt it=E->keys.begin(); it!=E->keys.end(); it++){ if (((*it)->time>from_time)&&((*it)->time<to_time)){ for (float tm=from_time; tm<=to_time; tm+=1.f/fFPS){ } } */ return TRUE; }
/*static*/ float Calculator::Evaluate(const std::string& expression, std::string& errorMessage) { try { std::string _expression = expression; //we do not want to change input data //trim _expression.erase(std::remove_if(_expression.begin(), _expression.end(), isspace), _expression.end()); //tolower case because for example sin = Sin = SIN std::transform(_expression.begin(), _expression.end(), _expression.begin(), ::tolower); int startIndex = 0; int braceCount = 0; float value = _Evaluate(_expression, startIndex, braceCount); if (braceCount != 0) throw BracesException(); return value; } catch (CalculatorException& e) { errorMessage = e.what(); } catch (std::exception& e) { errorMessage = "Something went wrong: "; errorMessage.append(+e.what()); } return std::numeric_limits<float>::quiet_NaN(); }
bool ExprTree:: Evaluate( EvalState &state, Value &val, ExprTree *&sig ) const { double diff = 0; #ifndef WIN32 struct timeval begin, end; if (state.debug) { gettimeofday(&begin, NULL); } #endif bool eval = _Evaluate( state, val, sig ); #ifndef WIN32 if (state.debug) { gettimeofday(&end, NULL); diff = (end.tv_sec + (end.tv_usec * 0.000001)) - (begin.tv_sec + (begin.tv_usec * 0.000001)); } #endif if(state.debug && GetKind() != ExprTree::LITERAL_NODE && GetKind() != ExprTree::OP_NODE) { debug_format_value(val, diff); } return eval; }
bool ScriptManager::ExecuteScript(QString name) { if(name == "" || !HasScript(name)) { Logger::Get().Error("Cannot execute script \"" + name + "\": script not found."); return false; } return _Evaluate(mScripts[name]); }
bool ExprTree:: Evaluate( EvalState &state, Value &val, ExprTree *&sig ) const { bool eval = _Evaluate( state, val, sig ); if(state.debug && GetKind() != ExprTree::LITERAL_NODE && GetKind() != ExprTree::OP_NODE) { debug_format_value(val); } return eval; }
bool WQLCompile::evaluate(const WQLPropertySource& source) const { WQLOperand lhs, rhs; UInt32 tableauSize = _tableau.size(); if (tableauSize == 0) { return true; } for (UInt32 i = 0; i < tableauSize; i++) { TableauRow tr = _tableau[i]; bool b = true; for (UInt32 j=0,m = tr.size(); b && j < m; j++) { if (tr[j].op == WQL_ISA) { String propertyName = tr[j].opn1.getPropertyName(); String className; if (tr[j].opn2.getType() == WQLOperand::PROPERTY_NAME) { className = tr[j].opn2.getPropertyName(); } else { className = tr[j].opn2.getStringValue(); // this will throw if it's not a string } b = source.evaluateISA(propertyName, className); } else { lhs = tr[j].opn1; WQLCompile::_ResolveProperty(lhs,source); rhs = tr[j].opn2; WQLCompile::_ResolveProperty(rhs,source); if (rhs.getType() != lhs.getType()) { OW_THROW(TypeMismatchException, Format("Type mismatch: lhs: %1 rhs: %2", lhs.toString(), rhs.toString()).c_str()); } b = _Evaluate(lhs, rhs, tr[j].op); } } if (b) { return true; } } return false; }
status_t DwarfExpressionEvaluator::Evaluate(const void* expression, size_t size, target_addr_t& _result) { fDataReader.SetTo(expression, size, fContext->AddressSize()); try { status_t error = _Evaluate(NULL); if (error != B_OK) return error; _result = _Pop(); return B_OK; } catch (const EvaluationException& exception) { WARNING("DwarfExpressionEvaluator::Evaluate(): %s\n", exception.message); return B_BAD_VALUE; } catch (const std::bad_alloc& exception) { return B_NO_MEMORY; } }
status_t DwarfExpressionEvaluator::EvaluateLocation(const void* expression, size_t size, ValueLocation& _location) { _location.Clear(); // the empty expression is a valid one if (size == 0) { ValuePieceLocation piece; piece.SetToUnknown(); piece.SetSize(0); return _location.AddPiece(piece) ? B_OK : B_NO_MEMORY; } fDataReader.SetTo(expression, size, fContext->AddressSize()); // parse the first (and maybe only) expression try { // push the object address, if any target_addr_t objectAddress; if (fContext->GetObjectAddress(objectAddress)) _Push(objectAddress); ValuePieceLocation piece; status_t error = _Evaluate(&piece); if (error != B_OK) return error; // if that's all, it's only a simple expression without composition if (fDataReader.BytesRemaining() == 0) { if (!piece.IsValid()) piece.SetToMemory(_Pop()); piece.SetSize(0); return _location.AddPiece(piece) ? B_OK : B_NO_MEMORY; } // there's more, so it must be a composition operator uint8 opcode = fDataReader.Read<uint8>(0); if (opcode == DW_OP_piece) { piece.SetSize(fDataReader.ReadUnsignedLEB128(0)); } else if (opcode == DW_OP_bit_piece) { uint64 bitSize = fDataReader.ReadUnsignedLEB128(0); piece.SetSize(bitSize, fDataReader.ReadUnsignedLEB128(0)); } else return B_BAD_DATA; // If there's a composition operator, there must be at least two // simple expressions, so this must not be the end. if (fDataReader.BytesRemaining() == 0) return B_BAD_DATA; } catch (const EvaluationException& exception) { WARNING("DwarfExpressionEvaluator::EvaluateLocation(): %s\n", exception.message); return B_BAD_VALUE; } catch (const std::bad_alloc& exception) { return B_NO_MEMORY; } // parse subsequent expressions (at least one) while (fDataReader.BytesRemaining() > 0) { // Restrict the data reader to the remaining bytes to prevent jumping // back. fDataReader.SetTo(fDataReader.Data(), fDataReader.BytesRemaining(), fDataReader.AddressSize()); try { // push the object address, if any target_addr_t objectAddress; if (fContext->GetObjectAddress(objectAddress)) _Push(objectAddress); ValuePieceLocation piece; status_t error = _Evaluate(&piece); if (error != B_OK) return error; if (!piece.IsValid()) piece.SetToMemory(_Pop()); // each expression must be followed by a composition operator if (fDataReader.BytesRemaining() == 0) return B_BAD_DATA; uint8 opcode = fDataReader.Read<uint8>(0); if (opcode == DW_OP_piece) { piece.SetSize(fDataReader.ReadUnsignedLEB128(0)); } else if (opcode == DW_OP_bit_piece) { uint64 bitSize = fDataReader.ReadUnsignedLEB128(0); piece.SetSize(bitSize, fDataReader.ReadUnsignedLEB128(0)); } else return B_BAD_DATA; } catch (const EvaluationException& exception) { WARNING("DwarfExpressionEvaluator::EvaluateLocation(): %s\n", exception.message); return B_BAD_VALUE; } catch (const std::bad_alloc& exception) { return B_NO_MEMORY; } } return B_OK; }
bool ScriptManager::Evaluate(QString snippet, QString context) { return _Evaluate(QScriptProgram(snippet, context)); }
/*static*/ float Calculator::_Evaluate(const std::string& expression, int& index, int& braceCount) { std::vector<float> numbers; std::vector<OPERATION_TYPE> operations; bool isPriorityOperationPending = false; std::string number_str; std::string operation_str; for (index; index < expression.length(); ++index) { if (isdigit(expression[index]) || expression[index] == '.') number_str.push_back(expression[index]); else { if (expression[index] == '(') { _AddNumber(_Evaluate(expression, ++index, braceCount), numbers, operations, isPriorityOperationPending); ++index; --braceCount; if (index >= expression.length()) break; } else _AddNumber(number_str, numbers, operations, isPriorityOperationPending); if (expression[index] == ')') { ++braceCount; break; } OPERATION_TYPE operation = Calculator::_ParseSymbolOperation(expression[index]); if (operation == UKNOWN) { //this is not symbol operation. Ok. Maybe it is key-word operation then? //parse until next digit while (index != expression.length() && expression[index] != '(' && expression[index] != '.' && !isdigit(expression[index])) { operation_str.push_back(expression[index]); ++index; } --index; operation = Calculator::_ParseWordOperation(operation_str); if (operation == UKNOWN) { //unknown word? Bam! We dead. throw CalculatorException(index); } operation_str.clear(); } operations.push_back(operation); if (numbers.size() == 0) { if (!_IsUnaryOperation(operation) && operation != SUBSTRACTION) //We have binary operation but do not have left operand. Obviously an input data error throw ParseException(index); else if (operation == SUBSTRACTION) numbers.push_back(0.0f); } if (_IsHighPriorityOperation(operation)) { isPriorityOperationPending = true; } } } Calculator::_AddNumber(number_str, numbers, operations, isPriorityOperationPending); //vectors contains only numbers and simple binary operations return _Unwind(numbers, operations); }
bool Literal:: _Flatten( EvalState &state, Value &val, ExprTree *&tree, int*) const { tree = NULL; return( _Evaluate( state, val ) ); }
bool Literal:: _Evaluate( EvalState &state, Value &val, ExprTree *&tree ) const { _Evaluate( state, val ); return( ( tree = Copy() ) ); }
Boolean WQLSelectStatementRep::evaluateWhereClause( const WQLPropertySource* source) const { if (!hasWhereClause()) return true; Stack<Boolean> stack; stack.reserveCapacity(16); // // Counter for operands: // Uint32 j = 0; // // Process each of the operations: // for (Uint32 i = 0, n = _operations.size(); i < n; i++) { WQLOperation operation = _operations[i]; switch (operation) { case WQL_OR: { PEGASUS_ASSERT(stack.size() >= 2); Boolean operand1 = stack.top(); stack.pop(); Boolean operand2 = stack.top(); stack.top() = operand1 || operand2; break; } case WQL_AND: { PEGASUS_ASSERT(stack.size() >= 2); Boolean operand1 = stack.top(); stack.pop(); Boolean operand2 = stack.top(); stack.top() = operand1 && operand2; break; } case WQL_NOT: { PEGASUS_ASSERT(stack.size() >= 1); Boolean operand = stack.top(); stack.top() = !operand; break; } case WQL_EQ: case WQL_NE: case WQL_LT: case WQL_LE: case WQL_GT: case WQL_GE: case WQL_LIKE: { Array<WQLOperand> whereOperands(_operands); PEGASUS_ASSERT(whereOperands.size() >= 2); // // Resolve the left-hand-side to a value (if not already // a value). // WQLOperand& lhs = whereOperands[j++]; _ResolveProperty(lhs, source); // // Resolve the right-hand-side to a value (if not already // a value). // WQLOperand& rhs = whereOperands[j++]; _ResolveProperty(rhs, source); // // Check for a type mismatch: // // PEGASUS_OUT(lhs.toString()); // PEGASUS_OUT(rhs.toString()); if (rhs.getType() != lhs.getType()) throw TypeMismatchException(); if(operation == WQL_LIKE && (lhs.getType() != WQLOperand::STRING_VALUE)) { MessageLoaderParms parms( "WQL.WQLSelectStatementRep.PROP_NOT_FOUND", "LIKE syntax can only be used against string properties."); throw QueryRuntimeException(parms); } // // Now that the types are known to be alike, apply the // operation: // stack.push(_Evaluate(lhs, rhs, operation)); break; } case WQL_IS_TRUE: case WQL_IS_NOT_FALSE: { PEGASUS_ASSERT(stack.size() >= 1); break; } case WQL_IS_FALSE: case WQL_IS_NOT_TRUE: { PEGASUS_ASSERT(stack.size() >= 1); stack.top() = !stack.top(); break; } case WQL_IS_NULL: { Array<WQLOperand> whereOperands(_operands); PEGASUS_ASSERT(whereOperands.size() >= 1); WQLOperand& operand = whereOperands[j++]; _ResolveProperty(operand, source); stack.push(operand.getType() == WQLOperand::NULL_VALUE); break; } case WQL_IS_NOT_NULL: { Array<WQLOperand> whereOperands(_operands); PEGASUS_ASSERT(whereOperands.size() >= 1); WQLOperand& operand = whereOperands[j++]; _ResolveProperty(operand, source); stack.push(operand.getType() != WQLOperand::NULL_VALUE); break; } } } PEGASUS_ASSERT(stack.size() == 1); return stack.top(); }