SAWYER_EXPORT std::string Grammar::evalFunction(TokenStream &tokens, ErrorLocation &eloc) const { ASSERT_require(tokens.isa(TOK_FUNCTION)); std::string funcName = tokens.lexeme(); ASSERT_require(funcName.size() >= 2 && '@' == funcName[0]); funcName = funcName.substr(1); tokens.consume(); // Get the function declaration const Function::Ptr func = functions_.getOrDefault(funcName); if (!func) throw SyntaxError("function \"" + funcName + "\" is not declared"); // Parse the actual arguments std::vector<std::string> actuals; while (tokens.isa(TOK_LEFT)) { tokens.consume(); if (func->isMacro()) { actuals.push_back(readArgument(tokens, eloc, CONSUME)); } else { actuals.push_back(evalArgument(tokens, eloc, CONSUME)); } } func->validateArgs(actuals, tokens); ErrorLocation::Trap t(eloc, tokens, "in function \"" + funcName + "\""); std::string retval = func->eval(*this, actuals); t.passed(); return retval; }
ManyRestraintsBase::ManyRestraintsBase(const ActionOptions& ao): Action(ao), ActionWithValue(ao), ActionPilot(ao), ActionWithVessel(ao), ActionWithInputVessel(ao) { // Read in the vessel we are action on readArgument("bridge"); aves=dynamic_cast<ActionWithVessel*>( getDependencies()[0] ); plumed_assert( getDependencies().size()==1 && aves ); log.printf(" adding restraints on variables calculated by %s action with label %s\n", aves->getName().c_str(),aves->getLabel().c_str()); // Add a task list in order to avoid problems for(unsigned i=0; i<aves->getFullNumberOfTasks(); ++i) addTaskToList( aves->getTaskCode(i) ); // And turn on the derivatives (note problems here because of ActionWithValue) turnOnDerivatives(); needsDerivatives(); // Now create the vessel std::string fake_input="LABEL=bias"; addVessel( "SUM", fake_input, 0 ); readVesselKeywords(); }
shared_ptr<IfcElectricCurrentMeasure> IfcElectricCurrentMeasure::createObjectFromStepData( const std::string& arg ) { // read TYPE if( arg.compare( "$" ) == 0 ) { return shared_ptr<IfcElectricCurrentMeasure>(); } auto type_object = std::make_shared<IfcElectricCurrentMeasure>(); type_object->readArgument( arg ); return type_object; }
shared_ptr<IfcTextDecoration> IfcTextDecoration::createObjectFromStepData( const std::string& arg ) { // read TYPE if( arg.compare( "$" ) == 0 ) { return shared_ptr<IfcTextDecoration>(); } auto type_object = std::make_shared<IfcTextDecoration>(); type_object->readArgument( arg ); return type_object; }
shared_ptr<IfcModulusOfLinearSubgradeReactionMeasure> IfcModulusOfLinearSubgradeReactionMeasure::createObjectFromStepData( const std::string& arg ) { // read TYPE if( arg.compare( "$" ) == 0 ) { return shared_ptr<IfcModulusOfLinearSubgradeReactionMeasure>(); } auto type_object = std::make_shared<IfcModulusOfLinearSubgradeReactionMeasure>(); type_object->readArgument( arg ); return type_object; }
shared_ptr<IfcBoxAlignment> IfcBoxAlignment::createObjectFromStepData( const std::string& arg ) { // read TYPE if( arg.compare( "$" ) == 0 ) { return shared_ptr<IfcBoxAlignment>(); } auto type_object = std::make_shared<IfcBoxAlignment>(); // read TYPE type_object->readArgument( arg ); return type_object; }
/** * Read an array from the byte stream. * @param types * @param i * @return an Array */ QList<QVariant> OSCByteArrayToMsgConverter::readArray(QByteArray& types, int i) { int arrayLen = 0; while(types.at(i+arrayLen)!= ']') arrayLen++; QList<QVariant> array; for(int j = 0; j < arrayLen; j++) { QVariant targm = readArgument(types.at(i+j)); if(!targm.isNull()) { array.append(targm); } } return array; }
int main(int argc, char *argv[]) { qInstallMessageHandler(emptyMessageHandler); QApplication app{argc, argv}; QTranslator qtTranslator; QTranslator chewingTranslator; loadTranslation(app, qtTranslator, chewingTranslator); readArgument(app); ChewingEditor w; w.show(); return app.exec(); }
void throttle() { int speed = readArgument(255); if(speed == 0){ digitalWrite(DRIVE_PIN1, 0); digitalWrite(DRIVE_PIN2, 0); } else if (speed > 0){ digitalWrite(DRIVE_PIN1, 1); digitalWrite(DRIVE_PIN2, 0); } else{ digitalWrite(DRIVE_PIN1, 0); digitalWrite(DRIVE_PIN2, 1); } analogWrite(DRIVE_ENABLE_PIN, abs(speed)); ping(); }
/** * Convert the byte array a simple message. Assumes that the byte array is a message. * @return a message containing the data specified in the byte stream */ OSCMessage& OSCByteArrayToMsgConverter::convertMessage() { OSCMessage* message = new OSCMessage(); QString addrStr = readString(); message->setAddress(addrStr); QByteArray types = readTypes(); if(types.isNull()) return *message; moveToFourByteBoundry(); for(int i = 0; i < types.length(); i++) { if('[' == types.at(i)) { // we're looking at an array -- read it in message->addArgument(readArray(types, ++i)); // then increment i to the end of the array while(']' != types.at(i)) i++; }else message->addArgument(readArgument(types.at(i))); } return *message; }
bool StaticRecordsReader::checkArguments(char *mem, qint64 memSize, qint64 pos, qint64 &readedSize, bool &success, QString argName, QVariant &argValue, SimpleEventInfo *info, quint8 eventID) { for(int i = 0; i < info[eventID].argsCount; i ++) { if(argName != info[eventID].argsInfo[i].name) { if(info[eventID].argsInfo[i].type == FIVE_BYTES_TYPE) { if(pos + 5 > memSize) return false; pos += 5; readedSize += 5; } else if(info[eventID].argsInfo[i].type == UINT8_TYPE) { if(qint64(pos + sizeof(quint8)) > memSize) return false; pos += sizeof(quint8); readedSize += sizeof(quint8); } else if(info[eventID].argsInfo[i].type == INT8_TYPE) { if(qint64(pos + sizeof(qint8)) > memSize) return false; pos += sizeof(qint8); readedSize += sizeof(qint8); } else if(info[eventID].argsInfo[i].type == UINT16_TYPE) { if(qint64(pos + sizeof(quint16)) > memSize) return false; pos += sizeof(quint16); readedSize += sizeof(quint16); } else if(info[eventID].argsInfo[i].type == UINT32_TYPE) { if(qint64(pos + sizeof(quint32)) > memSize) return false; pos += sizeof(quint32); readedSize += sizeof(quint32); } else if(info[eventID].argsInfo[i].type == UINT64_TYPE) { if(qint64(pos + sizeof(quint64)) > memSize) return false; pos += sizeof(quint64); readedSize += sizeof(quint64); } else if(info[eventID].argsInfo[i].type == INT32_TYPE) { if(qint64(pos + sizeof(qint32)) > memSize) return false; pos += sizeof(qint32); readedSize += sizeof(qint32); } else if(info[eventID].argsInfo[i].type == BOOL_TYPE) { if(qint64(pos + sizeof(bool)) > memSize) return false; pos += sizeof(bool); readedSize += sizeof(bool); } else if(info[eventID].argsInfo[i].type == DOUBLE_TYPE) { if(qint64(pos + sizeof(double)) > memSize) return false; pos += sizeof(double); readedSize += sizeof(double); } else if(info[eventID].argsInfo[i].type == BYTE_ARRAY_TYPE) { quint8 argSize = 0; if(!translateArg(mem, memSize, pos, argSize)) return false; pos += sizeof(quint8); readedSize += sizeof(quint8); if(pos + argSize > memSize) return false; pos += argSize; readedSize += argSize; } else if(info[eventID].argsInfo[i].type == STRING_TYPE) { quint16 argSize = 0; if(!translateArg(mem, memSize, pos, argSize)) return false; pos += sizeof(quint16); readedSize += sizeof(quint16); if(pos + argSize > memSize) return false; pos += argSize; readedSize += argSize; } } else { if(info[eventID].argsInfo[i].type == FIVE_BYTES_TYPE) { quint64 value = 0; if(!readArgumentUnusualSize(mem, memSize, pos, readedSize, value, 5)) return false; argValue = QVariant(value); success = true; } else if(info[eventID].argsInfo[i].type == UINT8_TYPE) { quint8 value = 0; if(!readArgument(mem, memSize, pos, readedSize, value)) return false; argValue = QVariant(value); success = true; } else if(info[eventID].argsInfo[i].type == INT8_TYPE) { qint8 value = 0; if(!readArgument(mem, memSize, pos, readedSize, value)) return false; argValue = QVariant(value); success = true; } else if(info[eventID].argsInfo[i].type == UINT16_TYPE) { quint16 value = 0; if(!readArgument(mem, memSize, pos, readedSize, value)) return false; argValue = QVariant(value); success = true; } else if(info[eventID].argsInfo[i].type == UINT32_TYPE) { quint32 value = 0; if(!readArgument(mem, memSize, pos, readedSize, value)) return false; argValue = QVariant(value); success = true; } else if(info[eventID].argsInfo[i].type == UINT64_TYPE) { quint64 value = 0; if(!readArgument(mem, memSize, pos, readedSize, value)) return false; argValue = QVariant(value); success = true; } else if(info[eventID].argsInfo[i].type == INT32_TYPE) { qint32 value = 0; if(!readArgument(mem, memSize, pos, readedSize, value)) return false; argValue = QVariant(value); success = true; } else if(info[eventID].argsInfo[i].type == BOOL_TYPE) { bool value = false; if(!readArgument(mem, memSize, pos, readedSize, value)) return false; argValue = QVariant(value); success = true; } else if(info[eventID].argsInfo[i].type == DOUBLE_TYPE) { double value = 0; if(!readArgument(mem, memSize, pos, readedSize, value)) return false; argValue = QVariant(value); success = true; } else if(info[eventID].argsInfo[i].type == BYTE_ARRAY_TYPE) { quint8 argSize = 0; if(!readArgument(mem, memSize, pos, readedSize, argSize)) return false; char *value = new char[argSize + 1]; if(!translateArg(mem, memSize, pos, value, argSize)) return false; pos += argSize; readedSize += argSize; argValue = QVariant(value); success = true; } else if(info[eventID].argsInfo[i].type == STRING_TYPE) { quint16 argSize = 0; if(!readArgument(mem, memSize, pos, readedSize, argSize)) return false; QString value; if(!translateArg(mem, memSize, pos, value, argSize)) return false; pos += argSize; readedSize += argSize; argValue = QVariant(value); success = true; } } } return true; }
bool StaticRecordsReader::readArguments(char *mem, qint64 memSize, qint64 pos, qint64 &readedSize, Record &record, SimpleEventInfo *info, quint8 eventID) { for(int i = 0; i < info[eventID].argsCount; i ++) { if(info[eventID].argsInfo[i].type == FIVE_BYTES_TYPE) { quint64 value = 0; qint64 temp = pos; if(!readArgumentUnusualSize(mem, memSize, pos, readedSize, value, 5)) return false; char *bytesValue = new char[5]; copyArg(mem, bytesValue, temp, 5); record.byteRecord.append(bytesValue, 5); record.other.append(QVariant(value)); delete[] bytesValue; } else if(info[eventID].argsInfo[i].type == UINT8_TYPE) { quint8 value = 0; qint64 temp = pos; if(!readArgument(mem, memSize, pos, readedSize, value)) return false; char *bytesValue = new char[sizeof(quint8)]; copyArg(mem, bytesValue, temp, sizeof(quint8)); record.byteRecord.append(bytesValue, sizeof(quint8)); record.other.append(QVariant(value)); delete[] bytesValue; } else if(info[eventID].argsInfo[i].type == INT8_TYPE) { qint8 value = 0; qint64 temp = pos; if(!readArgument(mem, memSize, pos, readedSize, value)) return false; char *bytesValue = new char[sizeof(qint8)]; copyArg(mem, bytesValue, temp, sizeof(qint8)); record.byteRecord.append(bytesValue, sizeof(qint8)); record.other.append(QVariant(value)); delete[] bytesValue; } else if(info[eventID].argsInfo[i].type == UINT16_TYPE) { quint16 value = 0; qint64 temp = pos; if(!readArgument(mem, memSize, pos, readedSize, value)) return false; char *bytesValue = new char[sizeof(quint16)]; copyArg(mem, bytesValue, temp, sizeof(quint16)); record.byteRecord.append(bytesValue, sizeof(quint16)); record.other.append(QVariant(value)); delete[] bytesValue; } else if(info[eventID].argsInfo[i].type == UINT32_TYPE) { quint32 value = 0; qint64 temp = pos; if(!readArgument(mem, memSize, pos, readedSize, value)) return false; char *bytesValue = new char[sizeof(quint32)]; copyArg(mem, bytesValue, temp, sizeof(quint32)); record.byteRecord.append(bytesValue, sizeof(quint32)); record.other.append(QVariant(value)); delete[] bytesValue; } else if(info[eventID].argsInfo[i].type == UINT64_TYPE) { quint64 value = 0; qint64 temp = pos; if(!readArgument(mem, memSize, pos, readedSize, value)) return false; char *bytesValue = new char[sizeof(quint64)]; copyArg(mem, bytesValue, temp, sizeof(quint64)); record.byteRecord.append(bytesValue, sizeof(quint64)); record.other.append(QVariant(value)); delete[] bytesValue; } else if(info[eventID].argsInfo[i].type == INT32_TYPE) { qint32 value = 0; qint64 temp = pos; if(!readArgument(mem, memSize, pos, readedSize, value)) return false; char *bytesValue = new char[sizeof(qint32)]; copyArg(mem, bytesValue, temp, sizeof(qint32)); record.byteRecord.append(bytesValue, sizeof(qint32)); record.other.append(QVariant(value)); delete[] bytesValue; } else if(info[eventID].argsInfo[i].type == BOOL_TYPE) { bool value = false; qint64 temp = pos; if(!readArgument(mem, memSize, pos, readedSize, value)) return false; char *bytesValue = new char[sizeof(bool)]; copyArg(mem, bytesValue, temp, sizeof(bool)); record.byteRecord.append(bytesValue, sizeof(bool)); record.other.append(QVariant(value)); delete[] bytesValue; } else if(info[eventID].argsInfo[i].type == DOUBLE_TYPE) { double value = 0; qint64 temp = pos; if(!readArgument(mem, memSize, pos, readedSize, value)) return false; char *bytesValue = new char[sizeof(double)]; copyArg(mem, bytesValue, temp, sizeof(double)); record.byteRecord.append(bytesValue, sizeof(double)); record.other.append(QVariant(value)); delete[] bytesValue; } else if(info[eventID].argsInfo[i].type == BYTE_ARRAY_TYPE) { quint8 argSize = 0; if(!readArgument(mem, memSize, pos, readedSize, argSize)) return false; char *value = new char[argSize + 1]; if(!translateArg(mem, memSize, pos, value, argSize)) return false; pos += argSize; readedSize += argSize; QByteArray arr(value, argSize); record.byteRecord.append(value, argSize); record.other.append(QVariant(arr)); delete[] value; } else if(info[eventID].argsInfo[i].type == STRING_TYPE) { quint16 argSize = 0; if(!readArgument(mem, memSize, pos, readedSize, argSize)) return false; char *byteValue = new char[argSize]; if(!translateArg(mem, memSize, pos, byteValue, argSize)) return false; record.byteRecord.append(byteValue, argSize); delete[] byteValue; QString value; if(!translateArg(mem, memSize, pos, value, argSize)) return false; pos += argSize; readedSize += argSize; record.other.append(QVariant(value)); } } return true; }
void steer() { int angle = readArgument(90); myservo.write(angle); ping(); }