void Sequence::setValues(QString minv, QString maxv, QString inc, QString start, QString cache) { minv=formatValue(minv); maxv=formatValue(maxv); inc=formatValue(inc); start=formatValue(start); cache=formatValue(cache); //Raises an error when some values are empty if(minv=="" || maxv=="" || inc=="" || start=="" || cache=="") throw Exception(ERR_ASG_INV_VALUE_SEQ_ATTRIBS,__PRETTY_FUNCTION__,__FILE__,__LINE__); //Raises an error when the min value is greater than max value else if(compareValues(minv,maxv) > 0) throw Exception(ERR_ASG_INV_SEQ_MIN_VALUE,__PRETTY_FUNCTION__,__FILE__,__LINE__); //Raises an error when the start value is less that min value or grater than max value else if(compareValues(start, minv) < 0 || compareValues(start, maxv) > 0) throw Exception(ERR_ASG_INV_SEQ_START_VALUE,__PRETTY_FUNCTION__,__FILE__,__LINE__); //Raises an error when the increment value is null (0) else if(isNullValue(inc)) throw Exception(ERR_ASG_INV_SEQ_INCR_VALUE,__PRETTY_FUNCTION__,__FILE__,__LINE__); //Raises an error when the cache value is null (0) else if(isNullValue(cache)) throw Exception(ERR_ASG_INV_SEQ_CACHE_VALUE,__PRETTY_FUNCTION__,__FILE__,__LINE__); this->min_value=minv; this->max_value=maxv; this->increment=inc; this->cache=cache; this->start=start; }
void AbstractNumericValidator::boundsCheck(const XMLNumber* const theData , MemoryManager* const manager) { int thisFacetsDefined = getFacetsDefined(); int result; try { // must be < MaxExclusive if ( (thisFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) != 0 ) { result = compareValues(theData, getMaxExclusive()); if ( result != -1) { REPORT_VALUE_ERROR(theData , getMaxExclusive() , XMLExcepts::VALUE_exceed_maxExcl , manager) } } // must be <= MaxInclusive if ( (thisFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) != 0 ) { result = compareValues(theData, getMaxInclusive()); if (result == 1) { REPORT_VALUE_ERROR(theData , getMaxInclusive() , XMLExcepts::VALUE_exceed_maxIncl , manager) } }
/* testLeftMost: function to test the left most element param: tree - the tree we are testing pre: tree is not null post: none */ void testLeftMost(struct BSTree *tree) { assert(tree != NULL); printTestResult(compareValues(_leftMostValue(tree->root), 20) == 0, "_leftMostValue", "left most of root"); printTestResult(compareValues(_leftMostValue(tree->root->left), 20) == 0, "_leftMostValue", "left most of left of root"); printTestResult(compareValues(_leftMostValue(tree->root->left->left), 20) == 0, "_leftMostValue", "left most of left of left of root"); printTestResult(compareValues(_leftMostValue(tree->root->right), 67) == 0, "_leftMostValue", "left most of right of root"); }
/* Main function for testing different functions of the assignment */ int main() { printf("%u\n",compareValues(2.0,2.0)); struct BSTree *tree = newBSTree(); testAddNode(tree); testContainsBSTree(tree); printf("printing in-order traversal \n"); inorderTraversal(tree->root); printf("printing pre-order traversal \n"); preorderTraversal(tree->root); printf("printing post-order traversal \n"); postorderTraversal(tree->root); testLeftMost(tree); testRemoveNode(tree); freeBSTree(tree); return 0; }
void FastCGITransport::handleHeader(const std::string& key, const std::string& value) { m_requestHeaders.insert(std::make_pair(key, std::vector<std::string>(1, value))); if (compareKeys(key, k_requestURIKey)) { m_requestURI = value; } else if (compareKeys(key, k_remoteHostKey)) { m_remoteHost = value; } else if (compareKeys(key, k_remotePortKey)) { try { int remote_port = std::stoi(value); if (remote_port < std::numeric_limits<decltype(m_remotePort)>::min() || remote_port > std::numeric_limits<decltype(m_remotePort)>::max()) { m_remotePort = 0; } m_remotePort = remote_port; } catch (std::invalid_argument&) { m_remotePort = 0; } catch (std::out_of_range&) { m_remotePort = 0; } } else if (compareKeys(key, k_methodKey)) { m_extendedMethod = value; if (compareValues(value, "GET")) { m_method = Method::GET; } else if (compareValues(value, "POST")) { m_method = Method::POST; } else if (compareValues(value, "HEAD")) { m_method = Method::HEAD; } else { m_method = Method::Unknown; } } else if (compareKeys(key, k_httpVersionKey)) { m_httpVersion = value; } else if (compareKeys(key, k_contentLengthKey)) { try { m_requestSize = std::stoi(value); } catch (std::invalid_argument&) { m_requestSize = 0; } catch (std::out_of_range&) { m_requestSize = 0; } } else if (compareKeys(key, k_documentRoot)) { m_documentRoot = value + "/"; } }
int compareHand(const Hand& h) const { if(rank > h.rank) { return 1; } if(rank < h.rank) { return -1; } return compareValues(h); }
/* testRemoveNode: function to test the left most element param: tree - the tree we are testing pre: tree is not null post: 3 nodes have been removed from the tree */ void testRemoveNode(struct BSTree *tree) { removeNodeFromTree(tree, 13); /* Should output: node is not contained in the tree */ removeNodeFromTree(tree, 20); printTestResult(tree->root->val == 55 && tree->root->left->left == NULL, "removeNodeFromTree", "remove left-left of root"); removeNodeFromTree(tree, 36); printTestResult(compareValues(tree->root->val, 55) == 0 && tree->root->left == NULL, "removeNodeFromTree", "remove left of root"); removeNodeFromTree(tree, 67); printTestResult(compareValues(tree->root->val, 55) == 0 && tree->root->right->left == NULL, "removeNodeFromTree", "remove right-left of root"); /* Comment out these test cases and try some more interesting ones */ }
// ----------------------------------------------------------------------- // Compare methods // ----------------------------------------------------------------------- int DecimalDatatypeValidator::compare(const XMLCh* const lValue , const XMLCh* const rValue , MemoryManager* const manager) { XMLBigDecimal lObj(lValue, manager); XMLBigDecimal rObj(rValue, manager); return compareValues(&lObj, &rObj); }
// ----------------------------------------------------------------------- // Compare methods // ----------------------------------------------------------------------- int DoubleDatatypeValidator::compare(const XMLCh* const lValue , const XMLCh* const rValue , MemoryManager* const manager) { XMLDouble lObj(lValue, manager); XMLDouble rObj(rValue, manager); return compareValues(&lObj, &rObj); }
// ----------------------------------------------------------------------- // Compare methods // ----------------------------------------------------------------------- int FloatDatatypeValidator::compare(const XMLCh* const lValue , const XMLCh* const rValue , MemoryManager* const manager) { XMLFloat lObj(lValue, manager); XMLFloat rObj(rValue, manager); return compareValues(&lObj, &rObj); }
int pytuple::compare(const pybase& rval) const { int ret = pybase::compare(rval); if (ret == 0){ return (compareValues((const pycontainer&)(rval))); } return (ret); }
/* testAddNode: function to test each node of the BST and children pre: tree is not null param: tree - the tree we are testing post: none */ void testAddNode(struct BSTree *tree) { assert(tree != NULL); printf("testing add node... \n"); addBSTree(tree, 55); if (compareValues(tree->root->val, 55) != 0) { printf("addNode() test: FAIL to insert 55 as root\n"); } else if (tree->cnt != 1) { /*check the tree->cnt value after adding a node to the tree*/ printf("addNode() test: FAIL to increase count when inserting 55 as root\n"); } else{ printf("addNode() test: PASS when adding 55 as root\n"); } addBSTree(tree, 36); if (compareValues(tree->root->left->val, 36) != 0) { /*check the position of the second element that is added to the BST tree*/ printf("addNode() test: FAIL to insert 36 as left child of root\n"); } else if (tree->cnt != 2) { printf("addNode() test: FAIL to increase count when inserting 36 as left of root\n"); } else printf("addNode() test: PASS when adding 36 as left of root\n"); addBSTree(tree, 78); if (compareValues(tree->root->right->val, 78) != 0) { /*check the position of the third element that is added to the BST tree*/ printf("addNode() test: FAIL to insert 78 as right child of root\n"); } else if (tree->cnt != 3) { printf("addNode() test: FAIL to increase count when inserting 78 as right of root\n"); } else printf("addNode() test: PASS when adding 78 as right of root\n"); addBSTree(tree, 20); if (compareValues(tree->root->left->left->val, 20) != 0) { /*check the position of the fourth element that is added to the BST tree*/ printf("addNode() test: FAIL to insert 10 as left child of left of root\n"); } else if (tree->cnt != 4) { printf("addNode() test: FAIL to increase count when inserting 20 as left of left of root\n"); } else printf("addNode() test: PASS when adding 20 as left of left of root\n"); addBSTree(tree, 85); if (compareValues(tree->root->right->right->val, 85) != 0) { /*check the position of the fourth element that is added to the BST tree*/ printf("addNode() test: FAIL to insert 85 as right right child of left of root\n"); } else if (tree->cnt != 5) { printf("addNode() test: FAIL to increase count when inserting 85 as right right child of root\n"); } else printf("addNode() test: PASS when adding 85 as right right child of root\n"); addBSTree(tree, 67); if (compareValues(tree->root->right->left->val, 67) != 0) { /*check the position of the fourth element that is added to the BST tree*/ printf("addNode() test: FAIL to insert 67 as right left child of left of root\n"); } else if (tree->cnt != 6) { printf("addNode() test: FAIL to increase count when inserting 67 as right left child of root\n"); } else printf("addNode() test: PASS when adding 67 as right left child of root\n"); printf("done testing add node... \n"); }
void HqlCppCaseInfo::addPair(IHqlExpression * expr) { IHqlExpression * compareExpr = expr->queryChild(0); IHqlExpression * resultExpr = expr->queryChild(1); if (allResultsMatch && pairs.ordinality()) { if (pairs.tos().queryChild(1) != resultExpr) allResultsMatch = false; } pairs.append(*LINK(expr)); if (!compareExpr->queryValue()) { constantCases = false; } else if (constantCases) { if (!lowestCompareExpr || compareValues(compareExpr, lowestCompareExpr) < 0) lowestCompareExpr.set(compareExpr); if (!highestCompareExpr || compareValues(compareExpr, highestCompareExpr) > 0) highestCompareExpr.set(compareExpr); } if (!expr->queryChild(1)->queryValue()) constantValues = false; if (cond && !complexCompare) { ITypeInfo * valueType = compareExpr->queryType(); if (valueType != cond->queryType()) complexCompare = isCompare3Valued(compareExpr->queryType()); } updateResultType(resultExpr); }
// ----------------------------------------------------------------------- // Abstract interface from AbstractNumericValidator // ----------------------------------------------------------------------- void FloatDatatypeValidator::checkContent(const XMLCh* const content , ValidationContext* const context , bool asBase , MemoryManager* const manager) { //validate against base validator if any FloatDatatypeValidator *pBase = (FloatDatatypeValidator*) this->getBaseValidator(); if (pBase) pBase->checkContent(content, context, true, manager); // we check pattern first if ( (getFacetsDefined() & DatatypeValidator::FACET_PATTERN ) != 0 ) { if (getRegex()->matches(content, manager) ==false) { ThrowXMLwithMemMgr2(InvalidDatatypeValueException , XMLExcepts::VALUE_NotMatch_Pattern , content , getPattern() , manager); } } // if this is a base validator, we only need to check pattern facet // all other facet were inherited by the derived type if (asBase) return; XMLFloat theValue(content, manager); XMLFloat *theData = &theValue; if (getEnumeration() != 0) { int i=0; int enumLength = getEnumeration()->size(); for ( ; i < enumLength; i++) { if (compareValues(theData, (XMLFloat*) getEnumeration()->elementAt(i))==0) break; } if (i == enumLength) ThrowXMLwithMemMgr1(InvalidDatatypeValueException, XMLExcepts::VALUE_NotIn_Enumeration, content, manager); } boundsCheck(theData, manager); }
void main() { int nn; long t1, t2, t_dif; t1 = clock(); t2 = clock(); t_dif = t2 - t1; CACHE_setL1DSize(CACHE_L1_32KCACHE); // CACHE_setL2Size(CACHE_L2_128KCACHE); generateData( (float *) inputComplex, 2*NUMBER_OF_ELEMENTS); nn = NUMBER_OF_ELEMENTS; // for (nn=512; nn <= NUMBER_OF_ELEMENTS; nn = nn * 2) { t1 = clock(); naturalC_filters(inputComplex, nn, outputEnergy1 ); t2 = clock(); printf("natural C code size %d time %d \n",nn, t2 - t1 - t_dif); } // printPower(outputEnergy1, NUMBER_OF_FILTERS ); // for (nn=512; nn <= NUMBER_OF_ELEMENTS; nn = nn * 2) { t1 = clock(); intrinsicC_filters(inputComplex, nn, outputEnergy2 ); t2 = clock(); printf("intrinsic C code size %d time %d \n",nn, t2 - t1 - t_dif); } compareValues(outputEnergy1, outputEnergy2,NUMBER_OF_FILTERS ); printf(" \n\n DONE \n\n" ); }
// // Check facet among self // check common facets // check Additional Facet Constraint // void AbstractNumericFacetValidator::inspectFacet(MemoryManager* const manager) { int thisFacetsDefined = getFacetsDefined(); XMLNumber *thisMaxInclusive = getMaxInclusive(); XMLNumber *thisMaxExclusive = getMaxExclusive(); XMLNumber *thisMinInclusive = getMinInclusive(); XMLNumber *thisMinExclusive = getMinExclusive(); if (!thisFacetsDefined) return; // non co-existence checking // check 4.3.8.c1 error: maxInclusive + maxExclusive if (((thisFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) != 0) && ((thisFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) != 0) ) ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_max_Incl_Excl, manager); // non co-existence checking // check 4.3.9.c1 error: minInclusive + minExclusive if (((thisFacetsDefined & DatatypeValidator::FACET_MINEXCLUSIVE) != 0) && ((thisFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) != 0) ) ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_min_Incl_Excl, manager); // // minExclusive < minInclusive <= maxInclusive < maxExclusive // // check 4.3.7.c1 must: minInclusive <= maxInclusive if (((thisFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) != 0) && ((thisFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) != 0) ) { int result = compareValues(thisMinInclusive, thisMaxInclusive); if ( result == 1 || result == INDETERMINATE ) { REPORT_FACET_ERROR(thisMinInclusive , thisMaxInclusive , XMLExcepts::FACET_maxIncl_minIncl , manager) } }
bool IPHeaderFilter::processPacket(Packet *p) { int srcvalue; void *start; switch(m_header) { case 1: start=p->data.netHeader; break; case 2: start=p->transportHeader; break; default: start=p->data.netHeader; } if(start == NULL) return false; srcvalue=getData(((char*)start + m_offset), m_size); return compareValues(srcvalue, m_value); }
// ----------------------------------------------------------------------- // Abstract interface from AbstractNumericValidator // ----------------------------------------------------------------------- void DecimalDatatypeValidator::checkContent(const XMLCh* const content , ValidationContext* const context , bool asBase , MemoryManager* const manager) { //validate against base validator if any DecimalDatatypeValidator *pBase = (DecimalDatatypeValidator*) this->getBaseValidator(); if (pBase) pBase->checkContent(content, context, true, manager); int thisFacetsDefined = getFacetsDefined(); // we check pattern first if ( (thisFacetsDefined & DatatypeValidator::FACET_PATTERN ) != 0 ) { // lazy construction if (getRegex() ==0) { try { // REVISIT: cargillmem fMemoryManager vs manager setRegex(new (fMemoryManager) RegularExpression(getPattern(), SchemaSymbols::fgRegEx_XOption, fMemoryManager)); } catch (XMLException &e) { ThrowXMLwithMemMgr1(InvalidDatatypeValueException, XMLExcepts::RethrowError, e.getMessage(), manager); } } if (getRegex()->matches(content, manager) ==false) { ThrowXMLwithMemMgr2(InvalidDatatypeValueException , XMLExcepts::VALUE_NotMatch_Pattern , content , getPattern() , manager); } } // if this is a base validator, we only need to check pattern facet // all other facet were inherited by the derived type if (asBase) return; XMLCh *errorMsg = 0; try { XMLBigDecimal compareDataValue(content, manager); XMLBigDecimal* compareData = &compareDataValue; if (getEnumeration()) { int i=0; int enumLength = getEnumeration()->size(); for ( ; i < enumLength; i++) { if (compareValues(compareData, (XMLBigDecimal*) getEnumeration()->elementAt(i)) ==0 ) break; } if (i == enumLength) ThrowXMLwithMemMgr1(InvalidDatatypeValueException, XMLExcepts::VALUE_NotIn_Enumeration, content, manager); } boundsCheck(compareData, manager); if ( (thisFacetsDefined & DatatypeValidator::FACET_FRACTIONDIGITS) != 0 ) { if ( compareData->getScale() > fFractionDigits ) { XMLCh value1[BUF_LEN+1]; XMLCh value2[BUF_LEN+1]; XMLString::binToText(compareData->getScale(), value1, BUF_LEN, 10, manager); XMLString::binToText(fFractionDigits, value2, BUF_LEN, 10, manager); ThrowXMLwithMemMgr3(InvalidDatatypeFacetException , XMLExcepts::VALUE_exceed_fractDigit , compareData->getRawData() , value1 , value2 , manager); } } if ( (thisFacetsDefined & DatatypeValidator::FACET_TOTALDIGITS) != 0 ) { if ( compareData->getTotalDigit() > fTotalDigits ) { XMLCh value1[BUF_LEN+1]; XMLCh value2[BUF_LEN+1]; XMLString::binToText(compareData->getTotalDigit(), value1, BUF_LEN, 10, manager); XMLString::binToText(fTotalDigits, value2, BUF_LEN, 10, manager); ThrowXMLwithMemMgr3(InvalidDatatypeFacetException , XMLExcepts::VALUE_exceed_totalDigit , compareData->getRawData() , value1 , value2 , manager); } /*** E2-44 totalDigits ... by restricting it to numbers that are expressible as i � 10^-n where i and n are integers such that |i| < 10^totalDigits and 0 <= n <= totalDigits. ***/ if ( compareData->getScale() > fTotalDigits ) { XMLCh value1[BUF_LEN+1]; XMLCh value2[BUF_LEN+1]; XMLString::binToText(compareData->getScale(), value1, BUF_LEN, 10, manager); XMLString::binToText(fTotalDigits, value2, BUF_LEN, 10, manager); ThrowXMLwithMemMgr3(InvalidDatatypeFacetException , XMLExcepts::VALUE_exceed_totalDigit , compareData->getRawData() , value1 , value2 , manager); } } } catch (XMLException &e) { errorMsg = XMLString::replicate(e.getMessage(), manager); } if(errorMsg) { ArrayJanitor<XMLCh> jan(errorMsg, manager); ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::RethrowError, errorMsg, manager); } }
void readcomplex(const std::string base) { // Row-wise streaming const double theMax = 1000.; const double theMin = -theMax; // The two formats std::vector<string> ofileNames; // ofileNames.push_back(base+".xml"); ofileNames.push_back(base + ".root"); for (int iFile = 0; iFile < ofileNames.size(); ++iFile) { const char *ifilename = ofileNames[iFile].c_str(); TFile *ifile = TFile::Open(ifilename); if (!ifile) { cout << "ERROR Cannot open " << ifilename << endl; continue; } cout << "Reading file " << ifilename << endl; TRandom3 rndm(1); // Write nIters random complex per type bool oncef = true; bool onced = true; int nIters = (ifile->GetListOfKeys()->GetSize()-1)*0.5; // -1 for the tree, the rest are row wise for (int j = 0; j < nIters; ++j) { // Re-generate values std::complex<float> cFloatRef(rndm.Uniform(theMin, theMax), rndm.Uniform(theMin, theMax)); std::complex<double> cDoubleRef(rndm.Uniform(theMin, theMax), rndm.Uniform(theMin, theMax)); // read them TString cFloatName(TString::Format("cFloat_%i", j)); std::complex<float> *cFloatPtr = (std::complex<float> *) ifile->Get(cFloatName); TString cDoubleName(TString::Format("cDouble_%i", j)); std::complex<double> *cDoublePtr = (std::complex<double> *) ifile->Get(cDoubleName); if (!cFloatPtr) { cout << "ERROR Cannot get " << cFloatName << " from file " << ifilename << endl; continue; } if (!cDoublePtr) { cout << "ERROR Cannot get " << cDoubleName << " from file " << ifilename << endl; continue; } // compare them bit-by-bit compareValues(ifilename, *cFloatPtr, cFloatRef, *cDoublePtr, cDoubleRef); } if (iFile != 1) { // Now the tree TTreeReader reader ("t",ifile); TTreeReaderValue<complex<float>> cFloat_split(reader, "cFloat_split"); TTreeReaderValue<complex<float>> cFloat(reader, "cFloat"); TTreeReaderValue<complex<double>> cDouble_split(reader, "cDouble_split"); TTreeReaderValue<complex<double>> cDouble(reader, "cDouble"); while (reader.Next()) { std::complex<float> cFloatn(rndm.Uniform(theMin,theMax),rndm.Uniform(theMin,theMax)); std::complex<double> cDoublen(rndm.Uniform(theMin,theMax),rndm.Uniform(theMin,theMax)); compareValues(ifilename, *cFloat_split, cFloatn, *cDouble_split, cDoublen); compareValues(ifilename, *cFloat, cFloatn, *cDouble, cDoublen); } } } }
void DateTimeValidator::checkContent(const XMLCh* const content , ValidationContext* const context , bool asBase , MemoryManager* const manager) { //validate against base validator if any DateTimeValidator *pBaseValidator = (DateTimeValidator*) this->getBaseValidator(); if (pBaseValidator) pBaseValidator->checkContent(content, context, true, manager); int thisFacetsDefined = getFacetsDefined(); // we check pattern first if ( (thisFacetsDefined & DatatypeValidator::FACET_PATTERN ) != 0 ) { if (getRegex()->matches(content, manager) ==false) { ThrowXMLwithMemMgr2(InvalidDatatypeValueException , XMLExcepts::VALUE_NotMatch_Pattern , content , getPattern() , manager); } } // if this is a base validator, we only need to check pattern facet // all other facet were inherited by the derived type if (asBase) return; // the derived classes' parse() method constructs an // XMLDateTime object anc invokes appropriate XMLDateTime's // parser to parse the content. XMLDateTime dateTimeValue(content, manager); XMLDateTime* dateTime = &dateTimeValue; parse(dateTime); // must be < MaxExclusive if ((thisFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) != 0) { if (compareValues(dateTime, getMaxExclusive()) != XMLDateTime::LESS_THAN) { REPORT_VALUE_ERROR( dateTime , getMaxExclusive() , XMLExcepts::VALUE_exceed_maxExcl , manager) } } // must be <= MaxInclusive if ((thisFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) != 0) { int result = compareValues(dateTime, getMaxInclusive()); if ( result == XMLDateTime::GREATER_THAN || result == XMLDateTime::INDETERMINATE ) { REPORT_VALUE_ERROR( dateTime , getMaxInclusive() , XMLExcepts::VALUE_exceed_maxIncl , manager) } }
static int comparePair(IHqlExpression * lexpr, IHqlExpression * rexpr) { return compareValues(lexpr->queryChild(0), rexpr->queryChild(0)); }