Example #1
0
/**
 * Do a binary search through a sorted array for a specific float value.
 *
 * @param search - The value to search for
 * @param sorted - The array to search in
 * @param length - The length of the array provided
 *
 * @return - true if the value (or a very close float) exists in the array, false otherwise.
 */
bool Tableau::find(float search, float sorted[], int length) {
    if(length == 0) return false;
    float midpoint = length/2;
    float size = midpoint;

    do {
        size /= 2;
        switch(compareFloat(search, sorted[(int)midpoint])) {
        case 0:
            return true;
        case -1:
            midpoint -= size;
            break;
        case 1:
            midpoint += size;
            break;
        }
    } while(round(size) > 0);
    return false;
}
void SoConditionalTrigger::inputChanged(SoField * whichField)
{
    if ((whichField == &token) | (whichField == &triggerAtInit))
    {
        trigger.enable(FALSE);
        tokenOut.enable(FALSE);
        boolOut.enable(FALSE);
		//SoDebugError::postInfo("SoConditionalTrigger::inputChanged()",
		//		"%s: token now set to: %s",
		//		this->getName().getString(), token.getValue().getString());
    }
    else {
	    bool localC = true;
        bool any = false;
	    int i,j, num, tnum;

        if (whichField == &triggerIn) {
            any = true;
            triggerNotified = false;
        }

	    // check all conditions.
	    if (((num = boolIn.getNum()) > 0) && ((tnum = triggerBool.getNum()) > 0)){
		    localC = false; any = true;
		    for (i=0; i<num; i++){
                for (j=0; j<tnum; j++){
			        if (boolIn[i] == triggerBool[j]){
				        localC = true;
				        break;
			        }
                }
                if (localC) break;
		    }
	    }

	    if (localC && ((num = floatIn.getNum()) > 0) && (triggerFloat.getNum() > 0)) {
		    localC = false; any = true;
		    for (i=0; i<num; i++){
			    if (compareFloat(floatIn[i])){
				    localC = true;
				    break;
			    }
		    }
	    }

	    if (localC && ((num = intIn.getNum()) > 0) && (triggerInt.getNum() > 0)) {
		    localC = false; any = true;
		    for (i=0; i<num; i++){
			    if (compareInt(intIn[i])){
				    localC = true;
				    break;
			    }
		    }
	    }

	    if (localC && ((num = stringIn.getNum()) > 0) && ((tnum = triggerString.getNum()) > 0)) {
		    localC = false; any = true;
            if (comparison.getValue() == EQUAL) {
                for (i=0; i<num; i++){
                    for (j=0; j<tnum; j++){
			            if (stringIn[i] == triggerString[j]){
				            localC = true;
				            break;
			            }
                    }
                    if (localC) break;
		        }
            }
            else {
                for (i=0; i<num; i++){
                    for (j=0; j<tnum; j++){
			            if (! stringIn[i] == triggerString[j]){
				            localC = true;
				            break;
			            }
                    }
                    if (localC) break;
		        }
            }
	    }
        
	    if (localC && ((num = nodeIn.getNum()) > 0) && ((tnum = triggerNode.getNum()) > 0)) {
		    localC = false; any = true;
		    for (i=0; i<num; i++){
                for (j=0; j<tnum; j++){
			        if (nodeIn[i] == triggerNode[j]){
				        localC = true;
				        break;
			        }
                }
                if (localC) break;
		    }
	    }

        if (!any) localC = false;
                
	    if (localC) {
            if (!retrigger.getValue())
            {
                if (!triggerNotified) {
				    //SoDebugError::postInfo("SoConditionalTrigger::inputChanged()",
				    //		"%s: condition == TRUE -> notify trigger!\n",this->getName().getString());
                    boolOut.enable(TRUE);
                    trigger.enable(TRUE);
                    tokenOut.enable(TRUE);
                    triggerNotified = true;
                    tempBool = true;
                }
                else {
                    trigger.enable(FALSE);
                    tokenOut.enable(FALSE);
                }
            }
            else
            {
                boolOut.enable(TRUE);
                trigger.enable(TRUE);
                tokenOut.enable(TRUE);
                triggerNotified = true;
                tempBool = true;
            }
	    }
        else {
            if (tempBool) {
				//SoDebugError::postInfo("SoConditionalTrigger::inputChanged()",
				//		"%s: condition == FALSE -> update boolOut!",
				//		this->getName().getString());
                tempBool = false;
                boolOut.enable(TRUE);
            }
            trigger.enable(FALSE);
            tokenOut.enable(FALSE);
            triggerNotified = false;
        }
    }
}