void ContainerSizeEmptyCheck::registerMatchers(MatchFinder *Finder) {
  const auto WrongUse = anyOf(
      hasParent(
          binaryOperator(
              anyOf(has(integerLiteral(equals(0))),
                    allOf(anyOf(hasOperatorName("<"), hasOperatorName(">="),
                                hasOperatorName(">"), hasOperatorName("<=")),
                          hasEitherOperand(integerLiteral(equals(1))))))
              .bind("SizeBinaryOp")),
      hasParent(implicitCastExpr(
          hasImplicitDestinationType(isBoolType()),
          anyOf(
              hasParent(unaryOperator(hasOperatorName("!")).bind("NegOnSize")),
              anything()))),
      hasParent(explicitCastExpr(hasDestinationType(isBoolType()))));

  Finder->addMatcher(
      memberCallExpr(
          on(expr(anyOf(hasType(namedDecl(stlContainer())),
                        hasType(pointsTo(namedDecl(stlContainer()))),
                        hasType(references(namedDecl(stlContainer())))))
                 .bind("STLObject")),
          callee(methodDecl(hasName("size"))), WrongUse).bind("SizeCallExpr"),
      this);
}
Exemplo n.º 2
0
//--------------------------------------------------------------
bool  ofxMuiNumberData::addValue(float val, ofxMuiRange _bounds, ofxMuiRange _range) {

    // prepare iterators
    // start inserting
    historyLength.push_back(_defaults->dataHistoryLength);
    deque<float> initQ(_defaults->dataHistoryLength, val); // create a history
    values.push_back(initQ); // add the queue
    
    bounds.push_back(_bounds);
    ranges.push_back(_range);

    displayPrecision.push_back(_defaults->displayPrecision);


    if(isBoolType() || isIntType()) {
        incrementValues.push_back(_defaults->incrementInt);
    } else if(isFloatType()) {
        incrementValues.push_back(_defaults->incrementFloat);
    }

    bool boundsChanged = false;
    bool rangeChanged = false;
    bool valueChanged = false;
    checkRange(boundsChanged, rangeChanged, getNumValues()-1);
    constrainValue(valueChanged, getNumValues()-1);

}
Exemplo n.º 3
0
//--------------------------------------------------------------
bool ofxMuiNumberData::toggle(int index) {
    if(isValidIndex(index)) {
        if(!isBoolType()) ofLog(OF_LOG_WARNING, "ofxMuiNumberData: Toggling non boolean type.");

        pushNewValue(values[index].back() > 0.5 ? 0 : 1, true, index);
        
        return true;
    } else {
        return false;
    }
}
Exemplo n.º 4
0
//--------------------------------------------------------------
bool  ofxMuiNumberData::insertValue(int index, float val, ofxMuiRange _bounds, ofxMuiRange _range) {
    if(isValidInsertionIndex(index)) {
        // prepare iterators
        valuesIter = values.begin() + index;
        historyLengthIter = historyLength.begin() + index;
        boundsIter = bounds.begin() + index;
        rangesIter = ranges.begin() + index;
        displayPrecisionIter = displayPrecision.begin() + index; 
        incrementValuesIter = incrementValues.begin() + index;
        
        // start inserting
        
        historyLength.insert(historyLengthIter, _defaults->dataHistoryLength);
        deque<float> initQ(_defaults->dataHistoryLength, val); // create a history
        values.push_back(initQ); // add the queue
        values.insert(valuesIter, initQ);

        bounds.insert(boundsIter, _bounds);
        ranges.insert(rangesIter, _range);
        
        // if it's global, take it from the other
        displayPrecision.insert(displayPrecisionIter, _defaults->displayPrecision);
        
        
        if(isBoolType() || isIntType()) {
            incrementValues.insert(incrementValuesIter, _defaults->incrementInt);
        } else if(isFloatType()) {
            incrementValues.insert(incrementValuesIter, _defaults->incrementFloat);
        }
        
        bool boundsChanged = false;
        bool rangeChanged = false;
        bool valueChanged = false;        
        checkRange(boundsChanged, rangeChanged, index);
        constrainValue(valueChanged,index);
        
    } else {
        return false;
    }
}