QString Sequence::formatValue(const QString &value) { QString fmt_value; //Before format the value checks if it is valid if(isValidValue(value)) { unsigned i, count, neg_cnt; i=neg_cnt=0; count=value.size(); /* Counts the number of negative operator because the quantity can interfere on the final result of formating */ while((value[i]=='+' || value[i]=='-') && i < count) { if(value[i]=='-') neg_cnt++; i++; } //When the negative signal count is odd the number is negative if(neg_cnt % 2 != 0) fmt_value+=QString("-"); fmt_value+=value.mid(i, count); } return(fmt_value); }
/** * checks if the value passed is valid and if true * references the value field with the validValues[i] */ BOOL VapixAttribute::setValue(char* value) { int index = isValidValue(value); if(index >= 0) { this->value = validValues[index]; return TRUE; } return FALSE; }
bool isValidSudoku(Board board) { Block block; std::vector<int> column; std::vector<int> row; bool isValidSize = true; bool isValidBlock = true; bool isValidRow = true; bool isValidColums = true; std::vector<bool> blockValidationResults; std::vector<bool> columnValidationResults; std::vector<bool> rowValidationResults; if (board.size() != 9) { return false; } for (int i = 0; i < 9; i++) { auto row = board[i]; isValidSize = isValidSize && (row.size() == 9); } if (!isValidSize) { return false; } for (unsigned int col = 0; col < BOARD_SIZE; col++) { for (unsigned int row = 0; row < BOARD_SIZE; row++) { if (!isValidValue(board[row][col])) return false; } } for (unsigned int i = 0; i < 9; i++) { block = getBlock(board, i); blockValidationResults.push_back(checkBlock(block)); } for (unsigned int i = 0; i < 9; i++) { column = getColumn(board, i); columnValidationResults.push_back(checkColumn(column)); } for (int j = 0; j < 9; j++) { row = getRow(board, j); rowValidationResults.push_back(checkRow(row)); } return checkResults(blockValidationResults, columnValidationResults, rowValidationResults); }
/** * DA MIXER FUNCTION! * Compares to see if all validValues in the passed * attribute are valid in this instance, if they are * then the passed attribute is considered equal */ BOOL VapixAttribute::isEqual(VapixAttribute* attribute) { int vvSize = 0; char** vv = attribute->getValidValues(&vvSize); //check name first if(strcmp(name, attribute->getName()) != 0) return FALSE; //then check valid values for(int i=0; i<vvSize; i++) { if(isValidValue(vv[i]) < 0) { return FALSE; } } return TRUE; }
//static DbId::value_type DbId::valueOf(QVariant /*pass-by-value*/ variant) { // The parameter "variant" is passed by value since we need to use // the in place QVariant::convert(). Due to Qt's implicit sharing // the value is only copied if the type is different. The redundant // conversion inside value() is bypassed since the type already // matches. We cannot use value(), only because it returns the // valid id 0 in case of conversion errors. if (variant.convert(kVariantType)) { value_type value = variant.value<value_type>(); if (isValidValue(value)) { return value; } } return kInvalidValue; }
void PeriodTime::set(DeltaTime value) { assert(isValidValue(value)); _offset = value; }
int main(int argc,char **argv) { std::string ifile = ""; OpenBabel::OBSpectrophore::AccuracyOption accuracy = OpenBabel::OBSpectrophore::AngStepSize20; OpenBabel::OBSpectrophore::StereoOption stereo = OpenBabel::OBSpectrophore::NoStereoSpecificProbes; OpenBabel::OBSpectrophore::NormalizationOption normalization = OpenBabel::OBSpectrophore::NoNormalization; double resolution = 3.0; int c; opterr = 0; std::string msg; while ((c = getopt(argc, argv, "ui:n:a:s:r:h")) != -1) { switch (c) { case 'u': showImplementationDetails(argv[0]); exit(1); break; case 'i': if (!isValidValue('i', optarg)) { msg = "Option -i is followed by an invalid argument: "; msg += optarg; showError(msg); exit(1); } else { ifile = optarg; } break; case 'n': if (!isValidValue('n', optarg)) { msg = "Option -n is followed by an invalid argument: "; msg += optarg; showError(msg); exit(1); } else normalization = stringToNormalizationOption(optarg); break; case 'a': if (!isValidValue('a', optarg)) { msg = "Option -a is followed by an invalid argument: "; msg += optarg; showError(msg); exit(1); } else accuracy = stringToAccuracyOption(optarg); break; case 's': if (!isValidValue('s', optarg)) { msg = "Option -s is followed by an invalid argument: "; msg += optarg; showError(msg); exit(1); } else stereo = stringToStereoOption(optarg); break; case 'r': if (!isValidValue('r', optarg)) { msg = "Option -r is followed by an invalid argument: "; msg += optarg; showError(msg); exit(1); } else { resolution = atof(optarg); if (resolution <= 0) { msg = "Resolution -r should be larger than 0.0: "; msg += optarg; showError(msg); exit(1); } } break; case 'h': showHelp(argv[0]); exit(0); break; case '?': if ((optopt == 'i') || (optopt == 'n') || (optopt == 'a') || (optopt == 's') || (optopt == 'r')) { msg = "Option -"; msg += optopt; msg += " requires an argument."; showError(msg); exit(1); } else { msg = "Unknown option -"; msg += optopt; msg += "."; showError(msg); exit(1); } break; default: showError("Unknown option"); exit(1); break; } } // The input file (-i) is the only required option if (ifile.empty()) { msg = "Input file specification is required (option -i)."; showError(msg); exit(1); } OpenBabel::OBConversion obconversion; OpenBabel::OBFormat *format = obconversion.FormatFromExt(ifile.c_str()); if (!format) { msg = "Could not find file format for "; msg += ifile; showError(msg); exit(1); } obconversion.SetInFormat(format); std::ifstream ifs; ifs.open(ifile.c_str()); obconversion.SetInStream(&ifs); // Start calculations OpenBabel::OBMol mol; OpenBabel::OBSpectrophore spec; spec.SetAccuracy(accuracy); spec.SetNormalization(normalization); spec.SetStereo(stereo); spec.SetResolution(resolution); showParameters(spec, ifile); unsigned int count(0); while (obconversion.Read(&mol)) { std::vector<double> result = spec.GetSpectrophore(&mol); if (result.empty()) { std::cerr << "Error calculating Spectrophore from molecule number "; std::cerr << count; std::cerr << " (counting starts at 0)!"; std::cerr << std::endl; } else { std::cout << mol.GetTitle() << "\t"; for (unsigned int i(0); i < result.size(); ++i) { std::cout << result[i] << "\t"; } std::cout << std::endl; } mol.Clear(); ++count; } return 0; }